2010-12-02 23:34:41 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* GroupUser.php
|
2012-10-19 17:09:00 -04:00
|
|
|
*
|
|
|
|
|
* @package workflow.engine.classes.model
|
2011-01-31 14:14:55 +00:00
|
|
|
*
|
2010-12-02 23:34:41 +00:00
|
|
|
* ProcessMaker Open Source Edition
|
2011-01-31 14:14:55 +00:00
|
|
|
* Copyright (C) 2004 - 2011 Colosa Inc.
|
2012-10-19 17:09:00 -04:00
|
|
|
*
|
2010-12-02 23:34:41 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2012-10-19 17:09:00 -04:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2010-12-02 23:34:41 +00:00
|
|
|
* GNU Affero General Public License for more details.
|
2012-10-19 17:09:00 -04:00
|
|
|
*
|
2010-12-02 23:34:41 +00:00
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
2012-10-19 17:09:00 -04:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*
|
|
|
|
|
* For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
|
2010-12-02 23:34:41 +00:00
|
|
|
* Coral Gables, FL, 33134, USA, or email info@colosa.com.
|
2012-10-19 17:09:00 -04:00
|
|
|
*
|
2010-12-02 23:34:41 +00:00
|
|
|
*/
|
|
|
|
|
|
2012-11-20 16:45:09 -04:00
|
|
|
//require_once 'classes/model/om/BaseGroupUser.php';
|
|
|
|
|
//require_once 'classes/model/Content.php';
|
|
|
|
|
//require_once 'classes/model/Users.php';
|
|
|
|
|
//require_once 'classes/model/Groupwf.php';
|
2010-12-02 23:34:41 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Skeleton subclass for representing a row from the 'GROUP_USER' table.
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* You should add additional methods to this class to meet the
|
2012-10-19 17:09:00 -04:00
|
|
|
* application requirements. This class will only be generated as
|
2010-12-02 23:34:41 +00:00
|
|
|
* long as it does not already exist in the input directory.
|
|
|
|
|
*
|
2012-10-19 17:09:00 -04:00
|
|
|
* @package workflow.engine.classes.model
|
2010-12-02 23:34:41 +00:00
|
|
|
*/
|
2012-10-19 17:09:00 -04:00
|
|
|
class GroupUser extends BaseGroupUser
|
|
|
|
|
{
|
2010-12-02 23:34:41 +00:00
|
|
|
|
2012-10-19 17:09:00 -04:00
|
|
|
/**
|
|
|
|
|
* Create the application document registry
|
|
|
|
|
*
|
|
|
|
|
* @param array $aData
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function create ($aData)
|
|
|
|
|
{
|
|
|
|
|
$oConnection = Propel::getConnection( GroupUserPeer::DATABASE_NAME );
|
|
|
|
|
try {
|
|
|
|
|
$oGroupUser = new GroupUser();
|
|
|
|
|
$oGroupUser->fromArray( $aData, BasePeer::TYPE_FIELDNAME );
|
|
|
|
|
if ($oGroupUser->validate()) {
|
|
|
|
|
$oConnection->begin();
|
|
|
|
|
$iResult = $oGroupUser->save();
|
|
|
|
|
$oConnection->commit();
|
|
|
|
|
return $iResult;
|
|
|
|
|
} else {
|
|
|
|
|
$sMessage = '';
|
|
|
|
|
$aValidationFailures = $oGroupUser->getValidationFailures();
|
|
|
|
|
foreach ($aValidationFailures as $oValidationFailure) {
|
|
|
|
|
$sMessage .= $oValidationFailure->getMessage() . '<br />';
|
|
|
|
|
}
|
|
|
|
|
throw (new Exception( 'The registry cannot be created!<br />' . $sMessage ));
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception $oError) {
|
|
|
|
|
$oConnection->rollback();
|
|
|
|
|
throw ($oError);
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-19 17:09:00 -04:00
|
|
|
/**
|
|
|
|
|
* Remove the application document registry
|
|
|
|
|
*
|
|
|
|
|
* @param string $sGrpUid
|
|
|
|
|
* @param string $sUserUid
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function remove ($sGrpUid, $sUserUid)
|
|
|
|
|
{
|
|
|
|
|
$oConnection = Propel::getConnection( GroupUserPeer::DATABASE_NAME );
|
|
|
|
|
try {
|
|
|
|
|
$oGroupUser = GroupUserPeer::retrieveByPK( $sGrpUid, $sUserUid );
|
|
|
|
|
if (! is_null( $oGroupUser )) {
|
|
|
|
|
$oConnection->begin();
|
|
|
|
|
$iResult = $oGroupUser->delete();
|
|
|
|
|
$oConnection->commit();
|
2014-10-07 15:58:46 -04:00
|
|
|
|
|
|
|
|
$oGrpwf = new Groupwf();
|
|
|
|
|
$grpName = $oGrpwf->loadByGroupUid($sGrpUid);
|
|
|
|
|
|
|
|
|
|
$oUsr = new Users();
|
|
|
|
|
$usrName = $oUsr->load($sUserUid);
|
|
|
|
|
|
2014-10-13 16:10:40 -04:00
|
|
|
G::auditLog("AssignUserToGroup", "Remove user: ".$usrName['USR_USERNAME'] ." (".$sUserUid.") from group ".$grpName['CON_VALUE']." (".$sGrpUid.") ");
|
2014-10-07 15:58:46 -04:00
|
|
|
|
2012-10-19 17:09:00 -04:00
|
|
|
return $iResult;
|
|
|
|
|
} else {
|
|
|
|
|
throw (new Exception( 'This row doesn\'t exist!' ));
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception $oError) {
|
|
|
|
|
$oConnection->rollback();
|
|
|
|
|
throw ($oError);
|
|
|
|
|
}
|
2011-02-07 22:54:01 +00:00
|
|
|
}
|
2010-12-02 23:34:41 +00:00
|
|
|
|
2012-10-20 17:19:10 -04:00
|
|
|
public function getCountAllUsersByGroup ()
|
2012-10-19 17:09:00 -04:00
|
|
|
{
|
|
|
|
|
$oCriteria = new Criteria( 'workflow' );
|
|
|
|
|
$oCriteria->addSelectColumn( GroupUserPeer::GRP_UID );
|
2016-10-18 16:08:22 -04:00
|
|
|
$oCriteria->addSelectColumn( 'COUNT(' . GroupUserPeer::GRP_UID . ') AS CNT' );
|
2012-10-19 17:09:00 -04:00
|
|
|
$oCriteria->addJoin( GroupUserPeer::USR_UID, UsersPeer::USR_UID, Criteria::INNER_JOIN );
|
|
|
|
|
$oCriteria->add( UsersPeer::USR_STATUS, 'CLOSED', Criteria::NOT_EQUAL );
|
|
|
|
|
$oCriteria->addGroupByColumn( GroupUserPeer::GRP_UID );
|
|
|
|
|
$oDataset = GroupUserPeer::doSelectRS( $oCriteria );
|
|
|
|
|
$oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC );
|
|
|
|
|
$aRows = Array ();
|
|
|
|
|
while ($oDataset->next()) {
|
|
|
|
|
$row = $oDataset->getRow();
|
|
|
|
|
$aRows[$row['GRP_UID']] = $row['CNT'];
|
|
|
|
|
}
|
|
|
|
|
return $aRows;
|
2012-01-26 09:33:01 -04:00
|
|
|
}
|
|
|
|
|
|
2012-10-20 17:19:10 -04:00
|
|
|
public function getAllUserGroups ($usrUid)
|
2012-10-19 17:09:00 -04:00
|
|
|
{
|
|
|
|
|
$oCriteria = new Criteria( 'workflow' );
|
|
|
|
|
$oCriteria->add( GroupUserPeer::USR_UID, $usrUid );
|
|
|
|
|
//$oCriteria->addGroupByColumn(GroupUserPeer::GRP_UID);
|
|
|
|
|
$oDataset = GroupUserPeer::doSelectRS( $oCriteria );
|
|
|
|
|
$oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC );
|
|
|
|
|
|
|
|
|
|
$rows = Array ();
|
|
|
|
|
while ($oDataset->next()) {
|
|
|
|
|
$row = $oDataset->getRow();
|
|
|
|
|
$g = new Groupwf();
|
|
|
|
|
try {
|
|
|
|
|
$grpRow = $g->load( $row['GRP_UID'] );
|
|
|
|
|
$row = array_merge( $row, $grpRow );
|
|
|
|
|
$rows[] = $row;
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-04 18:42:47 -04:00
|
|
|
return $rows;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Get all users assigned to Group
|
|
|
|
|
*
|
|
|
|
|
* @param string $gprUid
|
|
|
|
|
* @return array $rows
|
|
|
|
|
*/
|
|
|
|
|
public function getAllGroupUser ($gprUid)
|
|
|
|
|
{
|
|
|
|
|
$oCriteria = new Criteria( 'workflow' );
|
|
|
|
|
$oCriteria->add( GroupUserPeer::GRP_UID, $gprUid );
|
|
|
|
|
$oDataset = GroupUserPeer::doSelectRS( $oCriteria );
|
|
|
|
|
$oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC );
|
|
|
|
|
|
|
|
|
|
$rows = Array ();
|
|
|
|
|
while ($oDataset->next()) {
|
|
|
|
|
$row = $oDataset->getRow();
|
|
|
|
|
$g = new Groupwf();
|
|
|
|
|
try {
|
|
|
|
|
$grpRow = $g->load( $row['GRP_UID'] );
|
|
|
|
|
$row = array_merge( $row, $grpRow );
|
|
|
|
|
$rows[] = $row;
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-19 17:09:00 -04:00
|
|
|
return $rows;
|
|
|
|
|
}
|
2017-06-01 12:10:02 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This function check if the array have at least one UID valid
|
|
|
|
|
* Ex. we need to check the data for self service value based assignment
|
|
|
|
|
*
|
|
|
|
|
* @param array $toValidate , this array contains uid of user or uid of groups
|
|
|
|
|
* @param array $statusToCheck , this array must be have a valid status for users or groups, ACTIVE INACTIVE VACATION
|
|
|
|
|
* @param string $tableReview , if you need to check uid for users or groups
|
|
|
|
|
* @return boolean $rows
|
|
|
|
|
*/
|
|
|
|
|
public function groupsUsersAvailable($toValidate, $statusToCheck = array('ACTIVE'), $tableReview = 'users')
|
|
|
|
|
{
|
|
|
|
|
//Define the batching value for the MySQL error related to max_allowed_packet
|
|
|
|
|
$batching = 25000;
|
|
|
|
|
$array = array_chunk($toValidate, $batching);
|
|
|
|
|
foreach ($array as $key => $uidValues) {
|
|
|
|
|
$oCriteria = new Criteria('workflow');
|
|
|
|
|
switch ($tableReview) {
|
|
|
|
|
case 'groups':
|
|
|
|
|
$oCriteria->add(GroupwfPeer::GRP_UID, $uidValues, Criteria::IN);
|
|
|
|
|
$oCriteria->add(GroupwfPeer::GRP_STATUS, $statusToCheck, Criteria::IN);
|
|
|
|
|
$oCriteria->setLimit(1);
|
|
|
|
|
$rsCriteria = GroupwfPeer::doSelectRS($oCriteria);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
$oCriteria->add(UsersPeer::USR_UID, $uidValues, Criteria::IN);
|
|
|
|
|
$oCriteria->add(UsersPeer::USR_STATUS, $statusToCheck, Criteria::IN);
|
|
|
|
|
$oCriteria->setLimit(1);
|
|
|
|
|
$rsCriteria = UsersPeer::doSelectRS($oCriteria);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
$rsCriteria->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
if ($rsCriteria->next()) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2012-10-19 17:09:00 -04:00
|
|
|
}
|
2012-01-26 09:33:01 -04:00
|
|
|
|