v2021.0.15I’m working on two tables: Tasks and MilestonesEvery task has one owner, but other users can be added as collaborators to any task.
Colaborators and task owners can create their own Milestones under the main task, and when they do they are assigned as owner of that milestone.
Colaborators can also be added to milestones.The milestone table has a field fk_TaskID which contains the id of the main task:
The milestone table also has a custom field fk_TaskOwner which looks up the id of the owner of the main task:
(SELECT fk_StaffID FROM Workplan_Tasks WHERE Workplan_Tasks.id=fk_TaskID)I’m trying to using recordsetSelecting to filter the milestones table to show all records that the user is asssociated with, either as:
- owner of the milestone
- collaborator of the milestone
- owner of the main task
Here is my code currently:
public function recordsetSelecting(&$filter) {
if (CurrentUserLevel() !='-1') {
AddFilter($filter, "fk_StaffID LIKE '%".CurrentUserCode()."%' OR Owner='".CurrentUserID()."' OR fk_TaskOwner ='".CurrentUserID()."'");
}
}
which throws this error:/var/www/html/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php(79): An exception occurred while executing ‘SELECT COUNT(*) FROM (SELECT * FROM Workplan_Milestones_User WHERE (fk_StaffID LIKE ‘%36812100048%’ OR Owner=‘1’ OR fk_TaskOwner=‘1’) AND ((((SELECT fk_StudyYear FROM Workplan_Tasks WHERE id=fk_TaskID) = 15) AND (fk_School = ‘75014149’)) AND (fk_StaffID LIKE ‘%36812100048%’ OR Owner=‘1’ OR fk_TaskOwner =’‘))) COUNT_TABLE’: SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘fk_TaskOwner’ in 'where clause’The problem is with the owner lookup. If i remove that part, the page works fine, but also shows me tasks I’m not associated with at all.
It seems as though I can’t use custom fields in the filter, so I also tried this:
public function recordsetSelecting(&$filter) {
if (CurrentUserLevel() !='-1') {
$taskowner = ExecuteScalar("SELECT fk_StaffID FROM Workplan_Tasks WHERE id='".$this->fk_TaskID->CurrentValue."'");
AddFilter($filter, "fk_StaffID LIKE '%".CurrentUserCode()."%' OR Owner='".CurrentUserID()."' OR fk_TaskOwner ='".$taskowner."'");
}
}
This throws a similar error and I’m guessing its because I can’t use $this->fk_TaskID->CurrentValue within the recordsetSelecting function.In case anyone is wondering, yes, my global function CurrentUserCode() is working fineHow can I get around this problem?