Include info from one list to another

verzevoul

Member
Hi,

in the following website (http://88.198.17.8/~vip/5/) i have 5 lists ( ????? ??????, ??????????? (?????), ??????????? (?????), ???????????, ???????)
The first one "????? ??????" contains data about customers (firstname, lastname, address, etc.)

The second list "??????????? (?????)" contains invoices about each customer. Now, what i wanna do is to include customers info from the first list (????? ??????) to the second list (??????????? (?????)) just below the title of the list. This info should be filtered according to the invoices that this specific client has. I'm filtering the invoices with the fabrik's default filter (??????? - > dropdown list that comes from the first list)


i'm fetching the data that i want to include in the second list, using the following that is inside default.php of a custom template folder.

<?php
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query
->select($db->quoteName(array('a.Eponimia')))
->from($db->quoteName('1_epikoinonias', 'a'))
->join('LEFT', $db->quoteName('1_repeat_tziros', 'b') . ' ON (' . $db->quoteName('a.id') . ' = ' . $db->quoteName('b.pelatis_join') . ')');
//->where($db->quoteName('a.Eponimia') . ' = ' . $db->quoteName('b.pelatis_join'));

$db->setQuery($query);
$rows = $db->loadObjectList();

$list = array();
foreach ($rows as $row)
{
$list[] = "<li>" . $row->Eponimia . " " . $row->onoma . "</li>";
}
echo "<ol>" . implode($list) . "</ol>";

?>

"1_epikoinonias" is the table name of the first list and 1_repeat_tziros is the table name of the second list.

The problem is that i can't find the way to filter this data according to the built in filter that fabrik uses, that it returns data from the second list ONLY for one customer.
 
Hi
So to summarise you are on the invoice details page and you want to show the customer for that invoice?
Before going down the route of a custom query, wouldn't a user join element do for this?
Can you point us at the url for the lists/forms please?
 
rob - it's a little more complicated than that. He's not talking about form / detail view. he's talking about a filtered list view. So filtering the invoice ist by customer, and using that customer filter selection to then render that customer's address before the list itself.

I'm thinking this might be possible using a {fabrik view=details ...} plugin in the list intro ... it's just a case of working out how to derive the rowid. It'll be in the posted data, so technically could be accessed using [name] substitution (which looks for 'name' in the J!'s request data), but as filters are numerically keyed, it's kinda tough to know which is which, and of course they are subject to change ...

This is actually a fairly common request, to be able to access the current state of the filters during page load, and the answer is never straight forward.

I'm looking to see if there's some way we can make this easier.

-- hugh
 
I'm just getting back to work after the weekend, looking at this one now.

Note that what you are wanting to do is, at the moment, simply not supported by Fabrik, and there is currently really no maintainable way of doing this. There is a hacky way of doing it, that relies on using a numeric index which could change at any time - for example if you added / removed any elements as filters, the custom code would most probably break. And there is a more complex, round the houses way of doing it, which wouldn't be so fragile, but the custom code for doing it would not be simple.

So it's going to require adding a feature to Fabrik, in order for you to use it with any degree of reliability and for it to be maintainable by you, and supportable by us. I'll work on it as fast as I can, but I can't guarantee any kind of deadline or ETA for adding features to Fabrik.

--hugh
 
I've been looking to see if this is something we could add as a built in feature, but so far I'm not seeing a way to do it.

So ... we're going to need to do some custom coding, inside the list intro. For this, you'll need to install the 'Sourcerer' plugin from here:

http://www.nonumber.nl/extensions/sourcerer

The code you are going to need to run is something like this:

PHP:
{source}
<?php
$app = JFactory::getApplication;
$input = $app->input;
$fabrik___filter = (array) $input->get('fabrik___filter');
$filters = JArrayHelper::getValue($fabrik___filter, 'list_2_com_fabrik_2', array());
$filter_values = JArrayHelper::getValue($filters, 'value', array());
$pelatis_join_value = JArrayHelper::getInt($filter_values, 1, 0);
if (!empty($pelatis_join_value)
echo "{fabrik view=details id=2 layout=default row=" . $pelatis_join_value . "}";
?>
{/source}

This code may well not work straight away, as it's off the top of my head, and I'm not entirely sure I've gotten the element names / form id's etc correct.

So if you can get Sourcerer installed (I don't like installing components and plugins on client's live sites), and that code above inserted into the Intro text for your list.

The idea is that we fetch the lists filter form inputs, and extract the value of the dropdown filter for the pelatis_join. As that is a join which points to the 'id' (rowid) of table you want to grab the address from, which is a Fabrik list/form, we should be able to use a Fabrik content plugin to render the detail view for that customer record, using the id selected in the filter as the rowid.

So once you have that Sourcerer extension installed, and that code in your intro text, let me know.

-- hugh
 
Ok, i did exactly what you asked for, and now you're ready to go! Let me know if you have any progress on this! I've also noticed that there's something wrong with the sourcerer plugin, as it strips the "<" tag from the code... funny because everything is allowed inside plugin's parameters...

Thanks!

Chris
 
OK, I'll get back in there. Just remembered we did actually back port a feature from 3.1 to 3.0 which will make this a bit easier, won't have to dig through the filter inputs by hand, we now have a helper function to do that.

-- hugh
 
OK, couple of issues ... when entering code using Sourcerer in a WYSIWYG editor, you have to either use the "Insert Source" button, or toggle the editor to simple text mode. Otherwise the editor inserts all kinds of funky formatting tags in the code.

Also, in JCE, the default editor profile doesn't allow PHP tags, and will always strip that opening chevron.

Anyway, I'm working on trying to get your system to let us enter PHP code ...

-- hugh
 
Alright, I give up ... I know how to do this on a J! 3.2 site with the new editor ... but I'm just running in to all kinds of roadblocks. trying to get J! 2.5 and JCE (or even the plain text "no editor" option) to let me do it.

Also, re-reading your OP, I think to get this where you want it, it will need indeed need to go in the template, not the list intro. You said you were using a custom template - which one is it?

Also, can you check the ftp login details you gave us for that site? Your server is rejecting my ftp login attemtps:

Response:331 User *** OK. Password required
Command:pASS **********
Response:530 Login authentication failed
I copied the username and password directly from your My Sites info into FileZilla.
I'll need ftp, in order to edit your custom template.
-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top