Merged in cochalo/processmaker (pull request #375)

Adicion de puntos faltantes en DEPARTMENTS
This commit is contained in:
erik ao
2014-04-07 16:18:31 -04:00
2 changed files with 254 additions and 1 deletions

View File

@@ -31,6 +31,142 @@ class Department
return $aDepts;
}
/**
* Get list for Assigned User
*
* @access public
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
* @copyright Colosa - Bolivia
*
* @return array
*/
public function getAssignedUser($dep_uid)
{
$dep_uid = Validator::depUid($dep_uid);
$oDept = new \Department();
$oDept->Load( $dep_uid );
$manager = $oDept->getDepManager();
$oCriteria = new \Criteria( 'workflow' );
$oCriteria->addSelectColumn( UsersPeer::USR_UID );
$oCriteria->addSelectColumn( UsersPeer::USR_USERNAME );
$oCriteria->addSelectColumn( UsersPeer::USR_FIRSTNAME );
$oCriteria->addSelectColumn( UsersPeer::USR_LASTNAME );
$oCriteria->addSelectColumn( UsersPeer::USR_STATUS );
$oCriteria->add( UsersPeer::DEP_UID, '' );
$oCriteria->add( UsersPeer::USR_STATUS, 'CLOSED', \Criteria::NOT_EQUAL );
$oCriteria->add( UsersPeer::DEP_UID, $dep_uid );
$oDataset = UsersPeer::doSelectRS( $oCriteria );
$oDataset->setFetchmode( \ResultSet::FETCHMODE_ASSOC );
$aUsers = array ();
while ($oDataset->next()) {
$dataTemp = $oDataset->getRow();
$aUsers[] = array_change_key_case($dataTemp, CASE_LOWER);
$index = sizeof( $aUsers ) - 1;
$aUsers[$index]['usr_supervisor'] = ($manager == $aUsers[$index]['usr_uid']) ? true : false;
}
return $aUsers;
}
/**
* Get list for Available User
*
* @access public
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
* @copyright Colosa - Bolivia
*
* @return array
*/
public function getAvailableUser($dep_uid)
{
$dep_uid = Validator::depUid($dep_uid);
$oCriteria = new \Criteria( 'workflow' );
$oCriteria->addSelectColumn( UsersPeer::USR_UID );
$oCriteria->addSelectColumn( UsersPeer::USR_USERNAME );
$oCriteria->addSelectColumn( UsersPeer::USR_FIRSTNAME );
$oCriteria->addSelectColumn( UsersPeer::USR_LASTNAME );
$oCriteria->addSelectColumn( UsersPeer::USR_STATUS );
$oCriteria->add( UsersPeer::DEP_UID, '' );
$oCriteria->add( UsersPeer::USR_STATUS, 'CLOSED', \Criteria::NOT_EQUAL );
$oDataset = UsersPeer::doSelectRS( $oCriteria );
$oDataset->setFetchmode( \ResultSet::FETCHMODE_ASSOC );
$aUsers = array ();
while ($oDataset->next()) {
$dataTemp = $oDataset->getRow();
$aUsers[] = array_change_key_case($dataTemp, CASE_LOWER);
}
return $aUsers;
}
/**
* Put Assign User
*
* @access public
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
* @copyright Colosa - Bolivia
*
* @return void
*/
public function assignUser($dep_uid, $usr_uid)
{
$dep_uid = Validator::depUid($dep_uid);
$usr_uid = Validator::usrUid($usr_uid);
$dep = new \Department();
$dep->load($dep_uid);
$dep_manager = $dep->getDepManager();
$manager = ($dep_manager == '') ? true : false;
$dep->addUserToDepartment( $dep_uid, $usr_uid, $manager, false );
$dep->updateDepartmentManager( $dep_uid );
}
/**
* Post Unassign User
*
* @access public
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
* @copyright Colosa - Bolivia
*
* @return void
*/
public function unassignUser($dep_uid, $usr_uid)
{
$dep_uid = Validator::depUid($dep_uid);
$usr_uid = Validator::usrUid($usr_uid);
$dep = new \Department();
$dep->load( $dep_uid );
$manager = $dep->getDepManager();
$dep->removeUserFromDepartment( $dep_uid, $usr_uid );
if ($usr_uid == $manager) {
$editDepto['DEP_UID'] = $dep_uid;
$editDepto['DEP_MANAGER'] = '';
$dep->update( $editDepto );
$dep->updateDepartmentManager($dep_uid);
}
}
/**
* Put Set Manager User
*
* @access public
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
* @copyright Colosa - Bolivia
*
* @return void
*/
public function setManagerUser($dep_uid, $usr_uid)
{
$dep_uid = Validator::depUid($dep_uid);
$usr_uid = Validator::usrUid($usr_uid);
$editDepartment['DEP_UID'] = $dep_uid;
$editDepartment['DEP_MANAGER'] = $usr_uid;
$oDept = new \Department();
$oDept->update( $editDepartment );
$oDept->updateDepartmentManager( $dep_uid );
}
/**
* Get list for Departments
* @var string $dep_uid. Uid for Department
@@ -149,11 +285,15 @@ class Department
public function deleteDepartment($dep_uid)
{
$dep_uid = Validator::depUid($dep_uid);
$oDepartment = new \Department();
$countUsers = $oDepartment->cantUsersInDepartment($dep_uid);
if ($countUsers != 0) {
throw (new \Exception("Department cannot be deleted while has assigned users."));
}
$dep_data = $this->getDepartment($dep_uid);
if ($dep_data['has_children'] != 0) {
throw (new \Exception("Can not delete the department, it has a children department."));
}
$oDepartment = new \Department();
$oDepartment->remove($dep_uid);
}

View File

@@ -35,6 +35,119 @@ class Department extends Api
}
}
/**
* @param string $dep_uid {@min 1}{@max 32}
*
* @access public
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
* @copyright Colosa - Bolivia
*
* @return array
*
* @url GET /:dep_uid/assigned-user
*/
public function doGetAssignedUser($dep_uid)
{
try {
$oDepartment = new \ProcessMaker\BusinessModel\Department();
$response = $oDepartment->getAssignedUser($dep_uid);
return $response;
} catch (\Exception $e) {
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
}
}
/**
* @param string $dep_uid {@min 1}{@max 32}
*
* @access public
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
* @copyright Colosa - Bolivia
*
* @return array
*
* @url GET /:dep_uid/available-user
*/
public function doGetAvailableUser($dep_uid)
{
try {
$oDepartment = new \ProcessMaker\BusinessModel\Department();
$response = $oDepartment->getAvailableUser($dep_uid);
return $response;
} catch (\Exception $e) {
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
}
}
/**
* @param string $dep_uid {@min 1}{@max 32}
* @param string $usr_uid {@min 1}{@max 32}
*
* @access public
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
* @copyright Colosa - Bolivia
*
* @return array
*
* @url PUT /:dep_uid/assign-user/:usr_uid
*/
public function doPutAssignUser($dep_uid, $usr_uid)
{
try {
$oDepartment = new \ProcessMaker\BusinessModel\Department();
$response = $oDepartment->assignUser($dep_uid, $usr_uid);
return $response;
} catch (\Exception $e) {
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
}
}
/**
* @param string $dep_uid {@min 1}{@max 32}
* @param string $usr_uid {@min 1}{@max 32}
*
* @access public
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
* @copyright Colosa - Bolivia
*
* @return array
*
* @url PUT /:dep_uid/unassign-user/:usr_uid
*/
public function doPutUnassignUser($dep_uid, $usr_uid)
{
try {
$oDepartment = new \ProcessMaker\BusinessModel\Department();
$response = $oDepartment->unassignUser($dep_uid, $usr_uid);
return $response;
} catch (\Exception $e) {
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
}
}
/**
* @param string $dep_uid {@min 1}{@max 32}
* @param string $usr_uid {@min 1}{@max 32}
*
* @access public
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
* @copyright Colosa - Bolivia
*
* @return array
*
* @url PUT /:dep_uid/set-manager/:usr_uid
*/
public function doPutSetManager($dep_uid, $usr_uid)
{
try {
$oDepartment = new \ProcessMaker\BusinessModel\Department();
$response = $oDepartment->setManagerUser($dep_uid, $usr_uid);
return $response;
} catch (\Exception $e) {
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
}
}
/**
* @param string $dep_uid {@min 1}{@max 32}
*