This commit is contained in:
Paula Quispe
2019-04-09 16:26:16 -04:00
parent 96d823820c
commit 4bdb500b00
2 changed files with 45 additions and 9 deletions

View File

@@ -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
*

View File

@@ -333,17 +333,15 @@ 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();