I'm trying to find a way to show which items of a list have already been submitted. The idea is to reduce risk/prevent duplicate submissions
I wanted to filter the databasejoin element to exclude items that correspond to any already submitted by the user, but that did my head in and I came up with the idea of using a calc (with AJAX) to show the list of items... But it seems to interfere with other AJAX elements causing the spinner of doom once the first dropdown is selected (FA_Existing_Theme in the code below)...
tables: themes, activities, activities_feedback
activities has a foreign key from themes (and allows the cascading dbjoin elements)
My Calc code:
If I remove the 'where' clause I can see that the join works as expected, so I'm guessing that might have a little something to do with it! But I'm stumped. And stupid.
Thanks
I wanted to filter the databasejoin element to exclude items that correspond to any already submitted by the user, but that did my head in and I came up with the idea of using a calc (with AJAX) to show the list of items... But it seems to interfere with other AJAX elements causing the spinner of doom once the first dropdown is selected (FA_Existing_Theme in the code below)...
tables: themes, activities, activities_feedback
activities has a foreign key from themes (and allows the cascading dbjoin elements)
My Calc code:
// Get a db connection in Joomla 4+.
$db = \Joomla\CMS\Factory::getContainer()->get('DatabaseDriver');
// Create a new query object.
$myQuery = $db->createQuery(true);
$myQuery
->select(array('activities.id','activities.activity_name', 'activities_feedback.FA_SubmittedBy AS SubmittedBy'))
->from('activities')
-> join('INNER', 'activities_feedback ON activities_feedback.FA_Existing_Activity = activities.id')
->where('activities.themeid = '. $db->quote('{activities_feedback___FA_Existing_Theme_raw} AND activities_feedback.FA_SubmittedBy = {$my->id}'));
// Assign the query to the db
$db->setQuery($myQuery);
// Load the results as an array of objects.
$rows = $db->loadObjectList();
$list = array();
foreach ($rows as $row)
{
$list[] = $row->activity_name . " " . $row->SubmittedBy;
}
return $list;
$db = \Joomla\CMS\Factory::getContainer()->get('DatabaseDriver');
// Create a new query object.
$myQuery = $db->createQuery(true);
$myQuery
->select(array('activities.id','activities.activity_name', 'activities_feedback.FA_SubmittedBy AS SubmittedBy'))
->from('activities')
-> join('INNER', 'activities_feedback ON activities_feedback.FA_Existing_Activity = activities.id')
->where('activities.themeid = '. $db->quote('{activities_feedback___FA_Existing_Theme_raw} AND activities_feedback.FA_SubmittedBy = {$my->id}'));
// Assign the query to the db
$db->setQuery($myQuery);
// Load the results as an array of objects.
$rows = $db->loadObjectList();
$list = array();
foreach ($rows as $row)
{
$list[] = $row->activity_name . " " . $row->SubmittedBy;
}
return $list;
If I remove the 'where' clause I can see that the join works as expected, so I'm guessing that might have a little something to do with it! But I'm stumped. And stupid.
Thanks