HOR-3946
Fix CR and code style of the modified classes.
This commit is contained in:
@@ -1,14 +1,20 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace ProcessMaker\BusinessModel;
|
namespace ProcessMaker\BusinessModel;
|
||||||
|
|
||||||
use \G;
|
use BasePeer;
|
||||||
use \UsersPeer;
|
use Configurations;
|
||||||
use \DepartmentPeer;
|
use Criteria;
|
||||||
|
use Department as DepartmentModel;
|
||||||
|
use DepartmentPeer;
|
||||||
|
use Exception;
|
||||||
|
use ProcessMaker\BusinessModel\Validator;
|
||||||
|
use Propel;
|
||||||
|
use RBAC;
|
||||||
|
use ResultSet;
|
||||||
|
use Users;
|
||||||
|
use UsersPeer;
|
||||||
|
use G;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
|
||||||
* @copyright Colosa - Bolivia
|
|
||||||
*/
|
|
||||||
class Department
|
class Department
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@@ -16,27 +22,26 @@ class Department
|
|||||||
*
|
*
|
||||||
* @param string $departmentTitle Title
|
* @param string $departmentTitle Title
|
||||||
* @param string $departmentUidExclude Unique id of Department to exclude
|
* @param string $departmentUidExclude Unique id of Department to exclude
|
||||||
*
|
* @return bool Return true if exists the title of a Department, false otherwise
|
||||||
* return bool Return true if exists the title of a Department, false otherwise
|
|
||||||
*/
|
*/
|
||||||
public function existsTitle($departmentTitle, $departmentUidExclude = "")
|
public function existsTitle($departmentTitle, $departmentUidExclude = "")
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$criteria = new \Criteria("workflow");
|
$criteria = new Criteria("workflow");
|
||||||
|
|
||||||
$criteria->addSelectColumn(\DepartmentPeer::DEP_UID);
|
$criteria->addSelectColumn(DepartmentPeer::DEP_UID);
|
||||||
$criteria->addSelectColumn(\DepartmentPeer::DEP_TITLE);
|
$criteria->addSelectColumn(DepartmentPeer::DEP_TITLE);
|
||||||
|
|
||||||
if ($departmentUidExclude != "") {
|
if ($departmentUidExclude != "") {
|
||||||
$criteria->add(\DepartmentPeer::DEP_UID, $departmentUidExclude, \Criteria::NOT_EQUAL);
|
$criteria->add(DepartmentPeer::DEP_UID, $departmentUidExclude, Criteria::NOT_EQUAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
$criteria->add(\DepartmentPeer::DEP_TITLE, $departmentTitle, \Criteria::EQUAL);
|
$criteria->add(DepartmentPeer::DEP_TITLE, $departmentTitle, Criteria::EQUAL);
|
||||||
|
|
||||||
$rsCriteria = \DepartmentPeer::doSelectRS($criteria);
|
$rsCriteria = DepartmentPeer::doSelectRS($criteria);
|
||||||
|
|
||||||
return ($rsCriteria->next())? true : false;
|
return ($rsCriteria->next())? true : false;
|
||||||
} catch (\Exception $e) {
|
} catch (Exception $e) {
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -46,18 +51,17 @@ class Department
|
|||||||
*
|
*
|
||||||
* @param string $departmentUid
|
* @param string $departmentUid
|
||||||
* @param string $userUid
|
* @param string $userUid
|
||||||
*
|
* @return void Throw exception user not exists
|
||||||
* return void Throw exception user not exists
|
|
||||||
*/
|
*/
|
||||||
private function throwExceptionUserNotExistsInDepartment($departmentUid, $userUid)
|
private function throwExceptionUserNotExistsInDepartment($departmentUid, $userUid)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$user = \UsersPeer::retrieveByPK($userUid);
|
$user = UsersPeer::retrieveByPK($userUid);
|
||||||
|
|
||||||
if (is_null($user) || $user->getDepUid() != $departmentUid) {
|
if (is_null($user) || $user->getDepUid() != $departmentUid) {
|
||||||
throw new \Exception(\G::LoadTranslation('ID_USER_NOT_EXIST_DEPARTMENT', [$userUid]));
|
throw new Exception(G::LoadTranslation('ID_USER_NOT_EXIST_DEPARTMENT', [$userUid]));
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (Exception $e) {
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -68,16 +72,15 @@ class Department
|
|||||||
* @param string $departmentTitle Title
|
* @param string $departmentTitle Title
|
||||||
* @param string $fieldNameForException Field name for the exception
|
* @param string $fieldNameForException Field name for the exception
|
||||||
* @param string $departmentUidExclude Unique id of Department to exclude
|
* @param string $departmentUidExclude Unique id of Department to exclude
|
||||||
*
|
* @return void Throw exception if exists the title of a Department
|
||||||
* return void Throw exception if exists the title of a Department
|
|
||||||
*/
|
*/
|
||||||
public function throwExceptionIfExistsTitle($departmentTitle, $fieldNameForException, $departmentUidExclude = "")
|
public function throwExceptionIfExistsTitle($departmentTitle, $fieldNameForException, $departmentUidExclude = "")
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
if ($this->existsTitle($departmentTitle, $departmentUidExclude)) {
|
if ($this->existsTitle($departmentTitle, $departmentUidExclude)) {
|
||||||
throw new \Exception(\G::LoadTranslation("ID_DEPARTMENT_TITLE_ALREADY_EXISTS", array($fieldNameForException, $departmentTitle)));
|
throw new Exception(G::LoadTranslation("ID_DEPARTMENT_TITLE_ALREADY_EXISTS", array($fieldNameForException, $departmentTitle)));
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (Exception $e) {
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -89,7 +92,6 @@ class Department
|
|||||||
* @param array $arrayVariableNameForException Variable name for exception
|
* @param array $arrayVariableNameForException Variable name for exception
|
||||||
* @param bool $throwException Flag to throw the exception if the main parameters are invalid or do not exist
|
* @param bool $throwException Flag to throw the exception if the main parameters are invalid or do not exist
|
||||||
* (TRUE: throw the exception; FALSE: returns FALSE)
|
* (TRUE: throw the exception; FALSE: returns FALSE)
|
||||||
*
|
|
||||||
* @return array Returns an array with Department record, ThrowTheException/FALSE otherwise
|
* @return array Returns an array with Department record, ThrowTheException/FALSE otherwise
|
||||||
*/
|
*/
|
||||||
public function getDepartmentRecordByPk(
|
public function getDepartmentRecordByPk(
|
||||||
@@ -98,11 +100,11 @@ class Department
|
|||||||
$throwException = true
|
$throwException = true
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
$obj = \DepartmentPeer::retrieveByPK($departmentUid);
|
$obj = DepartmentPeer::retrieveByPK($departmentUid);
|
||||||
|
|
||||||
if (is_null($obj)) {
|
if (is_null($obj)) {
|
||||||
if ($throwException) {
|
if ($throwException) {
|
||||||
throw new \Exception(\G::LoadTranslation(
|
throw new Exception(G::LoadTranslation(
|
||||||
'ID_DEPARTMENT_NOT_EXIST', [$arrayVariableNameForException['$departmentUid'], $departmentUid]
|
'ID_DEPARTMENT_NOT_EXIST', [$arrayVariableNameForException['$departmentUid'], $departmentUid]
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
@@ -111,8 +113,8 @@ class Department
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Return
|
//Return
|
||||||
return $obj->toArray(\BasePeer::TYPE_FIELDNAME);
|
return $obj->toArray(BasePeer::TYPE_FIELDNAME);
|
||||||
} catch (\Exception $e) {
|
} catch (Exception $e) {
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -121,14 +123,11 @@ class Department
|
|||||||
* Get list for Departments
|
* Get list for Departments
|
||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
|
||||||
* @copyright Colosa - Bolivia
|
|
||||||
*
|
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getDepartments()
|
public function getDepartments()
|
||||||
{
|
{
|
||||||
$oDepartment = new \Department();
|
$oDepartment = new DepartmentModel();
|
||||||
$aDepts = $oDepartment->getDepartments('');
|
$aDepts = $oDepartment->getDepartments('');
|
||||||
foreach ($aDepts as &$depData) {
|
foreach ($aDepts as &$depData) {
|
||||||
$depData['DEP_CHILDREN'] = $this->getChildren($depData);
|
$depData['DEP_CHILDREN'] = $this->getChildren($depData);
|
||||||
@@ -142,15 +141,14 @@ class Department
|
|||||||
*
|
*
|
||||||
* @param string $departmentUid Unique id of Department
|
* @param string $departmentUid Unique id of Department
|
||||||
* @param array $arrayData Data
|
* @param array $arrayData Data
|
||||||
*
|
|
||||||
* return array Return data of the User assigned to Department
|
* return array Return data of the User assigned to Department
|
||||||
*/
|
*/
|
||||||
public function assignUser($departmentUid, array $arrayData)
|
public function assignUser($departmentUid, array $arrayData)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
//Verify data
|
//Verify data
|
||||||
$process = new \ProcessMaker\BusinessModel\Process();
|
$process = new Process();
|
||||||
$validator = new \ProcessMaker\BusinessModel\Validator();
|
$validator = new Validator();
|
||||||
|
|
||||||
$validator->throwExceptionIfDataIsNotArray($arrayData, "\$arrayData");
|
$validator->throwExceptionIfDataIsNotArray($arrayData, "\$arrayData");
|
||||||
$validator->throwExceptionIfDataIsEmpty($arrayData, "\$arrayData");
|
$validator->throwExceptionIfDataIsEmpty($arrayData, "\$arrayData");
|
||||||
@@ -172,14 +170,14 @@ class Department
|
|||||||
);
|
);
|
||||||
|
|
||||||
//Verify data
|
//Verify data
|
||||||
$departmentUid = \ProcessMaker\BusinessModel\Validator::depUid($departmentUid);
|
$departmentUid = Validator::depUid($departmentUid);
|
||||||
|
|
||||||
$process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $arrayUserFieldDefinition, $arrayUserFieldNameForException, true);
|
$process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $arrayUserFieldDefinition, $arrayUserFieldNameForException, true);
|
||||||
|
|
||||||
$process->throwExceptionIfNotExistsUser($arrayData["USR_UID"], $arrayUserFieldNameForException["userUid"]);
|
$process->throwExceptionIfNotExistsUser($arrayData["USR_UID"], $arrayUserFieldNameForException["userUid"]);
|
||||||
|
|
||||||
//Assign User
|
//Assign User
|
||||||
$department = new \Department();
|
$department = new DepartmentModel();
|
||||||
|
|
||||||
$department->load($departmentUid);
|
$department->load($departmentUid);
|
||||||
|
|
||||||
@@ -192,7 +190,7 @@ class Department
|
|||||||
$arrayData = array_change_key_case($arrayData, CASE_LOWER);
|
$arrayData = array_change_key_case($arrayData, CASE_LOWER);
|
||||||
|
|
||||||
return $arrayData;
|
return $arrayData;
|
||||||
} catch (\Exception $e) {
|
} catch (Exception $e) {
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -201,9 +199,6 @@ class Department
|
|||||||
* Post Unassign User
|
* Post Unassign User
|
||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
|
||||||
* @copyright Colosa - Bolivia
|
|
||||||
*
|
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function unassignUser($dep_uid, $usr_uid)
|
public function unassignUser($dep_uid, $usr_uid)
|
||||||
@@ -213,7 +208,7 @@ class Department
|
|||||||
|
|
||||||
$this->throwExceptionUserNotExistsInDepartment($dep_uid, $usr_uid);
|
$this->throwExceptionUserNotExistsInDepartment($dep_uid, $usr_uid);
|
||||||
|
|
||||||
$dep = new \Department();
|
$dep = new DepartmentModel();
|
||||||
$dep->load( $dep_uid );
|
$dep->load( $dep_uid );
|
||||||
$manager = $dep->getDepManager();
|
$manager = $dep->getDepManager();
|
||||||
$dep->removeUserFromDepartment( $dep_uid, $usr_uid );
|
$dep->removeUserFromDepartment( $dep_uid, $usr_uid );
|
||||||
@@ -229,7 +224,6 @@ class Department
|
|||||||
* Get custom record
|
* Get custom record
|
||||||
*
|
*
|
||||||
* @param array $record Record
|
* @param array $record Record
|
||||||
*
|
|
||||||
* @return array Return an array with custom record
|
* @return array Return an array with custom record
|
||||||
*/
|
*/
|
||||||
private function __getUserCustomRecordFromRecord(array $record)
|
private function __getUserCustomRecordFromRecord(array $record)
|
||||||
@@ -248,7 +242,7 @@ class Department
|
|||||||
}
|
}
|
||||||
|
|
||||||
return $recordc;
|
return $recordc;
|
||||||
} catch (\Exception $e) {
|
} catch (Exception $e) {
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -266,7 +260,6 @@ class Department
|
|||||||
* @param bool $flagRecord Flag that set the "getting" of record
|
* @param bool $flagRecord Flag that set the "getting" of record
|
||||||
* @param bool $throwException Flag to throw the exception (This only if the parameters are invalid)
|
* @param bool $throwException Flag to throw the exception (This only if the parameters are invalid)
|
||||||
* (TRUE: throw the exception; FALSE: returns FALSE)
|
* (TRUE: throw the exception; FALSE: returns FALSE)
|
||||||
*
|
|
||||||
* @return array Return an array with all Users of a Department, ThrowTheException/FALSE otherwise
|
* @return array Return an array with all Users of a Department, ThrowTheException/FALSE otherwise
|
||||||
*/
|
*/
|
||||||
public function getUsers(
|
public function getUsers(
|
||||||
@@ -288,14 +281,14 @@ class Department
|
|||||||
//Verify data and Set variables
|
//Verify data and Set variables
|
||||||
$flagFilter = !is_null($arrayFilterData) && is_array($arrayFilterData) && isset($arrayFilterData['filter']);
|
$flagFilter = !is_null($arrayFilterData) && is_array($arrayFilterData) && isset($arrayFilterData['filter']);
|
||||||
|
|
||||||
$result = \ProcessMaker\BusinessModel\Validator::validatePagerDataByPagerDefinition(
|
$result = Validator::validatePagerDataByPagerDefinition(
|
||||||
['$start' => $start, '$limit' => $limit],
|
['$start' => $start, '$limit' => $limit],
|
||||||
['$start' => '$start', '$limit' => '$limit']
|
['$start' => '$start', '$limit' => '$limit']
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($result !== true) {
|
if ($result !== true) {
|
||||||
if ($throwException) {
|
if ($throwException) {
|
||||||
throw new \Exception($result);
|
throw new Exception($result);
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -336,23 +329,23 @@ class Department
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Query
|
//Query
|
||||||
$criteria = new \Criteria('workflow');
|
$criteria = new Criteria('workflow');
|
||||||
|
|
||||||
$criteria->addSelectColumn(\UsersPeer::USR_UID);
|
$criteria->addSelectColumn(UsersPeer::USR_UID);
|
||||||
$criteria->addSelectColumn(\UsersPeer::USR_USERNAME);
|
$criteria->addSelectColumn(UsersPeer::USR_USERNAME);
|
||||||
$criteria->addSelectColumn(\UsersPeer::USR_FIRSTNAME);
|
$criteria->addSelectColumn(UsersPeer::USR_FIRSTNAME);
|
||||||
$criteria->addSelectColumn(\UsersPeer::USR_LASTNAME);
|
$criteria->addSelectColumn(UsersPeer::USR_LASTNAME);
|
||||||
$criteria->addSelectColumn(\UsersPeer::USR_STATUS);
|
$criteria->addSelectColumn(UsersPeer::USR_STATUS);
|
||||||
|
|
||||||
$criteria->add(\UsersPeer::USR_STATUS, 'CLOSED', \Criteria::NOT_EQUAL);
|
$criteria->add(UsersPeer::USR_STATUS, 'CLOSED', Criteria::NOT_EQUAL);
|
||||||
|
|
||||||
switch ($option) {
|
switch ($option) {
|
||||||
case 'ASSIGNED':
|
case 'ASSIGNED':
|
||||||
$criteria->add(\UsersPeer::DEP_UID, $departmentUid, \Criteria::EQUAL);
|
$criteria->add(UsersPeer::DEP_UID, $departmentUid, Criteria::EQUAL);
|
||||||
break;
|
break;
|
||||||
case 'AVAILABLE':
|
case 'AVAILABLE':
|
||||||
$criteria->add(\UsersPeer::DEP_UID, '', \Criteria::EQUAL);
|
$criteria->add(UsersPeer::DEP_UID, '', Criteria::EQUAL);
|
||||||
$criteria->add(\UsersPeer::USR_UID, \RBAC::GUEST_USER_UID, \Criteria::NOT_EQUAL);
|
$criteria->add(UsersPeer::USR_UID, RBAC::GUEST_USER_UID, Criteria::NOT_EQUAL);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -368,24 +361,24 @@ class Department
|
|||||||
];
|
];
|
||||||
|
|
||||||
$criteria->add(
|
$criteria->add(
|
||||||
$criteria->getNewCriterion(\UsersPeer::USR_USERNAME, $search, \Criteria::LIKE)->addOr(
|
$criteria->getNewCriterion(UsersPeer::USR_USERNAME, $search, Criteria::LIKE)->addOr(
|
||||||
$criteria->getNewCriterion(\UsersPeer::USR_FIRSTNAME, $search, \Criteria::LIKE)->addOr(
|
$criteria->getNewCriterion(UsersPeer::USR_FIRSTNAME, $search, Criteria::LIKE)->addOr(
|
||||||
$criteria->getNewCriterion(\UsersPeer::USR_LASTNAME, $search, \Criteria::LIKE)))
|
$criteria->getNewCriterion(UsersPeer::USR_LASTNAME, $search, Criteria::LIKE)))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Number records total
|
//Number records total
|
||||||
$numRecTotal = \UsersPeer::doCount($criteria);
|
$numRecTotal = UsersPeer::doCount($criteria);
|
||||||
|
|
||||||
//Query
|
//Query
|
||||||
$conf = new \Configurations();
|
$conf = new Configurations();
|
||||||
$sortFieldDefault = \UsersPeer::TABLE_NAME . '.' . $conf->userNameFormatGetFirstFieldByUsersTable();
|
$sortFieldDefault = UsersPeer::TABLE_NAME . '.' . $conf->userNameFormatGetFirstFieldByUsersTable();
|
||||||
|
|
||||||
if (!is_null($sortField) && trim($sortField) != '') {
|
if (!is_null($sortField) && trim($sortField) != '') {
|
||||||
$sortField = strtoupper($sortField);
|
$sortField = strtoupper($sortField);
|
||||||
|
|
||||||
if (in_array(\UsersPeer::TABLE_NAME . '.' . $sortField, $criteria->getSelectColumns())) {
|
if (in_array(UsersPeer::TABLE_NAME . '.' . $sortField, $criteria->getSelectColumns())) {
|
||||||
$sortField = \UsersPeer::TABLE_NAME . '.' . $sortField;
|
$sortField = UsersPeer::TABLE_NAME . '.' . $sortField;
|
||||||
} else {
|
} else {
|
||||||
$sortField = $sortFieldDefault;
|
$sortField = $sortFieldDefault;
|
||||||
}
|
}
|
||||||
@@ -407,8 +400,8 @@ class Department
|
|||||||
$criteria->setLimit((int)($limit));
|
$criteria->setLimit((int)($limit));
|
||||||
}
|
}
|
||||||
|
|
||||||
$rsCriteria = \UsersPeer::doSelectRS($criteria);
|
$rsCriteria = UsersPeer::doSelectRS($criteria);
|
||||||
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
$rsCriteria->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
||||||
|
|
||||||
while ($rsCriteria->next()) {
|
while ($rsCriteria->next()) {
|
||||||
$record = $rsCriteria->getRow();
|
$record = $rsCriteria->getRow();
|
||||||
@@ -432,7 +425,7 @@ class Department
|
|||||||
$filterName => ($flagFilter)? $arrayFilterData['filter'] : '',
|
$filterName => ($flagFilter)? $arrayFilterData['filter'] : '',
|
||||||
'data' => $arrayUser
|
'data' => $arrayUser
|
||||||
];
|
];
|
||||||
} catch (\Exception $e) {
|
} catch (Exception $e) {
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -441,9 +434,6 @@ class Department
|
|||||||
* Put Set Manager User
|
* Put Set Manager User
|
||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
|
||||||
* @copyright Colosa - Bolivia
|
|
||||||
*
|
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setManagerUser($dep_uid, $usr_uid)
|
public function setManagerUser($dep_uid, $usr_uid)
|
||||||
@@ -451,23 +441,23 @@ class Department
|
|||||||
$dep_uid = Validator::depUid($dep_uid);
|
$dep_uid = Validator::depUid($dep_uid);
|
||||||
$usr_uid = Validator::usrUid($usr_uid);
|
$usr_uid = Validator::usrUid($usr_uid);
|
||||||
|
|
||||||
$oCriteria = new \Criteria( 'workflow' );
|
$oCriteria = new Criteria( 'workflow' );
|
||||||
$oCriteria->addSelectColumn( DepartmentPeer::DEP_UID );
|
$oCriteria->addSelectColumn( DepartmentPeer::DEP_UID );
|
||||||
$oCriteria->add( DepartmentPeer::DEP_MANAGER, $usr_uid, \Criteria::EQUAL );
|
$oCriteria->add( DepartmentPeer::DEP_MANAGER, $usr_uid, Criteria::EQUAL );
|
||||||
|
|
||||||
$oDataset = DepartmentPeer::doSelectRS( $oCriteria );
|
$oDataset = DepartmentPeer::doSelectRS( $oCriteria );
|
||||||
$oDataset->setFetchmode( \ResultSet::FETCHMODE_ASSOC );
|
$oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC );
|
||||||
if ($oDataset->next()) {
|
if ($oDataset->next()) {
|
||||||
throw (new \Exception(\G::LoadTranslation("ID_DEPARTMENT_MANAGER_EXIST", array('usr_uid',$usr_uid))));
|
throw (new Exception(G::LoadTranslation("ID_DEPARTMENT_MANAGER_EXIST", array('usr_uid',$usr_uid))));
|
||||||
}
|
}
|
||||||
|
|
||||||
$editDepartment['DEP_UID'] = $dep_uid;
|
$editDepartment['DEP_UID'] = $dep_uid;
|
||||||
$editDepartment['DEP_MANAGER'] = $usr_uid;
|
$editDepartment['DEP_MANAGER'] = $usr_uid;
|
||||||
$oDept = new \Department();
|
$oDept = new DepartmentModel();
|
||||||
$oDept->update( $editDepartment );
|
$oDept->update( $editDepartment );
|
||||||
$oDept->updateDepartmentManager( $dep_uid );
|
$oDept->updateDepartmentManager( $dep_uid );
|
||||||
|
|
||||||
$oDept = new \Department();
|
$oDept = new DepartmentModel();
|
||||||
$oDept->Load($dep_uid);
|
$oDept->Load($dep_uid);
|
||||||
$oDept->addUserToDepartment($dep_uid, $usr_uid, ($oDept->getDepManager() == "")? true : false, false);
|
$oDept->addUserToDepartment($dep_uid, $usr_uid, ($oDept->getDepManager() == "")? true : false, false);
|
||||||
$oDept->updateDepartmentManager($dep_uid);
|
$oDept->updateDepartmentManager($dep_uid);
|
||||||
@@ -475,22 +465,19 @@ class Department
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get list for Departments
|
* Get list for Departments
|
||||||
|
*
|
||||||
* @var string $dep_uid. Uid for Department
|
* @var string $dep_uid. Uid for Department
|
||||||
*
|
|
||||||
* @access public
|
* @access public
|
||||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
|
||||||
* @copyright Colosa - Bolivia
|
|
||||||
*
|
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getDepartment($dep_uid)
|
public function getDepartment($dep_uid)
|
||||||
{
|
{
|
||||||
$dep_uid = Validator::depUid($dep_uid);
|
$dep_uid = Validator::depUid($dep_uid);
|
||||||
$criteria = new \Criteria( 'workflow' );
|
$criteria = new Criteria( 'workflow' );
|
||||||
$criteria->add( DepartmentPeer::DEP_UID, $dep_uid, \Criteria::EQUAL );
|
$criteria->add( DepartmentPeer::DEP_UID, $dep_uid, Criteria::EQUAL );
|
||||||
$con = \Propel::getConnection( DepartmentPeer::DATABASE_NAME );
|
$con = Propel::getConnection( DepartmentPeer::DATABASE_NAME );
|
||||||
$objects = DepartmentPeer::doSelect( $criteria, $con );
|
$objects = DepartmentPeer::doSelect( $criteria, $con );
|
||||||
$oUsers = new \Users();
|
$oUsers = new Users();
|
||||||
|
|
||||||
$node = array ();
|
$node = array ();
|
||||||
foreach ($objects as $oDepartment) {
|
foreach ($objects as $oDepartment) {
|
||||||
@@ -514,14 +501,14 @@ class Department
|
|||||||
$node['DEP_MANAGER_LASTNAME'] = '';
|
$node['DEP_MANAGER_LASTNAME'] = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$criteria = new \Criteria();
|
$criteria = new Criteria();
|
||||||
$criteria->add(UsersPeer::DEP_UID, $dep_uid, \Criteria::EQUAL );
|
$criteria->add(UsersPeer::DEP_UID, $dep_uid, Criteria::EQUAL );
|
||||||
$node['DEP_MEMBERS'] = UsersPeer::doCount($criteria);
|
$node['DEP_MEMBERS'] = UsersPeer::doCount($criteria);
|
||||||
|
|
||||||
$criteriaCount = new \Criteria( 'workflow' );
|
$criteriaCount = new Criteria( 'workflow' );
|
||||||
$criteriaCount->clearSelectColumns();
|
$criteriaCount->clearSelectColumns();
|
||||||
$criteriaCount->addSelectColumn( 'COUNT(*)' );
|
$criteriaCount->addSelectColumn( 'COUNT(*)' );
|
||||||
$criteriaCount->add( DepartmentPeer::DEP_PARENT, $oDepartment->getDepUid(), \Criteria::EQUAL );
|
$criteriaCount->add( DepartmentPeer::DEP_PARENT, $oDepartment->getDepUid(), Criteria::EQUAL );
|
||||||
$rs = DepartmentPeer::doSelectRS( $criteriaCount );
|
$rs = DepartmentPeer::doSelectRS( $criteriaCount );
|
||||||
$rs->next();
|
$rs->next();
|
||||||
$row = $rs->getRow();
|
$row = $rs->getRow();
|
||||||
@@ -533,13 +520,10 @@ class Department
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Save Department
|
* Save Department
|
||||||
|
*
|
||||||
* @var string $dep_data. Data for Process
|
* @var string $dep_data. Data for Process
|
||||||
* @var string $create. Flag for create or update
|
* @var string $create. Flag for create or update
|
||||||
*
|
|
||||||
* @access public
|
* @access public
|
||||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
|
||||||
* @copyright Colosa - Bolivia
|
|
||||||
*
|
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function saveDepartment($dep_data, $create = true)
|
public function saveDepartment($dep_data, $create = true)
|
||||||
@@ -554,7 +538,7 @@ class Department
|
|||||||
unset($dep_data["DEP_UID"]);
|
unset($dep_data["DEP_UID"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$oDepartment = new \Department();
|
$oDepartment = new DepartmentModel();
|
||||||
if (isset($dep_data['DEP_UID']) && $dep_data['DEP_UID'] != '') {
|
if (isset($dep_data['DEP_UID']) && $dep_data['DEP_UID'] != '') {
|
||||||
Validator::depUid($dep_data['DEP_UID']);
|
Validator::depUid($dep_data['DEP_UID']);
|
||||||
}
|
}
|
||||||
@@ -581,7 +565,7 @@ class Department
|
|||||||
if (isset($dep_data['DEP_TITLE'])) {
|
if (isset($dep_data['DEP_TITLE'])) {
|
||||||
$this->throwExceptionIfExistsTitle($dep_data["DEP_TITLE"], strtolower("DEP_TITLE"));
|
$this->throwExceptionIfExistsTitle($dep_data["DEP_TITLE"], strtolower("DEP_TITLE"));
|
||||||
} else {
|
} else {
|
||||||
throw (new \Exception(\G::LoadTranslation("ID_FIELD_REQUIRED", array('dep_title'))));
|
throw (new Exception(G::LoadTranslation("ID_FIELD_REQUIRED", array('dep_title'))));
|
||||||
}
|
}
|
||||||
|
|
||||||
$dep_uid = $oDepartment->create($dep_data);
|
$dep_uid = $oDepartment->create($dep_data);
|
||||||
@@ -595,41 +579,35 @@ class Department
|
|||||||
* @var string $dep_uid. Uid for department
|
* @var string $dep_uid. Uid for department
|
||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
|
||||||
* @copyright Colosa - Bolivia
|
|
||||||
*
|
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function deleteDepartment($dep_uid)
|
public function deleteDepartment($dep_uid)
|
||||||
{
|
{
|
||||||
$dep_uid = Validator::depUid($dep_uid);
|
$dep_uid = Validator::depUid($dep_uid);
|
||||||
$oDepartment = new \Department();
|
$oDepartment = new DepartmentModel();
|
||||||
$countUsers = $oDepartment->cantUsersInDepartment($dep_uid);
|
$countUsers = $oDepartment->cantUsersInDepartment($dep_uid);
|
||||||
if ($countUsers != 0) {
|
if ($countUsers != 0) {
|
||||||
throw (new \Exception(\G::LoadTranslation("ID_CANT_DELETE_DEPARTMENT_HAS_USERS")));
|
throw (new Exception(G::LoadTranslation("ID_CANT_DELETE_DEPARTMENT_HAS_USERS")));
|
||||||
}
|
}
|
||||||
$dep_data = $this->getDepartment($dep_uid);
|
$dep_data = $this->getDepartment($dep_uid);
|
||||||
if ($dep_data['has_children'] != 0) {
|
if ($dep_data['has_children'] != 0) {
|
||||||
throw (new \Exception(\G::LoadTranslation("ID_CANT_DELETE_DEPARTMENT_HAS_CHILDREN")));
|
throw (new Exception(G::LoadTranslation("ID_CANT_DELETE_DEPARTMENT_HAS_CHILDREN")));
|
||||||
}
|
}
|
||||||
$oDepartment->remove($dep_uid);
|
$oDepartment->remove($dep_uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Look for Children for department
|
* Look for Children for department
|
||||||
|
*
|
||||||
* @var array $dataDep. Data for child department
|
* @var array $dataDep. Data for child department
|
||||||
*
|
|
||||||
* @access public
|
* @access public
|
||||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
|
||||||
* @copyright Colosa - Bolivia
|
|
||||||
*
|
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function getChildren ($dataDep)
|
protected function getChildren ($dataDep)
|
||||||
{
|
{
|
||||||
$children = array();
|
$children = array();
|
||||||
if ((int)$dataDep['HAS_CHILDREN'] > 0) {
|
if ((int)$dataDep['HAS_CHILDREN'] > 0) {
|
||||||
$oDepartment = new \Department();
|
$oDepartment = new DepartmentModel();
|
||||||
$aDepts = $oDepartment->getDepartments($dataDep['DEP_UID']);
|
$aDepts = $oDepartment->getDepartments($dataDep['DEP_UID']);
|
||||||
foreach ($aDepts as &$depData) {
|
foreach ($aDepts as &$depData) {
|
||||||
$depData['DEP_CHILDREN'] = $this->getChildren($depData);
|
$depData['DEP_CHILDREN'] = $this->getChildren($depData);
|
||||||
@@ -640,4 +618,3 @@ class Department
|
|||||||
return $children;
|
return $children;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,19 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace ProcessMaker\BusinessModel\Role;
|
namespace ProcessMaker\BusinessModel\Role;
|
||||||
|
|
||||||
|
use Configurations;
|
||||||
|
use Criteria;
|
||||||
|
use Exception;
|
||||||
|
use G;
|
||||||
|
use ProcessMaker\BusinessModel\Process;
|
||||||
|
use ProcessMaker\BusinessModel\Role;
|
||||||
|
use ProcessMaker\BusinessModel\Validator;
|
||||||
|
use RBAC;
|
||||||
|
use RbacUsersPeer;
|
||||||
|
use ResultSet;
|
||||||
|
use Roles;
|
||||||
|
use UsersRolesPeer;
|
||||||
|
|
||||||
class User
|
class User
|
||||||
{
|
{
|
||||||
private $arrayFieldDefinition = array(
|
private $arrayFieldDefinition = array(
|
||||||
@@ -19,7 +32,7 @@ class User
|
|||||||
/**
|
/**
|
||||||
* Constructor of the class
|
* Constructor of the class
|
||||||
*
|
*
|
||||||
* return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
@@ -27,7 +40,7 @@ class User
|
|||||||
foreach ($this->arrayFieldDefinition as $key => $value) {
|
foreach ($this->arrayFieldDefinition as $key => $value) {
|
||||||
$this->arrayFieldNameForException[$value["fieldNameAux"]] = $key;
|
$this->arrayFieldNameForException[$value["fieldNameAux"]] = $key;
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (Exception $e) {
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -36,8 +49,7 @@ class User
|
|||||||
* Set the format of the fields name (uppercase, lowercase)
|
* Set the format of the fields name (uppercase, lowercase)
|
||||||
*
|
*
|
||||||
* @param bool $flag Value that set the format
|
* @param bool $flag Value that set the format
|
||||||
*
|
* @return void
|
||||||
* return void
|
|
||||||
*/
|
*/
|
||||||
public function setFormatFieldNameInUppercase($flag)
|
public function setFormatFieldNameInUppercase($flag)
|
||||||
{
|
{
|
||||||
@@ -45,7 +57,7 @@ class User
|
|||||||
$this->formatFieldNameInUppercase = $flag;
|
$this->formatFieldNameInUppercase = $flag;
|
||||||
|
|
||||||
$this->setArrayFieldNameForException($this->arrayFieldNameForException);
|
$this->setArrayFieldNameForException($this->arrayFieldNameForException);
|
||||||
} catch (\Exception $e) {
|
} catch (Exception $e) {
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -54,8 +66,7 @@ class User
|
|||||||
* Set exception messages for fields
|
* Set exception messages for fields
|
||||||
*
|
*
|
||||||
* @param array $arrayData Data with the fields
|
* @param array $arrayData Data with the fields
|
||||||
*
|
* @return void
|
||||||
* return void
|
|
||||||
*/
|
*/
|
||||||
public function setArrayFieldNameForException(array $arrayData)
|
public function setArrayFieldNameForException(array $arrayData)
|
||||||
{
|
{
|
||||||
@@ -63,7 +74,7 @@ class User
|
|||||||
foreach ($arrayData as $key => $value) {
|
foreach ($arrayData as $key => $value) {
|
||||||
$this->arrayFieldNameForException[$key] = $this->getFieldNameByFormatFieldName($value);
|
$this->arrayFieldNameForException[$key] = $this->getFieldNameByFormatFieldName($value);
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (Exception $e) {
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -72,14 +83,13 @@ class User
|
|||||||
* Get the name of the field according to the format
|
* Get the name of the field according to the format
|
||||||
*
|
*
|
||||||
* @param string $fieldName Field name
|
* @param string $fieldName Field name
|
||||||
*
|
* @return string Return the field name according the format
|
||||||
* return string Return the field name according the format
|
|
||||||
*/
|
*/
|
||||||
public function getFieldNameByFormatFieldName($fieldName)
|
public function getFieldNameByFormatFieldName($fieldName)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
return ($this->formatFieldNameInUppercase)? strtoupper($fieldName) : strtolower($fieldName);
|
return ($this->formatFieldNameInUppercase)? strtoupper($fieldName) : strtolower($fieldName);
|
||||||
} catch (\Exception $e) {
|
} catch (Exception $e) {
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -90,18 +100,17 @@ class User
|
|||||||
* @param string $roleUid Unique id of Role
|
* @param string $roleUid Unique id of Role
|
||||||
* @param string $userUid Unique id of User
|
* @param string $userUid Unique id of User
|
||||||
* @param string $fieldNameForException Field name for the exception
|
* @param string $fieldNameForException Field name for the exception
|
||||||
*
|
* @return void Throw exception if it's assigned the User to Role
|
||||||
* return void Throw exception if it's assigned the User to Role
|
|
||||||
*/
|
*/
|
||||||
public function throwExceptionIfItsAssignedUserToRole($roleUid, $userUid, $fieldNameForException)
|
public function throwExceptionIfItsAssignedUserToRole($roleUid, $userUid, $fieldNameForException)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$obj = \UsersRolesPeer::retrieveByPK($userUid, $roleUid);
|
$obj = UsersRolesPeer::retrieveByPK($userUid, $roleUid);
|
||||||
|
|
||||||
if (!is_null($obj)) {
|
if (!is_null($obj)) {
|
||||||
throw new \Exception(\G::LoadTranslation("ID_ROLE_USER_IS_ALREADY_ASSIGNED", array($fieldNameForException, $userUid)));
|
throw new Exception(G::LoadTranslation("ID_ROLE_USER_IS_ALREADY_ASSIGNED", array($fieldNameForException, $userUid)));
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (Exception $e) {
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -112,18 +121,17 @@ class User
|
|||||||
* @param string $roleUid Unique id of Role
|
* @param string $roleUid Unique id of Role
|
||||||
* @param string $userUid Unique id of User
|
* @param string $userUid Unique id of User
|
||||||
* @param string $fieldNameForException Field name for the exception
|
* @param string $fieldNameForException Field name for the exception
|
||||||
*
|
* @return void Throw exception if not it's assigned the User to Role
|
||||||
* return void Throw exception if not it's assigned the User to Role
|
|
||||||
*/
|
*/
|
||||||
public function throwExceptionIfNotItsAssignedUserToRole($roleUid, $userUid, $fieldNameForException)
|
public function throwExceptionIfNotItsAssignedUserToRole($roleUid, $userUid, $fieldNameForException)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$obj = \UsersRolesPeer::retrieveByPK($userUid, $roleUid);
|
$obj = UsersRolesPeer::retrieveByPK($userUid, $roleUid);
|
||||||
|
|
||||||
if (is_null($obj)) {
|
if (is_null($obj)) {
|
||||||
throw new \Exception(\G::LoadTranslation("ID_ROLE_USER_IS_NOT_ASSIGNED", array($fieldNameForException, $userUid)));
|
throw new Exception(G::LoadTranslation("ID_ROLE_USER_IS_NOT_ASSIGNED", array($fieldNameForException, $userUid)));
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (Exception $e) {
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -133,15 +141,14 @@ class User
|
|||||||
*
|
*
|
||||||
* @param string $roleUid Unique id of Role
|
* @param string $roleUid Unique id of Role
|
||||||
* @param array $arrayData Data
|
* @param array $arrayData Data
|
||||||
*
|
* @return array Return data of the User assigned to Role
|
||||||
* return array Return data of the User assigned to Role
|
|
||||||
*/
|
*/
|
||||||
public function create($roleUid, array $arrayData)
|
public function create($roleUid, array $arrayData)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
//Verify data
|
//Verify data
|
||||||
$process = new \ProcessMaker\BusinessModel\Process();
|
$process = new Process();
|
||||||
$validator = new \ProcessMaker\BusinessModel\Validator();
|
$validator = new Validator();
|
||||||
|
|
||||||
$validator->throwExceptionIfDataIsEmpty($arrayData, "\$arrayData");
|
$validator->throwExceptionIfDataIsEmpty($arrayData, "\$arrayData");
|
||||||
|
|
||||||
@@ -151,7 +158,7 @@ class User
|
|||||||
unset($arrayData["ROL_UID"]);
|
unset($arrayData["ROL_UID"]);
|
||||||
|
|
||||||
//Verify data
|
//Verify data
|
||||||
$role = new \ProcessMaker\BusinessModel\Role();
|
$role = new Role();
|
||||||
|
|
||||||
$role->throwExceptionIfNotExistsRole($roleUid, $this->arrayFieldNameForException["roleUid"]);
|
$role->throwExceptionIfNotExistsRole($roleUid, $this->arrayFieldNameForException["roleUid"]);
|
||||||
|
|
||||||
@@ -162,11 +169,11 @@ class User
|
|||||||
$this->throwExceptionIfItsAssignedUserToRole($roleUid, $arrayData["USR_UID"], $this->arrayFieldNameForException["userUid"]);
|
$this->throwExceptionIfItsAssignedUserToRole($roleUid, $arrayData["USR_UID"], $this->arrayFieldNameForException["userUid"]);
|
||||||
|
|
||||||
if ($arrayData["USR_UID"] == "00000000000000000000000000000001") {
|
if ($arrayData["USR_UID"] == "00000000000000000000000000000001") {
|
||||||
throw new \Exception(\G::LoadTranslation("ID_ADMINISTRATOR_ROLE_CANT_CHANGED"));
|
throw new Exception(G::LoadTranslation("ID_ADMINISTRATOR_ROLE_CANT_CHANGED"));
|
||||||
}
|
}
|
||||||
|
|
||||||
//Create
|
//Create
|
||||||
$role = new \Roles();
|
$role = new Roles();
|
||||||
|
|
||||||
$arrayData = array_merge(array("ROL_UID" => $roleUid), $arrayData);
|
$arrayData = array_merge(array("ROL_UID" => $roleUid), $arrayData);
|
||||||
|
|
||||||
@@ -178,7 +185,7 @@ class User
|
|||||||
}
|
}
|
||||||
|
|
||||||
return $arrayData;
|
return $arrayData;
|
||||||
} catch (\Exception $e) {
|
} catch (Exception $e) {
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -188,15 +195,14 @@ class User
|
|||||||
*
|
*
|
||||||
* @param string $roleUid Unique id of Role
|
* @param string $roleUid Unique id of Role
|
||||||
* @param string $userUid Unique id of User
|
* @param string $userUid Unique id of User
|
||||||
*
|
* @return void
|
||||||
* return void
|
|
||||||
*/
|
*/
|
||||||
public function delete($roleUid, $userUid)
|
public function delete($roleUid, $userUid)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
//Verify data
|
//Verify data
|
||||||
$process = new \ProcessMaker\BusinessModel\Process();
|
$process = new Process();
|
||||||
$role = new \ProcessMaker\BusinessModel\Role();
|
$role = new Role();
|
||||||
|
|
||||||
$role->throwExceptionIfNotExistsRole($roleUid, $this->arrayFieldNameForException["roleUid"]);
|
$role->throwExceptionIfNotExistsRole($roleUid, $this->arrayFieldNameForException["roleUid"]);
|
||||||
|
|
||||||
@@ -205,14 +211,14 @@ class User
|
|||||||
$this->throwExceptionIfNotItsAssignedUserToRole($roleUid, $userUid, $this->arrayFieldNameForException["userUid"]);
|
$this->throwExceptionIfNotItsAssignedUserToRole($roleUid, $userUid, $this->arrayFieldNameForException["userUid"]);
|
||||||
|
|
||||||
if ($userUid == "00000000000000000000000000000001") {
|
if ($userUid == "00000000000000000000000000000001") {
|
||||||
throw new \Exception(\G::LoadTranslation("ID_ADMINISTRATOR_ROLE_CANT_CHANGED"));
|
throw new Exception(G::LoadTranslation("ID_ADMINISTRATOR_ROLE_CANT_CHANGED"));
|
||||||
}
|
}
|
||||||
|
|
||||||
//Delete
|
//Delete
|
||||||
$role = new \Roles();
|
$role = new Roles();
|
||||||
|
|
||||||
$role->deleteUserRole($roleUid, $userUid);
|
$role->deleteUserRole($roleUid, $userUid);
|
||||||
} catch (\Exception $e) {
|
} catch (Exception $e) {
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -221,8 +227,7 @@ class User
|
|||||||
* Get data of a User from a record
|
* Get data of a User from a record
|
||||||
*
|
*
|
||||||
* @param array $record Record
|
* @param array $record Record
|
||||||
*
|
* @return array Return an array with data User
|
||||||
* return array Return an array with data User
|
|
||||||
*/
|
*/
|
||||||
public function getUserDataFromRecord(array $record)
|
public function getUserDataFromRecord(array $record)
|
||||||
{
|
{
|
||||||
@@ -234,7 +239,7 @@ class User
|
|||||||
$this->getFieldNameByFormatFieldName("USR_LASTNAME") => $record["USR_LASTNAME"] . "",
|
$this->getFieldNameByFormatFieldName("USR_LASTNAME") => $record["USR_LASTNAME"] . "",
|
||||||
$this->getFieldNameByFormatFieldName("USR_STATUS") => ($record["USR_STATUS"] . "" == "1")? "ACTIVE" : "INACTIVE"
|
$this->getFieldNameByFormatFieldName("USR_STATUS") => ($record["USR_STATUS"] . "" == "1")? "ACTIVE" : "INACTIVE"
|
||||||
);
|
);
|
||||||
} catch (\Exception $e) {
|
} catch (Exception $e) {
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -249,8 +254,7 @@ class User
|
|||||||
* @param string $sortDir Direction of sorting (ASC, DESC)
|
* @param string $sortDir Direction of sorting (ASC, DESC)
|
||||||
* @param int $start Start
|
* @param int $start Start
|
||||||
* @param int $limit Limit
|
* @param int $limit Limit
|
||||||
*
|
* @return array Return an array with all Users of a Role
|
||||||
* return array Return an array with all Users of a Role
|
|
||||||
*/
|
*/
|
||||||
public function getUsers($roleUid, $option, array $arrayFilterData = null, $sortField = null, $sortDir = null, $start = null, $limit = null)
|
public function getUsers($roleUid, $option, array $arrayFilterData = null, $sortField = null, $sortDir = null, $start = null, $limit = null)
|
||||||
{
|
{
|
||||||
@@ -262,8 +266,8 @@ class User
|
|||||||
//Verify data and Set variables
|
//Verify data and Set variables
|
||||||
$flagFilter = !is_null($arrayFilterData) && is_array($arrayFilterData) && isset($arrayFilterData['filter']);
|
$flagFilter = !is_null($arrayFilterData) && is_array($arrayFilterData) && isset($arrayFilterData['filter']);
|
||||||
|
|
||||||
$process = new \ProcessMaker\BusinessModel\Process();
|
$process = new Process();
|
||||||
$role = new \ProcessMaker\BusinessModel\Role();
|
$role = new Role();
|
||||||
|
|
||||||
$role->throwExceptionIfNotExistsRole($roleUid, $this->arrayFieldNameForException["roleUid"]);
|
$role->throwExceptionIfNotExistsRole($roleUid, $this->arrayFieldNameForException["roleUid"]);
|
||||||
|
|
||||||
@@ -303,25 +307,25 @@ class User
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Query
|
//Query
|
||||||
$criteria = new \Criteria('rbac');
|
$criteria = new Criteria('rbac');
|
||||||
|
|
||||||
$criteria->addSelectColumn(\RbacUsersPeer::USR_UID);
|
$criteria->addSelectColumn(RbacUsersPeer::USR_UID);
|
||||||
$criteria->addSelectColumn(\RbacUsersPeer::USR_USERNAME);
|
$criteria->addSelectColumn(RbacUsersPeer::USR_USERNAME);
|
||||||
$criteria->addSelectColumn(\RbacUsersPeer::USR_FIRSTNAME);
|
$criteria->addSelectColumn(RbacUsersPeer::USR_FIRSTNAME);
|
||||||
$criteria->addSelectColumn(\RbacUsersPeer::USR_LASTNAME);
|
$criteria->addSelectColumn(RbacUsersPeer::USR_LASTNAME);
|
||||||
$criteria->addSelectColumn(\RbacUsersPeer::USR_STATUS);
|
$criteria->addSelectColumn(RbacUsersPeer::USR_STATUS);
|
||||||
|
|
||||||
$criteria->addJoin(\RbacUsersPeer::USR_UID, \UsersRolesPeer::USR_UID, \Criteria::LEFT_JOIN);
|
$criteria->addJoin(RbacUsersPeer::USR_UID, UsersRolesPeer::USR_UID, Criteria::LEFT_JOIN);
|
||||||
|
|
||||||
$criteria->add(\RbacUsersPeer::USR_USERNAME, '', \Criteria::NOT_EQUAL);
|
$criteria->add(RbacUsersPeer::USR_USERNAME, '', Criteria::NOT_EQUAL);
|
||||||
|
|
||||||
switch ($option) {
|
switch ($option) {
|
||||||
case "USERS":
|
case "USERS":
|
||||||
$criteria->add(\UsersRolesPeer::ROL_UID, $roleUid, \Criteria::EQUAL);
|
$criteria->add(UsersRolesPeer::ROL_UID, $roleUid, Criteria::EQUAL);
|
||||||
break;
|
break;
|
||||||
case "AVAILABLE-USERS":
|
case "AVAILABLE-USERS":
|
||||||
$criteria->add(\UsersRolesPeer::ROL_UID, $roleUid, \Criteria::NOT_EQUAL);
|
$criteria->add(UsersRolesPeer::ROL_UID, $roleUid, Criteria::NOT_EQUAL);
|
||||||
$criteria->add(\RbacUsersPeer::USR_UID, [\RBAC::GUEST_USER_UID], \Criteria::NOT_IN);
|
$criteria->add(RbacUsersPeer::USR_UID, [RBAC::GUEST_USER_UID], Criteria::NOT_IN);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -337,24 +341,24 @@ class User
|
|||||||
];
|
];
|
||||||
|
|
||||||
$criteria->add(
|
$criteria->add(
|
||||||
$criteria->getNewCriterion(\RbacUsersPeer::USR_USERNAME, $search, \Criteria::LIKE)->addOr(
|
$criteria->getNewCriterion(RbacUsersPeer::USR_USERNAME, $search, Criteria::LIKE)->addOr(
|
||||||
$criteria->getNewCriterion(\RbacUsersPeer::USR_FIRSTNAME, $search, \Criteria::LIKE)->addOr(
|
$criteria->getNewCriterion(RbacUsersPeer::USR_FIRSTNAME, $search, Criteria::LIKE)->addOr(
|
||||||
$criteria->getNewCriterion(\RbacUsersPeer::USR_LASTNAME, $search, \Criteria::LIKE)))
|
$criteria->getNewCriterion(RbacUsersPeer::USR_LASTNAME, $search, Criteria::LIKE)))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Number records total
|
//Number records total
|
||||||
$numRecTotal = \RbacUsersPeer::doCount($criteria);
|
$numRecTotal = RbacUsersPeer::doCount($criteria);
|
||||||
|
|
||||||
//Query
|
//Query
|
||||||
$conf = new \Configurations();
|
$conf = new Configurations();
|
||||||
$sortFieldDefault = \RbacUsersPeer::TABLE_NAME . '.' . $conf->userNameFormatGetFirstFieldByUsersTable();
|
$sortFieldDefault = RbacUsersPeer::TABLE_NAME . '.' . $conf->userNameFormatGetFirstFieldByUsersTable();
|
||||||
|
|
||||||
if (!is_null($sortField) && trim($sortField) != '') {
|
if (!is_null($sortField) && trim($sortField) != '') {
|
||||||
$sortField = strtoupper($sortField);
|
$sortField = strtoupper($sortField);
|
||||||
|
|
||||||
if (in_array(\RbacUsersPeer::TABLE_NAME . '.' . $sortField, $criteria->getSelectColumns())) {
|
if (in_array(RbacUsersPeer::TABLE_NAME . '.' . $sortField, $criteria->getSelectColumns())) {
|
||||||
$sortField = \RbacUsersPeer::TABLE_NAME . '.' . $sortField;
|
$sortField = RbacUsersPeer::TABLE_NAME . '.' . $sortField;
|
||||||
} else {
|
} else {
|
||||||
$sortField = $sortFieldDefault;
|
$sortField = $sortFieldDefault;
|
||||||
}
|
}
|
||||||
@@ -376,8 +380,8 @@ class User
|
|||||||
$criteria->setLimit((int)($limit));
|
$criteria->setLimit((int)($limit));
|
||||||
}
|
}
|
||||||
|
|
||||||
$rsCriteria = \RbacUsersPeer::doSelectRS($criteria);
|
$rsCriteria = RbacUsersPeer::doSelectRS($criteria);
|
||||||
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
$rsCriteria->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
||||||
|
|
||||||
while ($rsCriteria->next()) {
|
while ($rsCriteria->next()) {
|
||||||
$row = $rsCriteria->getRow();
|
$row = $rsCriteria->getRow();
|
||||||
@@ -393,7 +397,7 @@ class User
|
|||||||
$filterName => ($flagFilter)? $arrayFilterData['filter'] : '',
|
$filterName => ($flagFilter)? $arrayFilterData['filter'] : '',
|
||||||
'data' => $arrayUser
|
'data' => $arrayUser
|
||||||
];
|
];
|
||||||
} catch (\Exception $e) {
|
} catch (Exception $e) {
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user