/** * Return available supervisors * @param string $obj_type * @param string $sProcessUID * * @return array * * @access public */ public function getAvailableProcessSupervisors($obj_type, $sProcessUID = '') { try { require_once (PATH_RBAC_HOME . "engine" . PATH_SEP . "classes" . PATH_SEP . "model" . PATH_SEP . "Roles.php"); $aRespLi = array(); $aRespLiGroups = array(); $userRole = new \ProcessMaker\BusinessModel\User(); // Groups $oCriteria = new \Criteria('workflow'); $oCriteria->addSelectColumn(\ProcessUserPeer::USR_UID); $oCriteria->addSelectColumn(\ProcessUserPeer::PU_TYPE); $oCriteria->add(\ProcessUserPeer::PRO_UID, $sProcessUID); $oCriteria->add(\ProcessUserPeer::PU_TYPE, '%SUPERVISOR%', \Criteria::LIKE); $oDataset = \ProcessUserPeer::doSelectRS($oCriteria); $oDataset->setFetchmode(\ResultSet::FETCHMODE_ASSOC); $oDataset->next(); $aUIDS = array(); $aGRUS = array(); while ($aRow = $oDataset->getRow()) { if ($aRow['PU_TYPE'] == 'SUPERVISOR') { $aUIDS [] = $aRow ['USR_UID']; } else { $aGRUS [] = $aRow ['USR_UID']; } $oDataset->next(); } $oCriteria = new \Criteria('workflow'); $oCriteria->addSelectColumn(\GroupwfPeer::GRP_UID); $oCriteria->addAsColumn('GRP_TITLE', \ContentPeer::CON_VALUE); $aConditions [] = array(\GroupwfPeer::GRP_UID, \ContentPeer::CON_ID); $aConditions [] = array(\ContentPeer::CON_CATEGORY, \DBAdapter::getStringDelimiter() . 'GRP_TITLE' . \DBAdapter::getStringDelimiter()); $aConditions [] = array(\ContentPeer::CON_LANG, \DBAdapter::getStringDelimiter() . SYS_LANG . \DBAdapter::getStringDelimiter()); $oCriteria->addJoinMC($aConditions, \Criteria::LEFT_JOIN); $oCriteria->add(\GroupwfPeer::GRP_UID, $aGRUS, \Criteria::NOT_IN); $oCriteria->addAscendingOrderByColumn(\ContentPeer::CON_VALUE); $oDataset = \GroupwfPeer::doSelectRS($oCriteria); $oDataset->setFetchmode(\ResultSet::FETCHMODE_ASSOC); $oDataset->next(); if ($obj_type == 'group' || $obj_type == '') { while ($aRow = $oDataset->getRow()) { $group = new \ProcessMaker\BusinessModel\Group(); $userGroup = $group->getUsers('USERS', $aRow['GRP_UID']); foreach ($userGroup as $value) { $permission = $userRole->loadUserRolePermission('PROCESSMAKER', $value["USR_UID"]); foreach ($permission as $values) { if ($values["PER_CODE"] == 'PM_SUPERVISOR') { $aRespLiGroups[] = array('grp_uid' => $aRow['GRP_UID'], 'grp_name' => $aRow['GRP_TITLE'], 'obj_type' => "group"); } } } $oDataset->next(); } } $exclude = array(""); for ($i = 0; $i<=count($aRespLiGroups)-1; $i++) { if (!in_array(trim($aRespLiGroups[$i]["grp_uid"]) ,$exclude)) { $aRespLi[] = $aRespLiGroups[$i]; $exclude[] = trim($aRespLiGroups[$i]["grp_uid"]); } } $sDelimiter = \DBAdapter::getStringDelimiter(); $oCriteria = new \Criteria('workflow'); $oCriteria->addSelectColumn(\UsersPeer::USR_UID); $oCriteria->addSelectColumn(\UsersPeer::USR_ROLE); $oCriteria->add(\UsersPeer::USR_UID, $aUIDS, \Criteria::NOT_IN); $oDataset = \UsersPeer::doSelectRS($oCriteria); $oDataset->setFetchmode(\ResultSet::FETCHMODE_ASSOC); $oDataset->next(); $aUIDS = array(); while ($aRow = $oDataset->getRow()) { $permission = $userRole->loadUserRolePermission('PROCESSMAKER', $aRow['USR_UID']); foreach ($permission as $key => $value) { if ($value["PER_CODE"] == 'PM_SUPERVISOR') { $aUIDS [] = $aRow ['USR_UID']; } } $oDataset->next(); } $oCriteria = new \Criteria('workflow'); $oCriteria->addSelectColumn(\UsersPeer::USR_UID); $oCriteria->addSelectColumn(\UsersPeer::USR_FIRSTNAME); $oCriteria->addSelectColumn(\UsersPeer::USR_LASTNAME); $oCriteria->addSelectColumn(\UsersPeer::USR_USERNAME); $oCriteria->addSelectColumn(\UsersPeer::USR_EMAIL); $oCriteria->add(\UsersPeer::USR_UID, $aUIDS, \Criteria::IN); $oCriteria->addAscendingOrderByColumn(\UsersPeer::USR_FIRSTNAME); $oCriteria->add(\UsersPeer::USR_STATUS, 'ACTIVE'); $oDataset = \UsersPeer::doSelectRS($oCriteria); $oDataset->setFetchmode(\ResultSet::FETCHMODE_ASSOC); $oDataset->next(); if ($obj_type == 'user' || $obj_type == '') { while ($aRow = $oDataset->getRow()) { $aRespLi[] = array('usr_uid' => $aRow['USR_UID'], 'usr_firstname' => $aRow['USR_FIRSTNAME'], 'usr_lastname' => $aRow['USR_LASTNAME'], 'usr_username' => $aRow['USR_USERNAME'], 'usr_email' => $aRow['USR_EMAIL'], "obj_type" => "user" ); $oDataset->next(); } } return $aRespLi; } catch (Exception $e) { throw $e; } }
/** * @url GET /:grp_uid/available-users * * @param string $grp_uid {@min 32}{@max 32} */ public function doGetAvailableUsers($grp_uid, $filter = null, $start = null, $limit = null) { try { $group = new \ProcessMaker\BusinessModel\Group(); $group->setFormatFieldNameInUppercase(false); $response = $group->getUsers("AVAILABLE-USERS", $grp_uid, array("filter" => $filter), null, null, $start, $limit); return $response; } catch (\Exception $e) { throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); } }
/** * Unassign User of the Group * * @param string $groupUid Unique id of Group * @param string $userUid Unique id of User * * return void */ public function delete($groupUid, $userUid) { try { //Verify data $process = new \ProcessMaker\BusinessModel\Process(); $group = new \ProcessMaker\BusinessModel\Group(); $group->throwExceptionIfNotExistsGroup($groupUid, $this->arrayFieldNameForException["groupUid"]); $process->throwExceptionIfNotExistsUser($userUid, $this->arrayFieldNameForException["userUid"]); $this->throwExceptionIfNotExistsGroupUser($groupUid, $userUid, $this->arrayFieldNameForException["userUid"]); //Delete $group = new \Groups(); $group->removeUserOfGroup($groupUid, $userUid); } catch (\Exception $e) { throw $e; } }