Welcome, Guest
Username: Password: Remember me

TOPIC: [HIRE] Pay for help to foreign key to another component

Pay for help to foreign key to another component 22 May 2015 22:19 #13164

  • jonathanbell
  • jonathanbell's Avatar
  • Offline
  • Premium Member
  • Posts: 147
  • Thank you received: 5
  • Karma: 1
Hi, I have searched the forum, but being a novice scripter I'm not even sure what I am looking at.

I have a foreign field in a component that looks up employees names in a table in the current component.
I simply want it to look in another component for the data for the list box.
Can someone provide a straight forward explanation of what code needs to change and where it is located in a basic component and explain what it actually does.

I just have not understood anything else I have read. Please believe me I have tried ( old man learning new tricks :blink: )

Hope someone can explain in plain English what I should do. Please......

www.upwork.com/c/jobs/Help-show-how-Fore...a_~~90fd0597d67d46c1
Last Edit: 23 May 2015 00:42 by jonathanbell. Reason: Add payment
The administrator has disabled public write access.

Pay for help to foreign key to another component 23 May 2015 09:19 #13166

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
At the moment I am not available, but soon I will dedicate more for such needs.
Coding is now a piece of cake
The administrator has disabled public write access.

Pay for help to foreign key to another component 23 May 2015 10:56 #13167

  • MorganL
  • MorganL's Avatar
  • Offline
  • Platinum Member
  • Posts: 438
  • Thank you received: 53
  • Karma: 15
Clearly a custom model in your component referencing the thridparty table, but my famiiarity with models in J3 is not solid enough, nor do I have the spare time.

However for other who may see this it may help to

1) State clearly what version of Joomla this is for
2) Is the primary component a J-Cook one, and which builder
3) Is the third party component (where data is coming from for the FK) a J-Cook component or is it a component listed on the JED

If you supply as much info as possible (even the FK table and fields you want to pull off) people can help a lot quicker if they are free as they can even supply complete examples with the actual code you need

That aside, The code for pulling data from a table in J3 is
// Get a db connection.
$db = JFactory::getDbo();
 
// Create a new query object.
$query = $db->getQuery(true);
 
// Select all records from the user profile table where key begins with "custom.".
// Order it by the ordering field.
$query->select($db->quoteName(array('FIELD1', 'FIELD2', ....... , 'FIELDX')));
$query->from($db->quoteName('#__THIRDPARTY_TABLE'));
$query->where($db->quoteName('FIELDX') . ' LIKE '. $db->quote('\'custom.%\''));
$query->order('ordering ASC');
 
// Reset the query using our newly populated query object.
$db->setQuery($query);
 
// Load the results as a list of stdClass objects (see later for more options on retrieving data).
$results = $db->loadObjectList();

which is HOW you can construct the FK list, but I dont have sufficient knowledge of J3 select boxes etc to construct it

A guiding point may be to

create a blank project with one table
add a field called USERS to a blank table and use a Joomla user wizard data type
make a collection and item view with a single select box of the users table

down load and run it and see how that select box in the item is generated by looking at the code. As the select box is a third party table one (#__users), you may see how that box is propegated, and using the query supplied above, altered it to point at whatever table contains your data, you can make the select box contain the data you want
Morgan Leecy MCSE

Novell / Linux
PHP. MYSQL, Apache, node.js
Coldfusion, JQuery, HTML5
Joomla
Last Edit: 23 May 2015 10:58 by MorganL.
The administrator has disabled public write access.

Pay for help to foreign key to another component 23 May 2015 21:30 #13169

  • jonathanbell
  • jonathanbell's Avatar
  • Offline
  • Premium Member
  • Posts: 147
  • Thank you received: 5
  • Karma: 1
Thanks for the suggestions.

All Components are all created in J-Cook
Latest stable version for 3.2
All Components will be pulling from a component called: Company Details

- Tables

Sites
Departments
Employees

Actual Fields data pulled from

Sites/Site Name (site_name)
Departments/Department Name ( department_name)
Employees/ Employee Name (employee_name)

I will go and have a go with the scripting. Cant hurt...

Thanks again.. :)
The administrator has disabled public write access.

Pay for help to foreign key to another component 24 May 2015 06:20 #13171

  • Romkabouter
  • Romkabouter's Avatar
  • Offline
  • Elite Member
  • Posts: 310
  • Thank you received: 131
  • Karma: 48
Hi Jonathan,

Do you need the dropdown in the frontend or backend?
I have done it like this, but another way might be better for your components

- create a fork folder
- create a helperfile in your fork folder
- in the view.html.php, create a filter with the list from that helper
- in the layout (i.e. default.php) echo that filter.

More detailed (will post some code later):

Create fork folder
Create a "fork" folder in your admin part (or the site part)
Lets assume you have a view named "someview".
Create in the fork folder the following folder: views/someview
Copy the view.html.php and index.html from _fork/views/someview into your fork/views/someview.
Copy the displayDefault() function from the original into it.
Create in your fork/views/someview a folder tmpl
Copy default.php and index.html (can be different in your component) from _fork/views/someview/tmpl into your fork/views/someview/tmpl.
The index.html file are just empty pages.

Create helper file
Create a folder in your fork: fork/helpers and a file name functions.php, also copy a index.html (empty page)

Create filter in (forked) view.html.php
Create a list in put it in the default filters array. Put the code in the display()
$filters['sites']->jdomOptions = array(
    'dataValue' => $state->get('filter.site_name'),
    'labelKey' => 'site_name',
    'list' => MyComponentFunctions::getSites()
);

Echo the filter in your layout
Put the following code where you want the dropdown.
<?php echo $this->filters['sites']->input;?>


code for helper file
This is example code
<?php
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' ); 
if( !class_exists('MyComponentFunctions') ){ 
		/**
		 * JoomBMSFunctions Class  
		 */
	    class MyComponentFunctions{
		
		/**
		 * @var string $_name is name of group;
		 *
		 * @access private;
		 */
		private static $_name = 'MyComponent Functions';
		
		/**
		 * getter of name variable
		 */
		public static function getName(){
			return self::$_name;	
		}	
		
		public static function getSites() {
			$db = JFactory::getDbo();
			$query = $db->getQuery(true);
			$query
				->select(array('id', 'site_name'))
				->from('#__yourothercomponent_sitetable')
				->where('published = 1'); //if you have this
			$db->setQuery($query);
			$result = $db->loadObjectList();
			return $result;
		}								
	}
}
?>

I can give more help if you need it.
I can even create the code for you, but you would have to create some designmockups so that I can see where and how you want the data.
Last Edit: 24 May 2015 06:21 by Romkabouter.
The administrator has disabled public write access.
The following user(s) said Thank You: jonathanbell

Pay for help to foreign key to another component 31 May 2015 07:23 #13201

  • jonathanbell
  • jonathanbell's Avatar
  • Offline
  • Premium Member
  • Posts: 147
  • Thank you received: 5
  • Karma: 1
Thanks, I will go have a try...
The administrator has disabled public write access.

Pay for help to foreign key to another component 31 May 2015 07:28 #13202

  • jonathanbell
  • jonathanbell's Avatar
  • Offline
  • Premium Member
  • Posts: 147
  • Thank you received: 5
  • Karma: 1
Hi, I need the drop down box for the front end. I currently have put all the tables with relationships in the same component. Makes it huge , how ever it works. In the long run , splitting the component into smaller parts would be the ultimate go. I will have a try and see what I can do. If I get stuck I will contact you for some help.

Thanks again..
The administrator has disabled public write access.

Pay for help to foreign key to another component 15 Jun 2016 21:44 #14074

  • jonathanbell
  • jonathanbell's Avatar
  • Offline
  • Premium Member
  • Posts: 147
  • Thank you received: 5
  • Karma: 1
Hi Romkabouter, hope your well. Was quite a while ago I was trying to work this out. Can I send you a couple of mock ups of what I am trying to do? Happy to discuss costs.

I will be making two mock up components - one will have some common tables that will need to be called across a number of components. ( Departments / Sites / Employees )

The other mock up (mockup 2) will be an example component that would need to get this information. Do I need to include Foreign Key and similar tables in t(mockup 2)?

Is there a reasonably straight forward way to get the foreign key to point to the tables in the other component?

Anyhow, hope your able to help :)
The administrator has disabled public write access.

Pay for help to foreign key to another component 17 Jun 2016 11:18 #14075

  • Romkabouter
  • Romkabouter's Avatar
  • Offline
  • Elite Member
  • Posts: 310
  • Thank you received: 131
  • Karma: 48
Hi Jonathan,

I am fine thank you :)
You are welcome to send me some mockups on paul[at]newbreedmedia[dot]nl

I have read the whole post again, but I do not quite get why you want to split up the components for Departments/Sites/Employees
And what is this Company Details component? Also a Cook or an existing?

For the mockups, please try to create screens and mark where the data should come from.
We can talk further over email, I will do this for free :)
The administrator has disabled public write access.
The following user(s) said Thank You: jonathanbell

Pay for help to foreign key to another component 18 Jun 2016 22:11 #14077

  • jonathanbell
  • jonathanbell's Avatar
  • Offline
  • Premium Member
  • Posts: 147
  • Thank you received: 5
  • Karma: 1
Thanks, component mock ups on their way shortly. :)
The administrator has disabled public write access.

Pay for help to foreign key to another component 21 Jun 2016 13:45 #14085

  • vlemos
  • vlemos's Avatar
  • Online
  • Elite Member
  • Posts: 295
  • Thank you received: 41
  • Karma: 21
Hello Jonathan / Rom

I thought long and hard before deciding to respond on this thread. Only because "Romkabouter" has offered his services for free, will I share a hack I use while I wait for Admin to code a more elegant solution.

In j-cook, if you recreate only the table(s) you need from the target extension you can link your component to that table as you normally would in the builder. You have the full power of the builder at your command to manipulate and filter that "external" dataset. However, the table is still currently part of your component.

Once you are happy with how your component interacts with the table, download your component and unzip it. Do a bulk replace for the target table name on the admin and site folders. Your component is now connected to that extension via that table. All that is necessary is to remove the target table-name from the install and uninstall SQL scripts to avoid damaging the target extension. Re-zip your component and install and you have successfully coupled your component to an external extension.

This assumes that the external target tables are few and not very large. The builder has at times given problems with very large components.

This solution works well in instances where you need to ensure that maintenance remains fully in-house.

Good luck. . . .

Warm regards
vlemos
The administrator has disabled public write access.
The following user(s) said Thank You: jonathanbell

Pay for help to foreign key to another component 21 Jun 2016 13:51 #14086

  • Romkabouter
  • Romkabouter's Avatar
  • Offline
  • Elite Member
  • Posts: 310
  • Thank you received: 131
  • Karma: 48
I indeed did that also once (I need access to K2) :)

Good solution, I have send a zip file already with a view forked files in it.
This is no other then filling a FK list to show in the form and a forked model to show some values from the other component.

What is best depends a bit on how much functionality you need for the external tables :)
Last Edit: 21 Jun 2016 13:55 by Romkabouter.
The administrator has disabled public write access.

Pay for help to foreign key to another component 22 Jun 2016 00:44 #14087

  • jonathanbell
  • jonathanbell's Avatar
  • Offline
  • Premium Member
  • Posts: 147
  • Thank you received: 5
  • Karma: 1
Hi Rom, a very very big thank you for your help. Going through what you sent has helped me understand forking better (previously zip knowledge) and pointed me exactly to where I want to go. :cheer:

vlemos thanks also for your guidance on this.

Sometimes one cannot see something even when it has been staring them right in the face all the time ( That's been me for a while now). I'm not a very proficient scripter in php, but learn something new nearly every day.

So again.. Thank you so much. This deserves a good Beer to celebrate this little hurdle that seemed way bigger than it actually was.

:P
The administrator has disabled public write access.

Pay for help to foreign key to another component 22 Jun 2016 07:15 #14088

  • Romkabouter
  • Romkabouter's Avatar
  • Offline
  • Elite Member
  • Posts: 310
  • Thank you received: 131
  • Karma: 48
No worries, good luck coding :)
The administrator has disabled public write access.
Time to create page: 0.234 seconds

Get Started