Make Calc-elements "filtering sensitive" in list view...

mudshark79

Member
Hello, i want to ask you for some help on one special aspect in the use of calc elements. My Basic goal is to visualize a list's data usinc "helper"-calc elements to prepare the data (already achieved, could be done more elegant though for sure) BUT also to respect filtering of the list within these calc elements (the part where i hope to get help). I have prepared a special version of the site in question at shared-hosting webspace and would like to use this as an illustration and can also provide access ...

You can find it here:

http://nahtdemo1-1.biberelite.de/

use

testadmin:fabrikadmin

as a frontend-login

I have one list in the upmost Menu on the left side called "Klienten", there's a column "Erwerbseinkommen" wich is counted by total in column ErwerbseinkommenCount. This is done by a calc element doing a Query directly in the DB. It's nothing that isn't much more convenient done by the list-element-counter but read on after the PHP used in the first calc:
PHP:
$id = '{01_klienten___erwerbseinkommen_id_raw}';
$db = FabrikWorker::getDbo(true, 2);
$sql = "SELECT erwerbseinkommen_id FROM 01_klienten WHERE erwerbseinkommen_id = $id";
$db->setQuery($sql);
$einkommens = $db->loadObjectList();
$count = 0;
foreach($einkommens as $einkommen)
{
$count = $count + 1;
}
return $count;

I have a second column "Helper" wich is also a calc_element wich ensures, that a "boolean" value of 1 or 0 indicates whether the row in the DB is the first one holding the specific value of the first column in question "Erwerbseinkommen" - only the first row holds the value of 1, all the others get a 0.

PHP:
$erwerbs_id = '{01_klienten___erwerbseinkommen_id_raw}';
$id = '{01_klienten___id_raw}';
$db = FabrikWorker::getDbo(true, 2);
$sql = "SELECT id FROM 01_klienten WHERE erwerbseinkommen_id = $erwerbs_id";
$db->setQuery($sql);
$einkommens = $db->loadObjectList();
$disp = array();
foreach($einkommens as $einkommen)
{
$array = (array)$einkommen;
$disp[] = $array[id];
//echo "<pre>";print_r($disp);echo "<pre>";
}
if ($disp[0] == $id){
$db =&JFactory::getDBO();
$db->setQuery("UPDATE 01_klienten SET erwerbseinkommenauswhelper_calc = '1' WHERE id = '$id'");
$db->query();
return 1;
}else{
$db = FabrikWorker::getDbo(true, 2);
$db->setQuery("UPDATE 01_klienten SET erwerbseinkommenauswhelper_calc = '0' WHERE id = '$id'");
if (!$db->query()) {
var_dump($db->getErrorMsg()); exit;
};
return 0;
}

I use this construction for a visualization found in the same menu on the left at "Demovisualisierung",the helper element makes sure that every counted-up value of Erwerbseinkommen is shown only once.

Despite of the fact that the calc-code for sure is quite ineffective and would not perform on a big scale: I'm looking for a way to make this thing sensitive of the filtering of the list. For Example if use the filter for "Standorte" and only show, say, "unbekannt" the helper-element should reflect on this, but of course it doesn't.

I have found several questions regarding counting and visualization that go into this direction but only the thread that comes closest is this one?:

http://fabrikar.com/forums/index.php?threads/row-counter.26928/

To sum it up:

There definitely is a solution with incorporating the whole logic into one top-of-the-pops sql-query (that i'm far away from understanding), last but not least the Element counter beneath the list does the same...

Question:

Can i somehow do a visualisation of the result of the List-Calculation?

But even more interesting: Is there a different approach I'm not aware of? Couldn't I use the "list-count-code" in a calc element, how is this whole counting and calculation beneath the list done? Can I use some list-Php Plugin to read the lists data on page load, do the logic, override certain values and giving them back before the visualization logic kicks in (I already feel quite familiar with form-plugins)?

So far and quite confused ... please PM me for backend-access, i appreciate every feedback...
 
I think for your second calculation, in the select query you would need to filter by the submitted filter values as well?
 
Thanks for looking into the issue.

If I can figure out how to do it, this would, of course, solve my "problem". How do I query the filter settings, is there a placeholder or do i use some "JRequest::Var" php? I will look in the wiki and do a forum search, maybe I can sort it out on myself, knowing that there is a way....

BTW: isn't the count-element-plugin supposed to do exactly the same thing? It counts the total of the element it is adjusted to and then stops the rendering of the table? I did try it some time ago but couldn't figure out what it was meant for, i did try again just after seeing different postings supposing a bug in the count element. After the extra reading (maybe a wiki entry would clear things up) and trying again (but also experiencing "strange" behaviour of the element) It sounds to me that this element should be the solution, functioning properly?
 
Hmmm, I'm not convinced the count element will work in 3.x. I don't think anybody has touched the code except to convert it from 2.1 to 3.x standard since 2005, and the way we do our list building has changed somewhat since then. I've fixed an actual error in the code, but it's still not adding the "GROUP BY" clause.

BTW, in the second chunk of code you quoted, there is a syntax error:

PHP:
$disp[] = $array[id];

... which I presume should be $id.

To be honest, I'm still a little confused about what your calc's are doing, specifically what they are writing out to the database, and I'd need to look at the backend to get a better understanding.

In general, you need to be VERY careful about doing "extra stuff" in calc elements. They were designed to simply return a value for the calc element itself, not to "do stuff" outside of that. So, for example, unless you have "Calc on save only" set, we run the calc code several times during list and form rendering.

Can you give that account backend access? Probably best to change the password, and put the details in your My Sites list:

http://fabrikar.com/you/my-sites

-- hugh
 
Thanks for your efforts so far.

I updated "/you/mysites" with all necessary informations and also did tidy up the demosite and elements in questions (f.e. 2nd calc writing back sthg. was useless, further try i already forgot about when posting) to make it easier to understand, i think it's really not that complicated, maybe just my approach and descriptoin is a bit confusing. That's why a short summary again:

and again for the reference:
testadmin:fabrikadmin
as a frontend-login

The goal is to have a simple visualisation of some counted up values. So there is a list "Clients". Every client has a choosen type of income, in our case this is as a database2join-dropdown-element. The visualisation should show: that many clients have this and that sort of income. The visualization should be "filtering sensitive" (so if one filters on "Place" and chooses "Sch?ndorf" as a value, there should be shown only 2 times "ALG2", values as is in time of writing). End of Story.

My Solution so Far and my question in particular:
I have 2 (or 3 to be exately) calc elements:

1. income_id_count counts up the given value of income (but doesn't reflect on filters)
2. income_id_display_helper is a simple display-helper to have a proper label for the vizualization
3. income_id_count_vizhelp is a calc wich tests, wheter the given income_value is the first of it's kind in the list. If yes, there's a 1, if the value is a repating of it's kind, it's returning a zero

4. i have a vizualization of the list,
type 2d bar,
income_id_count is visualized
income_id_display_helper is label
WHERE Statement is "income_id_count_vizhelp = '1' " in order that no duplicate entries get visualized

Question:
How can i make the first calc "filtering sensitive" so only the rows get counted, that really show up in the list when filtered? The income_id_count_vizhelp does what it's suppoed to do...


Remarks / Further questions:
1. The simple list count/split underneath the list does exaktly perfect what i want. If there would be a way do a visualization on this, this would be the perfect solution.

2. Of course my approach doing several calcs i maybe too complicated, maybe there is a completely different, better approach (i read about mysql views an understand the concept, but the sql-view would have to reflect on the filters too and istherefore not easier to construct?)

3 .Maybe the count-element-plugin once was created to do exaktly what I'm trying to do with my helper calcs?

Thanks again and looking forward for a solution
 
I've looked at the count element, and it doesn't do what you want. It's to do with counting joined rows.

I'm playing around with a test on my local server to see if I can work out a way of doing this.

rob - do you think it would be easier to work up this as a test case in the new nvd3 graphing viz?

-- hugh
 
Thanks, I'm glad that at least I managed to explain the case ;) - it's not crucial in the short run but sooner or later i will have to come up with a solution for this .... and I think some others might also tried the same? Counting things up is the most obvious thing to do .... also in a visualisation.

If this will be a coming feature of a completely new visualization plugin, will this be available for 3.0 also? I doubt I will do a port of my existing application to 3.1. :)

Matthias
 
The element calculations should be selectable as input values into the fusion chart viz.
For more complex charts, I suggest making a mySQL view of the data and then using that as the base for the chart viz
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top