Merged in victorsl/processmaker/PM-1762 (pull request #1638)
PM-1762 "HTTP status code will be set to 200 no coincide..." SOLVED
This commit is contained in:
@@ -11,6 +11,65 @@ use \DepartmentPeer;
|
|||||||
*/
|
*/
|
||||||
class Department
|
class Department
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Verify if exists the title of a Department
|
||||||
|
*
|
||||||
|
* @param string $departmentTitle Title
|
||||||
|
* @param string $departmentUidExclude Unique id of Department to exclude
|
||||||
|
*
|
||||||
|
* return bool Return true if exists the title of a Department, false otherwise
|
||||||
|
*/
|
||||||
|
public function existsTitle($departmentTitle, $departmentUidExclude = "")
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$delimiter = \DBAdapter::getStringDelimiter();
|
||||||
|
|
||||||
|
$criteria = new \Criteria("workflow");
|
||||||
|
|
||||||
|
$criteria->addSelectColumn(\DepartmentPeer::DEP_UID);
|
||||||
|
|
||||||
|
$criteria->addAlias("CT", \ContentPeer::TABLE_NAME);
|
||||||
|
|
||||||
|
$arrayCondition = array();
|
||||||
|
$arrayCondition[] = array(\DepartmentPeer::DEP_UID, "CT.CON_ID", \Criteria::EQUAL);
|
||||||
|
$arrayCondition[] = array("CT.CON_CATEGORY", $delimiter . "DEPO_TITLE" . $delimiter, \Criteria::EQUAL);
|
||||||
|
$arrayCondition[] = array("CT.CON_LANG", $delimiter . SYS_LANG . $delimiter, \Criteria::EQUAL);
|
||||||
|
$criteria->addJoinMC($arrayCondition, \Criteria::LEFT_JOIN);
|
||||||
|
|
||||||
|
if ($departmentUidExclude != "") {
|
||||||
|
$criteria->add(\DepartmentPeer::DEP_UID, $departmentUidExclude, \Criteria::NOT_EQUAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
$criteria->add("CT.CON_VALUE", $departmentTitle, \Criteria::EQUAL);
|
||||||
|
|
||||||
|
$rsCriteria = \DepartmentPeer::doSelectRS($criteria);
|
||||||
|
|
||||||
|
return ($rsCriteria->next())? true : false;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verify if exists the title of a Department
|
||||||
|
*
|
||||||
|
* @param string $departmentTitle Title
|
||||||
|
* @param string $fieldNameForException Field name for the exception
|
||||||
|
* @param string $departmentUidExclude Unique id of Department to exclude
|
||||||
|
*
|
||||||
|
* return void Throw exception if exists the title of a Department
|
||||||
|
*/
|
||||||
|
public function throwExceptionIfExistsTitle($departmentTitle, $fieldNameForException, $departmentUidExclude = "")
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if ($this->existsTitle($departmentTitle, $departmentUidExclude)) {
|
||||||
|
throw new \Exception(\G::LoadTranslation("ID_DEPARTMENT_TITLE_ALREADY_EXISTS", array($fieldNameForException, $departmentTitle)));
|
||||||
|
}
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get list for Departments
|
* Get list for Departments
|
||||||
*
|
*
|
||||||
@@ -99,25 +158,63 @@ class Department
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Put Assign User
|
* Assign User to Department
|
||||||
*
|
*
|
||||||
* @access public
|
* @param string $departmentUid Unique id of Department
|
||||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
* @param array $arrayData Data
|
||||||
* @copyright Colosa - Bolivia
|
|
||||||
*
|
*
|
||||||
* @return void
|
* return array Return data of the User assigned to Department
|
||||||
*/
|
*/
|
||||||
public function assignUser($dep_uid, $usr_uid)
|
public function assignUser($departmentUid, array $arrayData)
|
||||||
{
|
{
|
||||||
$dep_uid = Validator::depUid($dep_uid);
|
try {
|
||||||
$usr_uid = Validator::usrUid($usr_uid);
|
//Verify data
|
||||||
|
$process = new \ProcessMaker\BusinessModel\Process();
|
||||||
|
$validator = new \ProcessMaker\BusinessModel\Validator();
|
||||||
|
|
||||||
$dep = new \Department();
|
$validator->throwExceptionIfDataIsNotArray($arrayData, "\$arrayData");
|
||||||
$dep->load($dep_uid);
|
$validator->throwExceptionIfDataIsEmpty($arrayData, "\$arrayData");
|
||||||
$dep_manager = $dep->getDepManager();
|
|
||||||
$manager = ($dep_manager == '') ? true : false;
|
//Set data
|
||||||
$dep->addUserToDepartment( $dep_uid, $usr_uid, $manager, false );
|
$arrayData = array_change_key_case($arrayData, CASE_UPPER);
|
||||||
$dep->updateDepartmentManager( $dep_uid );
|
|
||||||
|
unset($arrayData["DEP_UID"]);
|
||||||
|
|
||||||
|
//Set variables
|
||||||
|
$arrayUserFieldDefinition = array(
|
||||||
|
"DEP_UID" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "departmentUid"),
|
||||||
|
"USR_UID" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "userUid")
|
||||||
|
);
|
||||||
|
|
||||||
|
$arrayUserFieldNameForException = array(
|
||||||
|
"departmentUid" => strtolower("DEP_UID"),
|
||||||
|
"userUid" => strtolower("USR_UID")
|
||||||
|
);
|
||||||
|
|
||||||
|
//Verify data
|
||||||
|
$departmentUid = \ProcessMaker\BusinessModel\Validator::depUid($departmentUid);
|
||||||
|
|
||||||
|
$process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $arrayUserFieldDefinition, $arrayUserFieldNameForException, true);
|
||||||
|
|
||||||
|
$process->throwExceptionIfNotExistsUser($arrayData["USR_UID"], $arrayUserFieldNameForException["userUid"]);
|
||||||
|
|
||||||
|
//Assign User
|
||||||
|
$department = new \Department();
|
||||||
|
|
||||||
|
$department->load($departmentUid);
|
||||||
|
|
||||||
|
$department->addUserToDepartment($departmentUid, $arrayData["USR_UID"], ($department->getDepManager() == "")? true : false, false);
|
||||||
|
$department->updateDepartmentManager($departmentUid);
|
||||||
|
|
||||||
|
//Return
|
||||||
|
$arrayData = array_merge(array("DEP_UID" => $departmentUid), $arrayData);
|
||||||
|
|
||||||
|
$arrayData = array_change_key_case($arrayData, CASE_LOWER);
|
||||||
|
|
||||||
|
return $arrayData;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -239,6 +336,11 @@ class Department
|
|||||||
Validator::isBoolean($create, '$create');
|
Validator::isBoolean($create, '$create');
|
||||||
|
|
||||||
$dep_data = array_change_key_case($dep_data, CASE_UPPER);
|
$dep_data = array_change_key_case($dep_data, CASE_UPPER);
|
||||||
|
|
||||||
|
if ($create) {
|
||||||
|
unset($dep_data["DEP_UID"]);
|
||||||
|
}
|
||||||
|
|
||||||
$oDepartment = new \Department();
|
$oDepartment = new \Department();
|
||||||
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']);
|
||||||
@@ -254,18 +356,21 @@ class Department
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!$create) {
|
if (!$create) {
|
||||||
$dep_data['DEPO_TITLE'] = $dep_data['DEP_TITLE'];
|
if (isset($dep_data["DEP_TITLE"])) {
|
||||||
if (isset($dep_data['DEP_TITLE'])) {
|
$this->throwExceptionIfExistsTitle($dep_data["DEP_TITLE"], strtolower("DEP_TITLE"), $dep_data["DEP_UID"]);
|
||||||
Validator::depTitle($dep_data['DEP_TITLE'], $dep_data['DEP_UID']);
|
|
||||||
|
$dep_data["DEPO_TITLE"] = $dep_data["DEP_TITLE"];
|
||||||
}
|
}
|
||||||
|
|
||||||
$oDepartment->update($dep_data);
|
$oDepartment->update($dep_data);
|
||||||
$oDepartment->updateDepartmentManager($dep_data['DEP_UID']);
|
$oDepartment->updateDepartmentManager($dep_data['DEP_UID']);
|
||||||
} else {
|
} else {
|
||||||
if (isset($dep_data['DEP_TITLE'])) {
|
if (isset($dep_data['DEP_TITLE'])) {
|
||||||
Validator::depTitle($dep_data['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);
|
||||||
$response = $this->getDepartment($dep_uid);
|
$response = $this->getDepartment($dep_uid);
|
||||||
return $response;
|
return $response;
|
||||||
|
|||||||
@@ -35,47 +35,6 @@ class Validator
|
|||||||
return $dep_uid;
|
return $dep_uid;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Validate dep_title
|
|
||||||
* @var string $dep_title. Name or Title for Departament
|
|
||||||
* @var string $dep_uid. Uid for Departament
|
|
||||||
*
|
|
||||||
* @access public
|
|
||||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
|
||||||
* @copyright Colosa - Bolivia
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*
|
|
||||||
* @url GET
|
|
||||||
*/
|
|
||||||
static public function depTitle($dep_title, $dep_uid = '')
|
|
||||||
{
|
|
||||||
$dep_title = trim($dep_title);
|
|
||||||
if ($dep_title == '') {
|
|
||||||
throw (new \Exception(\G::LoadTranslation("ID_DEPARTMENT_NOT_EXIST", array('dep_title',''))));
|
|
||||||
}
|
|
||||||
|
|
||||||
$oCriteria = new \Criteria( 'workflow' );
|
|
||||||
$oCriteria->clearSelectColumns();
|
|
||||||
$oCriteria->addSelectColumn( \ContentPeer::CON_CATEGORY );
|
|
||||||
$oCriteria->addSelectColumn( \ContentPeer::CON_VALUE );
|
|
||||||
$oCriteria->addSelectColumn( \DepartmentPeer::DEP_PARENT );
|
|
||||||
$oCriteria->add( \ContentPeer::CON_CATEGORY, 'DEPO_TITLE' );
|
|
||||||
$oCriteria->addJoin( \ContentPeer::CON_ID, \DepartmentPeer::DEP_UID, \Criteria::LEFT_JOIN );
|
|
||||||
$oCriteria->add( \ContentPeer::CON_VALUE, $dep_title );
|
|
||||||
$oCriteria->add( \ContentPeer::CON_LANG, SYS_LANG );
|
|
||||||
if ($dep_uid != '') {
|
|
||||||
$oCriteria->add( \ContentPeer::CON_ID, $dep_uid, \Criteria::NOT_EQUAL );
|
|
||||||
}
|
|
||||||
|
|
||||||
$oDataset = \DepartmentPeer::doSelectRS( $oCriteria );
|
|
||||||
$oDataset->setFetchmode( \ResultSet::FETCHMODE_ASSOC );
|
|
||||||
if ($oDataset->next()) {
|
|
||||||
throw (new \Exception(\G::LoadTranslation("ID_DEPARTMENT_NOT_EXIST", array('dep_title',$dep_title))));
|
|
||||||
}
|
|
||||||
return $dep_title;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate dep_status
|
* Validate dep_status
|
||||||
* @var string $dep_uid. Uid for Departament
|
* @var string $dep_uid. Uid for Departament
|
||||||
|
|||||||
@@ -80,25 +80,21 @@ class Department extends Api
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $dep_uid {@min 1}{@max 32}
|
* @url POST /:dep_uid/assign-user
|
||||||
* @param string $usr_uid {@min 1}{@max 32}
|
|
||||||
*
|
*
|
||||||
* @access public
|
* @param string $dep_uid {@min 32}{@max 32}
|
||||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
* @param array $request_data
|
||||||
* @copyright Colosa - Bolivia
|
|
||||||
*
|
*
|
||||||
* @return array
|
* @status 201
|
||||||
*
|
|
||||||
* @url PUT /:dep_uid/assign-user/:usr_uid
|
|
||||||
*/
|
*/
|
||||||
public function doPutAssignUser($dep_uid, $usr_uid)
|
public function doPostAssignUser($dep_uid, array $request_data)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$oDepartment = new \ProcessMaker\BusinessModel\Department();
|
$department = new \ProcessMaker\BusinessModel\Department();
|
||||||
$response = $oDepartment->assignUser($dep_uid, $usr_uid);
|
|
||||||
return $response;
|
$arrayData = $department->assignUser($dep_uid, $request_data);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
|
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user