Concept help ... is this even possible with Fabrik?

chris.paschen

Chris Paschen
I've got a project that I need to do for our local scout troop and it's escaping my mind how this might work (or even IF it is possible within Fabrik).

The basic need is to track the boys participation in events (i.e. an attendance system) that both records attendance and assigns an award (like a grade) to the boys. It needs to allow the data entry person to set a number of filters (select group of boys based on a fields in their profile) and then identify the 'award/s' that would be assigned to the boys record.

It would look something like this:

EVENT INFO
Event Date: [Date selector]
Event Title: [Text field]
Leaders: [look-up in leader table, multiple select]
Group: [look-up in group table, single select]

PARTICIPANTS
The participant area should be populated automatically based on the 'group' selected in the Event Info.
The participant should have a couple check boxes to allow assigning.
Like this:

Participant Present Participated
Joe Smith [ ] [ ]
Jim Doe [ ] [ ]
Sam Johnson [ ] [ ]
...etc.


MY DILEMA
Is how to polulate/show the 'many' (participant) part of this one-to-many form - having it pre-populated based on the selection in the main part (Event info) of the form. How to filter that participant list on the 'group' field selector.

In addition, the end goal will be to generate a list for an individual boy that shows all their attendances and participations.

I'm open to any creative way to solve this problem (including potentially 're-configuring' the way we are approaching it - although we have to be able to only work with the participants from specific groups (because there are close to 100 participants in the organization).

I know I'm probably over-thinking this, but it's one of those pesky problems (for a pro-bono project) and any help would be appreciated (by me and the boys and families).
 
Hello Chris

From what I read above, it certainly looks possible. I am not certain if this is just a start to something bigger, or if this is your complete requirement.
 
I forgot to mention ... that is my basic requirement (other than some other specific field thank aren't linked etc.) but if I had that functionality it would 98% of what I need to have happen.
 
Hmmm, I don't think it would be easy.

You'd have to programatically fill a repeat group for the participants with the users for that group. It can be done, but it's some fiddly custom work.

-- hugh
 
Yeah, that's what I was afraid of. I HATE fiddly custom work ... mainly because I keep fiddling with it to make it better and it never gets done (esp. with this type of project which is pro-bono and doesn't have a specific deadline ... I'll never get it done.

Thanks. I'm going to try to rethink how we enter the needed data.
I'm sure I can turn-around my thinking in a way that wouldn't require fiddling.
 
OK ... I 'think' that I have a potential solution ... but it doesn't appear to be working.

Here's the plugin PHP code that I have added to the form:

//get the current Service Project information
$projectID = $formModel->getElementData('tlsys_advancement_service_projects___id');
$hours = $formModel->getElementData('tlsys_advancement_service_projects___total_possible_hours');
$trailmanID = $formModel->getElementData('tlsys_advancement_service_projects___trailman_leader');

//run a query to update all hours entries with same project ID with null info to include the info above

$db = JFactory::getDbo();

$query = $db->getQuery(true);

$query = "UPDATE `tlsys_advancement_service_hours` SET `service_hours` = " . $hours . ", `verified_by_trailman` = " . $trailmanID . " WHERE `service_project_ID` = " . $projectID . " AND (`service_hours` IS NULL OR `service_hours` = 0)";

$db->setQuery($query);

$result = $db->execute();

return 'Trailmen Updated';


HOWEVER, when I save the form I get the following error:

1054 Unknown column 'Array' in 'field list' SQL=UPDATE `tlsys_advancement_service_hours` SET `service_hours` = 8, `verified_by_trailman` = Array WHERE `service_project_ID` = 17 AND (`service_hours` IS NULL OR `service_hours` = 0)

I've tested the SQL itself and works fine when I substitute actual values into these.

The problem appears to be with the $trailmanID field.
The 'tlsys_advancement_service_projects___trailman_leader' element is a a databasejoin, drop-down single select within Fabrik, and in mySQL it is int(11). So I can't figure out why it thinks it is an array when Fabrik tries to process this.

Does the getElementData somehow automatically see this as an array?
 
UPDATE: I was able to cast that value specifically as an int using:
$trailmanID = intval($formModel->getElementData('tlsys_advancement_service_projects___trailman_leader'));

And that made it work; however, I'm still curious to know why that getElementData call would be returing an array rather than the integer that is stored in the field.
 
You may be test with following code to see the data:
PHP:
$trailmanID = $formModel->getElementData('tlsys_advancement_service_projects___trailman_leader');
echo '<pre>trailmanID: ' . var_export($trailmanID, true) . '</pre>';
echo '<pre>trailmanID value: ' . var_export($trailmanID[0], true) . '</pre>';
exit;
 
If it's any of the element types which can have multiple values, like joins, dropdowns, check boxes, etc, the value will be an array. If it's a dropdown or a radio, it'll be an array with just one item, $foo[0].



Sent from my HTC 10 using Tapatalk
 
What I typically do if I'm not sure ...

Code:
$foo = $formModel->getElementData('mytable___foo');
$foo = is_array($foo) ? $foo[0] : $foo;

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top