diff --git a/workflow/engine/classes/Groups.php b/workflow/engine/classes/Groups.php index b00b776b1..08b393881 100644 --- a/workflow/engine/classes/Groups.php +++ b/workflow/engine/classes/Groups.php @@ -74,6 +74,44 @@ class Groups } } + /** + * Get the IDs of the active groups for an user + * + * @param string $usrUid + * + * @return array + * @throws Exception + */ + public function getActiveGroupsForAnUserById($usrUid) + { + try { + $criteria = new Criteria(); + $criteria->addSelectColumn(GroupUserPeer::GRP_ID); + $criteria->addJoin(GroupUserPeer::GRP_ID, GroupwfPeer::GRP_ID, Criteria::LEFT_JOIN); + //@todo: we need to add a new column GROUP_USER.USR_ID + $criteria->add(GroupUserPeer::USR_UID, $usrUid); + //@todo: we need to add a new column GROUPWF.GRP_STATUS_ID + $criteria->add(GroupwfPeer::GRP_STATUS, 'ACTIVE'); + $dataset = GroupUserPeer::doSelectRS($criteria); + $dataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); + $dataset->next(); + + //If the user does not relate with any group we will to return a default value for avoiding problems with the IN + $groups = [-1]; + $row = $dataset->getRow(); + while (is_array($row)) { + $groups[] = $row['GRP_ID']; + $dataset->next(); + $row = $dataset->getRow(); + } + + return $groups; + } catch (Exception $error) { + throw ($error); + } + } + + /** * Set a user to group * diff --git a/workflow/engine/classes/model/ListUnassigned.php b/workflow/engine/classes/model/ListUnassigned.php index 7306ad7fe..a073a8c7b 100644 --- a/workflow/engine/classes/model/ListUnassigned.php +++ b/workflow/engine/classes/model/ListUnassigned.php @@ -333,18 +333,16 @@ class ListUnassigned extends BaseListUnassigned implements ListInterface { try { $arrayAppAssignSelfServiceValueData = []; - $criteria = new Criteria("workflow"); + $group = new Groups(); + //Get the GRP_ID related to the $userUid + $arrayId = $group->getActiveGroupsForAnUserById($userUid); + $sql = "(" - . AppAssignSelfServiceValueGroupPeer::ASSIGNEE_ID . " IN (" - . " SELECT " . GroupUserPeer::GRP_ID . " " - . " FROM " . GroupUserPeer::TABLE_NAME . " " - . " LEFT JOIN " . GroupwfPeer::TABLE_NAME . " ON (" . GroupUserPeer::GRP_ID . "=" . GroupwfPeer::GRP_ID . ") " - . " WHERE " . GroupUserPeer::USR_UID . "='" . $userUid . "' AND " . GroupwfPeer::GRP_STATUS . "='ACTIVE'" - . " ) AND " - . " " . AppAssignSelfServiceValueGroupPeer::ASSIGNEE_TYPE . "=2 " - . ")"; + . AppAssignSelfServiceValueGroupPeer::ASSIGNEE_ID . " IN (" . implode(",", $arrayId) . ") AND " + . " " . AppAssignSelfServiceValueGroupPeer::ASSIGNEE_TYPE . " = 2 " + . ")"; $criteria->setDistinct(); $criteria->addSelectColumn(AppAssignSelfServiceValuePeer::APP_UID);