HOR-378 "PM 3.0.1.7: El modo de derivacion 'Reports To'..." SOLVED
Issue:
PM 3.0.1.7: El modo de derivacion "Reports To" no funciona correctamente
Cause:
Se obtiene de manera incorrecta el manager de un usuario (No se respeta la jerarquia de los departamentos)
Solution:
- Se revirtio los cambios del card PMLOCAL-3705
- Se creo un metodo para obtener el manager de un usuario (Respetando la jerarquia de los departamentos)
This commit is contained in:
@@ -636,15 +636,12 @@ class Derivation
|
||||
*/
|
||||
function getDenpendentUser ($USR_UID)
|
||||
{
|
||||
//Here the uid to next user
|
||||
$oC = new Criteria();
|
||||
$oC->addSelectColumn( UsersPeer::USR_REPORTS_TO );
|
||||
$oC->add( UsersPeer::USR_UID, $USR_UID );
|
||||
$oDataset = UsersPeer::doSelectRS( $oC );
|
||||
$oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC );
|
||||
$oDataset->next();
|
||||
$aRow = $oDataset->getRow();
|
||||
return $aRow['USR_REPORTS_TO'] != '' ? $aRow['USR_REPORTS_TO'] : $USR_UID;
|
||||
$user = new \ProcessMaker\BusinessModel\User();
|
||||
|
||||
$manager = $user->getUsersManager($USR_UID);
|
||||
|
||||
//Return
|
||||
return ($manager !== false)? $manager : $USR_UID;
|
||||
}
|
||||
|
||||
/* setTasLastAssigned
|
||||
|
||||
@@ -114,7 +114,7 @@ class Department extends BaseDepartment
|
||||
$res = $this->save();
|
||||
|
||||
$con->commit();
|
||||
|
||||
|
||||
G::auditLog("Create".$msgLog, $msgLog." Name: ". $aData['DEP_TITLE']);
|
||||
|
||||
return $this->getDepUid();
|
||||
@@ -332,7 +332,7 @@ class Department extends BaseDepartment
|
||||
}
|
||||
|
||||
public function updateDepartmentManager ($depId)
|
||||
{
|
||||
{
|
||||
$managerId = '';
|
||||
$depParent = '';
|
||||
$oDept = DepartmentPeer::retrieveByPk( $depId );
|
||||
@@ -347,10 +347,6 @@ class Department extends BaseDepartment
|
||||
$selectCriteria = new Criteria( 'workflow' );
|
||||
$selectCriteria->add( UsersPeer::DEP_UID, $depId );
|
||||
$selectCriteria->add( UsersPeer::USR_UID, $managerId, Criteria::NOT_EQUAL );
|
||||
|
||||
if(empty($depParent)) {
|
||||
$depParent = $depId;
|
||||
}
|
||||
|
||||
// Create a Criteria object includes the value you want to set
|
||||
$updateCriteria = new Criteria( 'workflow' );
|
||||
@@ -370,7 +366,7 @@ class Department extends BaseDepartment
|
||||
}
|
||||
$oUser->save();
|
||||
}
|
||||
|
||||
|
||||
if ($managerId) {
|
||||
$user = $oUser->loadDetailed ($managerId);
|
||||
if (is_object( $oDept ) && get_class( $oDept ) == 'Department') {
|
||||
@@ -393,41 +389,6 @@ class Department extends BaseDepartment
|
||||
}
|
||||
$oDataset->next();
|
||||
}
|
||||
|
||||
$this->updateUserReportsTo($depId);
|
||||
}
|
||||
|
||||
public function updateUserReportsTo($depId)
|
||||
{
|
||||
$departments = $this->getChildDepartments($depId);
|
||||
$departments = explode("_",$departments);
|
||||
$departments = array_filter(array_unique($departments));
|
||||
foreach($departments as $depUid) {
|
||||
$mgrParentId = $this->getDepartmentParentManager($depUid);
|
||||
$conn = Propel::getConnection( UsersPeer::DATABASE_NAME );
|
||||
$selectCriteria = new Criteria( 'workflow' );
|
||||
$selectCriteria->add( UsersPeer::DEP_UID, $depUid );
|
||||
$updateCriteria = new Criteria( 'workflow' );
|
||||
$updateCriteria->add( UsersPeer::USR_REPORTS_TO, $mgrParentId );
|
||||
BasePeer::doUpdate( $selectCriteria, $updateCriteria, $conn );
|
||||
}
|
||||
}
|
||||
|
||||
public function getChildDepartments($depId)
|
||||
{
|
||||
$depIds = "";
|
||||
$depIds .= $depId."_";
|
||||
$childrenCriteria = new Criteria( 'workflow' );
|
||||
$childrenCriteria->add( DepartmentPeer::DEP_PARENT, $depId );
|
||||
$oDataset = DepartmentPeer::doSelectRS( $childrenCriteria );
|
||||
$oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC );
|
||||
$oDataset->next();
|
||||
while ($aRow = $oDataset->getRow()) {
|
||||
$depId = $aRow['DEP_UID'];
|
||||
$depIds .= $this->getChildDepartments($depId);
|
||||
$oDataset->next();
|
||||
}
|
||||
return $depIds;
|
||||
}
|
||||
|
||||
//add an user to a department and sync all about manager info
|
||||
@@ -623,7 +584,7 @@ class Department extends BaseDepartment
|
||||
$oUser->setDepUid( '' );
|
||||
$oUser->setUsrReportsTo( '' );
|
||||
$oUser->save();
|
||||
|
||||
|
||||
G::auditLog("RemoveUsersFromDepartament", "Remove user ".$user['USR_USERNAME']."( ".$UsrUid.") from departament ".$dptoTitle['DEPO_TITLE']." (".$DepUid.") ");
|
||||
}
|
||||
} catch (exception $oError) {
|
||||
@@ -738,19 +699,5 @@ class Department extends BaseDepartment
|
||||
}
|
||||
return $departments;
|
||||
}
|
||||
|
||||
public function getDepartmentParentManager($depId)
|
||||
{
|
||||
$managerUid = "";
|
||||
$depInfo = $this->Load($depId);
|
||||
if(empty($depInfo['DEP_MANAGER'])) {
|
||||
if(!empty($depInfo['DEP_PARENT'])) {
|
||||
$managerUid = $this->getDepartmentParentManager($depInfo['DEP_PARENT']);
|
||||
}
|
||||
} else {
|
||||
$managerUid = $depInfo['DEP_MANAGER'];
|
||||
}
|
||||
return $managerUid;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -91,6 +91,41 @@ class Department
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Department record
|
||||
*
|
||||
* @param string $departmentUid Unique id of Department
|
||||
* @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
|
||||
* (TRUE: throw the exception; FALSE: returns FALSE)
|
||||
*
|
||||
* @return array Returns an array with Department record, ThrowTheException/FALSE otherwise
|
||||
*/
|
||||
public function getDepartmentRecordByPk(
|
||||
$departmentUid,
|
||||
array $arrayVariableNameForException,
|
||||
$throwException = true
|
||||
) {
|
||||
try {
|
||||
$obj = \DepartmentPeer::retrieveByPK($departmentUid);
|
||||
|
||||
if (is_null($obj)) {
|
||||
if ($throwException) {
|
||||
throw new \Exception(\G::LoadTranslation(
|
||||
'ID_DEPARTMENT_NOT_EXIST', [$arrayVariableNameForException['$departmentUid'], $departmentUid]
|
||||
));
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//Return
|
||||
return $obj->toArray(\BasePeer::TYPE_FIELDNAME);
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list for Departments
|
||||
*
|
||||
@@ -187,7 +222,7 @@ class Department
|
||||
$oCriteria->setOffset( $start );
|
||||
|
||||
if ($search != '') {
|
||||
$oCriteria->add( $oCriteria->getNewCriterion( UsersPeer::USR_USERNAME, '%' . $search . '%', \Criteria::LIKE )->addOr( $oCriteria->getNewCriterion( UsersPeer::USR_FIRSTNAME, '%' . $search . '%', \Criteria::LIKE )->addOr( $oCriteria->getNewCriterion( UsersPeer::USR_LASTNAME, '%' . $search . '%', \Criteria::LIKE ) ) ) );
|
||||
$oCriteria->add( $oCriteria->getNewCriterion( UsersPeer::USR_USERNAME, '%' . $search . '%', \Criteria::LIKE )->addOr( $oCriteria->getNewCriterion( UsersPeer::USR_FIRSTNAME, '%' . $search . '%', \Criteria::LIKE )->addOr( $oCriteria->getNewCriterion( UsersPeer::USR_LASTNAME, '%' . $search . '%', \Criteria::LIKE ) ) ) );
|
||||
}
|
||||
|
||||
$oDataset = UsersPeer::doSelectRS( $oCriteria );
|
||||
|
||||
@@ -328,6 +328,38 @@ class User
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get User record
|
||||
*
|
||||
* @param string $userUid Unique id of User
|
||||
* @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
|
||||
* (TRUE: throw the exception; FALSE: returns FALSE)
|
||||
*
|
||||
* @return array Returns an array with User record, ThrowTheException/FALSE otherwise
|
||||
*/
|
||||
public function getUserRecordByPk($userUid, array $arrayVariableNameForException, $throwException = true)
|
||||
{
|
||||
try {
|
||||
$obj = \UsersPeer::retrieveByPK($userUid);
|
||||
|
||||
if (is_null($obj)) {
|
||||
if ($throwException) {
|
||||
throw new \Exception(\G::LoadTranslation(
|
||||
'ID_USER_DOES_NOT_EXIST', [$arrayVariableNameForException['$userUid'], $userUid]
|
||||
));
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//Return
|
||||
return $obj->toArray(\BasePeer::TYPE_FIELDNAME);
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data of a from a record
|
||||
*
|
||||
@@ -1288,5 +1320,68 @@ class User
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the User's Manager
|
||||
*
|
||||
* @param string $userUid Unique id of User
|
||||
* @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)
|
||||
*
|
||||
* @return string Returns an string with Unique id of User (Manager), ThrowTheException/FALSE otherwise
|
||||
*/
|
||||
public function getUsersManager($userUid, $throwException = true)
|
||||
{
|
||||
try {
|
||||
//Verify data and Set variables
|
||||
$arrayUserData = $this->getUserRecordByPk($userUid, ['$userUid' => '$userUid'], $throwException);
|
||||
|
||||
if ($arrayUserData === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//Set variables
|
||||
$department = new \ProcessMaker\BusinessModel\Department();
|
||||
|
||||
//Get Manager
|
||||
if ((string)($arrayUserData['USR_REPORTS_TO']) == '' ||
|
||||
(string)($arrayUserData['USR_REPORTS_TO']) == $userUid
|
||||
) {
|
||||
if ((string)($arrayUserData['DEP_UID']) != '') {
|
||||
$departmentUid = $arrayUserData['DEP_UID'];
|
||||
|
||||
do {
|
||||
$flagd = false;
|
||||
|
||||
$arrayDepartmentData = $department->getDepartmentRecordByPk(
|
||||
$departmentUid, ['$departmentUid' => '$departmentUid'], $throwException
|
||||
);
|
||||
|
||||
if ($arrayDepartmentData === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((string)($arrayDepartmentData['DEP_MANAGER']) == '' ||
|
||||
(string)($arrayDepartmentData['DEP_MANAGER']) == $userUid
|
||||
) {
|
||||
if ((string)($arrayDepartmentData['DEP_PARENT']) != '') {
|
||||
$departmentUid = $arrayDepartmentData['DEP_PARENT'];
|
||||
$flagd = true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return $arrayDepartmentData['DEP_MANAGER'];
|
||||
}
|
||||
} while ($flagd);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return $arrayUserData['USR_REPORTS_TO'];
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user