Merge branch 'master' of bitbucket.org:colosa/processmaker

This commit is contained in:
Brayan Osmar Pereyra Suxo
2014-05-29 15:39:48 -04:00
19 changed files with 2271 additions and 40 deletions

View File

@@ -46,6 +46,19 @@ $noShowTitle = 0;
if (isset( $aProcessFieds['PRO_SHOW_MESSAGE'] )) {
$noShowTitle = $aProcessFieds['PRO_SHOW_MESSAGE'];
}
// getting bpmn projects
$c = new Criteria('workflow');
$c->addSelectColumn(BpmnProjectPeer::PRJ_UID);
$ds = ProcessPeer::doSelectRS($c);
$ds->setFetchmode(ResultSet::FETCHMODE_ASSOC);
$bpmnProjects = array();
while ($ds->next()) {
$row = $ds->getRow();
$bpmnProjects[] = $row['PRJ_UID'];
}
switch (($aCaseTracker['CT_MAP_TYPE'])) {
case 'NONE':
//Nothing
@@ -55,6 +68,15 @@ switch (($aCaseTracker['CT_MAP_TYPE'])) {
G::LoadClass( 'processMap' );
$oCase = new Cases();
$aFields = $oCase->loadCase( $_SESSION['APPLICATION'] );
if (in_array($aFields['PRO_UID'], $bpmnProjects)) {
//bpmb
$_SESSION["APP_UID"] = $aFields["APP_UID"];
$G_PUBLISH = new Publisher();
$G_PUBLISH->AddContent( 'view', 'tracker/viewMap' );
G::RenderPage( 'publish' );
//note: url processmap "../designer?prj_uid=$_SESSION['PROCESS']&prj_readonly=true&app_uid=$_SESSION['APP_UID']"
break;
}
if (isset( $aFields['TITLE'] )) {
$aFields['APP_TITLE'] = $aFields['TITLE'];
}
@@ -139,6 +161,15 @@ switch (($aCaseTracker['CT_MAP_TYPE'])) {
G::LoadClass( 'case' );
$oCase = new Cases();
$aFields = $oCase->loadCase( $_SESSION['APPLICATION'] );
if (in_array($aFields['PRO_UID'], $bpmnProjects)) {
//bpmb
$_SESSION["APP_UID"] = $aFields["APP_UID"];
$G_PUBLISH = new Publisher();
$G_PUBLISH->AddContent( 'view', 'tracker/viewMap' );
G::RenderPage( 'publish' );
//note: url processmap "../designer?prj_uid=$_SESSION['PROCESS']&prj_readonly=true&app_uid=$_SESSION['APP_UID']"
break;
}
if (isset( $aFields['TITLE'] )) {
$aFields['APP_TITLE'] = $aFields['TITLE'];
}

View File

@@ -644,7 +644,10 @@ class Calendar
$criteria = $this->getCalendarCriteria();
if (!is_null($arrayFilterData) && is_array($arrayFilterData) && isset($arrayFilterData["filter"]) && trim($arrayFilterData["filter"]) != "") {
$criteria->add(\CalendarDefinitionPeer::CALENDAR_NAME, "%" . $arrayFilterData["filter"] . "%", \Criteria::LIKE);
$criteria->add(
$criteria->getNewCriterion(\CalendarDefinitionPeer::CALENDAR_NAME, "%" . $arrayFilterData["filter"] . "%", \Criteria::LIKE)->addOr(
$criteria->getNewCriterion(\CalendarDefinitionPeer::CALENDAR_DESCRIPTION, "%" . $arrayFilterData["filter"] . "%", \Criteria::LIKE))
);
}
//Number records total

View File

@@ -0,0 +1,645 @@
<?php
namespace ProcessMaker\BusinessModel;
require_once(PATH_RBAC . "model" . PATH_SEP . "Roles.php");
class Role
{
private $arrayFieldDefinition = array(
"ROL_UID" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "roleUid"),
"ROL_CODE" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "roleCode"),
"ROL_NAME" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "roleName"),
"ROL_STATUS" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array("ACTIVE", "INACTIVE"), "fieldNameAux" => "roleStatus")
);
private $formatFieldNameInUppercase = true;
private $arrayFieldNameForException = array(
"filter" => "FILTER",
"start" => "START",
"limit" => "LIMIT"
);
/**
* Constructor of the class
*
* return void
*/
public function __construct()
{
try {
foreach ($this->arrayFieldDefinition as $key => $value) {
$this->arrayFieldNameForException[$value["fieldNameAux"]] = $key;
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Set the format of the fields name (uppercase, lowercase)
*
* @param bool $flag Value that set the format
*
* return void
*/
public function setFormatFieldNameInUppercase($flag)
{
try {
$this->formatFieldNameInUppercase = $flag;
$this->setArrayFieldNameForException($this->arrayFieldNameForException);
} catch (\Exception $e) {
throw $e;
}
}
/**
* Set exception messages for fields
*
* @param array $arrayData Data with the fields
*
* return void
*/
public function setArrayFieldNameForException(array $arrayData)
{
try {
foreach ($arrayData as $key => $value) {
$this->arrayFieldNameForException[$key] = $this->getFieldNameByFormatFieldName($value);
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Get the name of the field according to the format
*
* @param string $fieldName Field name
*
* return string Return the field name according the format
*/
public function getFieldNameByFormatFieldName($fieldName)
{
try {
return ($this->formatFieldNameInUppercase)? strtoupper($fieldName) : strtolower($fieldName);
} catch (\Exception $e) {
throw $e;
}
}
/**
* Verify if exists the code of a Role
*
* @param string $roleCode Code
* @param string $roleSystemUid Unique id of System (00000000000000000000000000000001: RBAC, 00000000000000000000000000000002: PROCESSMAKER)
* @param string $roleUidExclude Unique id of Role to exclude
*
* return bool Return true if exists the code of a Role, false otherwise
*/
public function existsCode($roleCode, $roleSystemUid, $roleUidExclude = "")
{
try {
$criteria = new \Criteria("rbac");
$criteria->addSelectColumn(\RolesPeer::ROL_UID);
$criteria->add(\RolesPeer::ROL_SYSTEM, $roleSystemUid, \Criteria::EQUAL);
if ($roleUidExclude != "") {
$criteria->add(\RolesPeer::ROL_UID, $roleUidExclude, \Criteria::NOT_EQUAL);
}
$criteria->add(\RolesPeer::ROL_CODE, $roleCode, \Criteria::EQUAL);
$rsCriteria = \RolesPeer::doSelectRS($criteria);
if ($rsCriteria->next()) {
return true;
} else {
return false;
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Verify if exists the name of a Role
*
* @param string $roleName Name
* @param string $roleSystemUid Unique id of System (00000000000000000000000000000001: RBAC, 00000000000000000000000000000002: PROCESSMAKER)
* @param string $roleUidExclude Unique id of Role to exclude
*
* return bool Return true if exists the name of a Role, false otherwise
*/
public function existsName($roleName, $roleSystemUid, $roleUidExclude = "")
{
try {
//Set variables
$content = new \Content();
$role = new \Roles();
$arrayContentByRole = $content->getAllContentsByRole();
//SQL
$criteria = new \Criteria("rbac");
$criteria->addSelectColumn(\RolesPeer::ROL_UID);
$criteria->add(\RolesPeer::ROL_SYSTEM, $roleSystemUid, \Criteria::EQUAL);
if ($roleUidExclude != "") {
$criteria->add(\RolesPeer::ROL_UID, $roleUidExclude, \Criteria::NOT_EQUAL);
}
$rsCriteria = \RolesPeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
while ($rsCriteria->next()) {
$row = $rsCriteria->getRow();
$roleUid = $row["ROL_UID"];
if (isset($arrayContentByRole[$roleUid])) {
$roleNameAux = $arrayContentByRole[$roleUid];
} else {
$rowAux = $role->load($roleUid);
$roleNameAux = $rowAux["ROL_NAME"];
}
if ($roleNameAux == $roleName) {
return true;
}
}
return false;
} catch (\Exception $e) {
throw $e;
}
}
/**
* Verify if does not exist the Role in table ROLES
*
* @param string $roleUid Unique id of Role
* @param string $fieldNameForException Field name for the exception
*
* return void Throw exception if does not exist the Role in table ROLES
*/
public function throwExceptionIfNotExistsRole($roleUid, $fieldNameForException)
{
try {
$obj = \RolesPeer::retrieveByPK($roleUid);
if (is_null($obj)) {
throw new \Exception(\G::LoadTranslation("ID_ROLE_DOES_NOT_EXIST", array($fieldNameForException, $roleUid)));
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Verify if exists the code of a Role
*
* @param string $roleCode Code
* @param string $roleSystemUid Unique id of System (00000000000000000000000000000001: RBAC, 00000000000000000000000000000002: PROCESSMAKER)
* @param string $fieldNameForException Field name for the exception
* @param string $roleUidExclude Unique id of Role to exclude
*
* return void Throw exception if exists the code of a Role
*/
public function throwExceptionIfExistsCode($roleCode, $roleSystemUid, $fieldNameForException, $roleUidExclude = "")
{
try {
if ($this->existsCode($roleCode, $roleSystemUid, $roleUidExclude)) {
throw new \Exception(\G::LoadTranslation("ID_ROLE_CODE_ALREADY_EXISTS", array($fieldNameForException, $roleCode)));
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Verify if exists the name of a Role
*
* @param string $roleName Name
* @param string $roleSystemUid Unique id of System (00000000000000000000000000000001: RBAC, 00000000000000000000000000000002: PROCESSMAKER)
* @param string $fieldNameForException Field name for the exception
* @param string $roleUidExclude Unique id of Role to exclude
*
* return void Throw exception if exists the name of a Role
*/
public function throwExceptionIfExistsName($roleName, $roleSystemUid, $fieldNameForException, $roleUidExclude = "")
{
try {
if ($this->existsName($roleName, $roleSystemUid, $roleUidExclude)) {
throw new \Exception(\G::LoadTranslation("ID_ROLE_NAME_ALREADY_EXISTS", array($fieldNameForException, $roleName)));
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Validate the data if they are invalid (INSERT and UPDATE)
*
* @param string $roleUid Unique id of Role
* @param array $arrayData Data
*
* return void Throw exception if data has an invalid value
*/
public function throwExceptionIfDataIsInvalid($roleUid, array $arrayData)
{
try {
//Set variables
$arrayRoleData = ($roleUid == "")? array() : $this->getRole($roleUid, true);
$flagInsert = ($roleUid == "")? true : false;
$arrayDataMain = array_merge($arrayRoleData, $arrayData);
//Verify data - Field definition
$process = new \ProcessMaker\BusinessModel\Process();
$process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $this->arrayFieldDefinition, $this->arrayFieldNameForException, $flagInsert);
//Verify data
if (isset($arrayData["ROL_CODE"]) && !preg_match("/^\w+$/", $arrayData["ROL_CODE"])) {
throw new \Exception(\G::LoadTranslation("ID_ROLE_FIELD_CANNOT_CONTAIN_SPECIAL_CHARACTERS", array($this->arrayFieldNameForException["roleCode"])));
}
if (isset($arrayData["ROL_CODE"])) {
$this->throwExceptionIfExistsCode($arrayData["ROL_CODE"], $arrayDataMain["ROL_SYSTEM"], $this->arrayFieldNameForException["roleCode"], $roleUid);
}
if (isset($arrayData["ROL_NAME"])) {
$this->throwExceptionIfExistsName($arrayData["ROL_NAME"], $arrayDataMain["ROL_SYSTEM"], $this->arrayFieldNameForException["roleName"], $roleUid);
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Create Role
*
* @param array $arrayData Data
*
* return array Return data of the new Role created
*/
public function create(array $arrayData)
{
try {
//Verify data
$process = new \ProcessMaker\BusinessModel\Process();
$validator = new \ProcessMaker\BusinessModel\Validator();
$validator->throwExceptionIfDataIsNotArray($arrayData, "\$arrayData");
$validator->throwExceptionIfDataIsEmpty($arrayData, "\$arrayData");
//Set data
$arrayData = array_change_key_case($arrayData, CASE_UPPER);
unset($arrayData["ROL_UID"]);
$arrayData["ROL_SYSTEM"] = "00000000000000000000000000000002"; //PROCESSMAKER
//Verify data
$this->throwExceptionIfDataIsInvalid("", $arrayData);
//Create
$role = new \Roles();
$roleUid = \ProcessMaker\Util\Common::generateUID();
$arrayData["ROL_UID"] = $roleUid;
$arrayData["ROL_STATUS"] = (isset($arrayData["ROL_STATUS"]))? (($arrayData["ROL_STATUS"] == "ACTIVE")? 1 : 0) : 1;
$arrayData["ROL_CREATE_DATE"] = date("Y-M-d H:i:s");
$result = $role->createRole($arrayData);
//Return
return $this->getRole($roleUid);
} catch (\Exception $e) {
throw $e;
}
}
/**
* Update Role
*
* @param string $roleUid Unique id of Role
* @param array $arrayData Data
*
* return array Return data of the Role updated
*/
public function update($roleUid, array $arrayData)
{
try {
$arrayDataBackup = $arrayData;
//Verify data
$process = new \ProcessMaker\BusinessModel\Process();
$validator = new \ProcessMaker\BusinessModel\Validator();
$validator->throwExceptionIfDataIsNotArray($arrayData, "\$arrayData");
$validator->throwExceptionIfDataIsEmpty($arrayData, "\$arrayData");
//Set data
$arrayData = array_change_key_case($arrayData, CASE_UPPER);
$arrayRoleData = $this->getRole($roleUid);
//Verify data
$this->throwExceptionIfNotExistsRole($roleUid, $this->arrayFieldNameForException["roleUid"]);
$this->throwExceptionIfDataIsInvalid($roleUid, $arrayData);
//Update
$role = new \Roles();
$arrayData["ROL_UID"] = $roleUid;
$arrayData["ROL_UPDATE_DATE"] = date("Y-M-d H:i:s");
if (!isset($arrayData["ROL_NAME"])) {
$arrayData["ROL_NAME"] = $arrayRoleData[$this->getFieldNameByFormatFieldName("ROL_NAME")];
}
if (isset($arrayData["ROL_STATUS"])) {
$arrayData["ROL_STATUS"] = ($arrayData["ROL_STATUS"] == "ACTIVE")? 1 : 0;
}
$result = $role->updateRole($arrayData);
$arrayData = $arrayDataBackup;
//Return
if (!$this->formatFieldNameInUppercase) {
$arrayData = array_change_key_case($arrayData, CASE_LOWER);
}
return $arrayData;
} catch (\Exception $e) {
throw $e;
}
}
/**
* Delete Role
*
* @param string $roleUid Unique id of Role
*
* return void
*/
public function delete($roleUid)
{
try {
$role = new \Roles();
//Verify data
$this->throwExceptionIfNotExistsRole($roleUid, $this->arrayFieldNameForException["roleUid"]);
if ($role->numUsersWithRole($roleUid) > 0) {
throw new \Exception(\G::LoadTranslation("ID_ROLES_CAN_NOT_DELETE"));
}
//Delete
$result = $role->removeRole($roleUid);
} catch (\Exception $e) {
throw $e;
}
}
/**
* Get criteria for Role
*
* return object
*/
public function getRoleCriteria()
{
try {
$criteria = new \Criteria("rbac");
$criteria->addSelectColumn(\RolesPeer::ROL_UID);
$criteria->addSelectColumn(\RolesPeer::ROL_PARENT);
$criteria->addSelectColumn(\RolesPeer::ROL_CODE);
$criteria->addSelectColumn(\RolesPeer::ROL_STATUS);
$criteria->addSelectColumn(\RolesPeer::ROL_SYSTEM);
$criteria->addSelectColumn(\RolesPeer::ROL_CREATE_DATE);
$criteria->addSelectColumn(\RolesPeer::ROL_UPDATE_DATE);
$criteria->add(\RolesPeer::ROL_SYSTEM, "00000000000000000000000000000002", \Criteria::EQUAL); //PROCESSMAKER
return $criteria;
} catch (\Exception $e) {
throw $e;
}
}
/**
* Get data of a Role from a record
*
* @param array $record Record
*
* return array Return an array with data Role
*/
public function getRoleDataFromRecord(array $record)
{
try {
$conf = new \Configurations();
$confEnvSetting = $conf->getFormats();
$dateTime = new \DateTime($record["ROL_CREATE_DATE"]);
$roleCreateDate = $dateTime->format($confEnvSetting["dateFormat"]);
$roleUpdateDate = "";
if (!empty($record["ROL_UPDATE_DATE"])) {
$dateTime = new \DateTime($record["ROL_UPDATE_DATE"]);
$roleUpdateDate = $dateTime->format($confEnvSetting["dateFormat"]);
}
return array(
$this->getFieldNameByFormatFieldName("ROL_UID") => $record["ROL_UID"],
$this->getFieldNameByFormatFieldName("ROL_CODE") => $record["ROL_CODE"],
$this->getFieldNameByFormatFieldName("ROL_NAME") => $record["ROL_NAME"],
$this->getFieldNameByFormatFieldName("ROL_STATUS") => ($record["ROL_STATUS"] . "" == "1")? "ACTIVE" : "INACTIVE",
$this->getFieldNameByFormatFieldName("ROL_SYSTEM") => $record["ROL_SYSTEM"],
$this->getFieldNameByFormatFieldName("ROL_CREATE_DATE") => $roleCreateDate,
$this->getFieldNameByFormatFieldName("ROL_UPDATE_DATE") => $roleUpdateDate,
$this->getFieldNameByFormatFieldName("ROL_TOTAL_USERS") => (int)($record["ROL_TOTAL_USERS"])
);
} catch (\Exception $e) {
throw $e;
}
}
/**
* Get all Roles
*
* @param array $arrayFilterData Data of the filters
* @param string $sortField Field name to sort
* @param string $sortDir Direction of sorting (ASC, DESC)
* @param int $start Start
* @param int $limit Limit
*
* return array Return an array with all Roles
*/
public function getRoles(array $arrayFilterData = null, $sortField = null, $sortDir = null, $start = null, $limit = null)
{
try {
$arrayRole = array();
//Verify data
$process = new \ProcessMaker\BusinessModel\Process();
$process->throwExceptionIfDataNotMetPagerVarDefinition(array("start" => $start, "limit" => $limit), $this->arrayFieldNameForException);
//Get data
if (!is_null($limit) && $limit . "" == "0") {
return $arrayRole;
}
//Set variables
$content = new \Content();
$role = new \Roles();
$arrayContentByRole = $content->getAllContentsByRole();
//SQL
$criteria = $this->getRoleCriteria();
$criteria->addAsColumn("ROL_TOTAL_USERS", "(SELECT COUNT(" . \UsersRolesPeer::ROL_UID . ") FROM " . \UsersRolesPeer::TABLE_NAME . " WHERE " . \UsersRolesPeer::ROL_UID . " = " . \RolesPeer::ROL_UID . ")");
if (!is_null($arrayFilterData) && is_array($arrayFilterData) && isset($arrayFilterData["filter"]) && trim($arrayFilterData["filter"]) != "") {
$criteria->add(\RolesPeer::ROL_CODE, "%" . $arrayFilterData["filter"] . "%", \Criteria::LIKE);
}
//Number records total
$criteriaCount = clone $criteria;
$criteriaCount->clearSelectColumns();
$criteriaCount->addAsColumn("NUM_REC", "COUNT(" . \RolesPeer::ROL_UID . ")");
$rsCriteriaCount = \RolesPeer::doSelectRS($criteriaCount);
$rsCriteriaCount->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
$rsCriteriaCount->next();
$row = $rsCriteriaCount->getRow();
$numRecTotal = $row["NUM_REC"];
//SQL
if (!is_null($sortField) && trim($sortField) != "") {
$sortField = strtoupper($sortField);
if (in_array($sortField, array("ROL_UID", "ROL_PARENT", "ROL_STATUS", "ROL_SYSTEM", "ROL_CREATE_DATE", "ROL_UPDATE_DATE"))) {
$sortField = \RolesPeer::TABLE_NAME . "." . $sortField;
} else {
$sortField = \RolesPeer::ROL_CODE;
}
} else {
$sortField = \RolesPeer::ROL_CODE;
}
if (!is_null($sortDir) && trim($sortDir) != "" && strtoupper($sortDir) == "DESC") {
$criteria->addDescendingOrderByColumn($sortField);
} else {
$criteria->addAscendingOrderByColumn($sortField);
}
if (!is_null($start)) {
$criteria->setOffset((int)($start));
}
if (!is_null($limit)) {
$criteria->setLimit((int)($limit));
}
$rsCriteria = \RolesPeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
while ($rsCriteria->next()) {
$row = $rsCriteria->getRow();
$roleUid = $row["ROL_UID"];
if (isset($arrayContentByRole[$roleUid])) {
$roleName = $arrayContentByRole[$roleUid];
} else {
$rowAux = $role->load($roleUid);
$roleName = $rowAux["ROL_NAME"];
}
$row["ROL_NAME"] = $roleName;
$arrayRole[] = $this->getRoleDataFromRecord($row);
}
//Return
return $arrayRole;
} catch (\Exception $e) {
throw $e;
}
}
/**
* Get data of a Role
*
* @param string $roleUid Unique id of Role
* @param bool $flagGetRecord Value that set the getting
*
* return array Return an array with data of a Role
*/
public function getRole($roleUid, $flagGetRecord = false)
{
try {
//Verify data
$this->throwExceptionIfNotExistsRole($roleUid, $this->arrayFieldNameForException["roleUid"]);
//Set variables
if (!$flagGetRecord) {
$content = new \Content();
$role = new \Roles();
$arrayContentByRole = $content->getAllContentsByRole();
}
//Get data
//SQL
$criteria = $this->getRoleCriteria();
if (!$flagGetRecord) {
$criteria->addAsColumn("ROL_TOTAL_USERS", "(SELECT COUNT(" . \UsersRolesPeer::ROL_UID . ") FROM " . \UsersRolesPeer::TABLE_NAME . " WHERE " . \UsersRolesPeer::ROL_UID . " = " . \RolesPeer::ROL_UID . ")");
}
$criteria->add(\RolesPeer::ROL_UID, $roleUid, \Criteria::EQUAL);
$rsCriteria = \RolesPeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
$rsCriteria->next();
$row = $rsCriteria->getRow();
if (!$flagGetRecord) {
if (isset($arrayContentByRole[$roleUid])) {
$roleName = $arrayContentByRole[$roleUid];
} else {
$rowAux = $role->load($roleUid);
$roleName = $rowAux["ROL_NAME"];
}
$row["ROL_NAME"] = $roleName;
}
//Return
return (!$flagGetRecord)? $this->getRoleDataFromRecord($row) : $row;
} catch (\Exception $e) {
throw $e;
}
}
}

View File

@@ -0,0 +1,408 @@
<?php
namespace ProcessMaker\BusinessModel\Role;
class User
{
private $arrayFieldDefinition = array(
"ROL_UID" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "roleUid"),
"USR_UID" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "userUid")
);
private $formatFieldNameInUppercase = true;
private $arrayFieldNameForException = array(
"filter" => "FILTER",
"start" => "START",
"limit" => "LIMIT"
);
/**
* Constructor of the class
*
* return void
*/
public function __construct()
{
try {
foreach ($this->arrayFieldDefinition as $key => $value) {
$this->arrayFieldNameForException[$value["fieldNameAux"]] = $key;
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Set the format of the fields name (uppercase, lowercase)
*
* @param bool $flag Value that set the format
*
* return void
*/
public function setFormatFieldNameInUppercase($flag)
{
try {
$this->formatFieldNameInUppercase = $flag;
$this->setArrayFieldNameForException($this->arrayFieldNameForException);
} catch (\Exception $e) {
throw $e;
}
}
/**
* Set exception messages for fields
*
* @param array $arrayData Data with the fields
*
* return void
*/
public function setArrayFieldNameForException(array $arrayData)
{
try {
foreach ($arrayData as $key => $value) {
$this->arrayFieldNameForException[$key] = $this->getFieldNameByFormatFieldName($value);
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Get the name of the field according to the format
*
* @param string $fieldName Field name
*
* return string Return the field name according the format
*/
public function getFieldNameByFormatFieldName($fieldName)
{
try {
return ($this->formatFieldNameInUppercase)? strtoupper($fieldName) : strtolower($fieldName);
} catch (\Exception $e) {
throw $e;
}
}
/**
* Verify if it's assigned the User to Role
*
* @param string $roleUid Unique id of Role
* @param string $userUid Unique id of User
* @param string $fieldNameForException Field name for the exception
*
* return void Throw exception if it's assigned the User to Role
*/
public function throwExceptionIfItsAssignedUserToRole($roleUid, $userUid, $fieldNameForException)
{
try {
$obj = \UsersRolesPeer::retrieveByPK($userUid, $roleUid);
if (!is_null($obj)) {
throw new \Exception(\G::LoadTranslation("ID_ROLE_USER_IS_ALREADY_ASSIGNED", array($fieldNameForException, $userUid)));
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Verify if not it's assigned the User to Role
*
* @param string $roleUid Unique id of Role
* @param string $userUid Unique id of User
* @param string $fieldNameForException Field name for the exception
*
* return void Throw exception if not it's assigned the User to Role
*/
public function throwExceptionIfNotItsAssignedUserToRole($roleUid, $userUid, $fieldNameForException)
{
try {
$obj = \UsersRolesPeer::retrieveByPK($userUid, $roleUid);
if (is_null($obj)) {
throw new \Exception(\G::LoadTranslation("ID_ROLE_USER_IS_NOT_ASSIGNED", array($fieldNameForException, $userUid)));
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Assign User to Role
*
* @param string $roleUid Unique id of Role
* @param array $arrayData Data
*
* return array Return data of the User assigned to Role
*/
public function create($roleUid, array $arrayData)
{
try {
//Verify data
$process = new \ProcessMaker\BusinessModel\Process();
$validator = new \ProcessMaker\BusinessModel\Validator();
$validator->throwExceptionIfDataIsNotArray($arrayData, "\$arrayData");
$validator->throwExceptionIfDataIsEmpty($arrayData, "\$arrayData");
//Set data
$arrayData = array_change_key_case($arrayData, CASE_UPPER);
unset($arrayData["ROL_UID"]);
//Verify data
$role = new \ProcessMaker\BusinessModel\Role();
$role->throwExceptionIfNotExistsRole($roleUid, $this->arrayFieldNameForException["roleUid"]);
$process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $this->arrayFieldDefinition, $this->arrayFieldNameForException, true);
$process->throwExceptionIfNotExistsUser($arrayData["USR_UID"], $this->arrayFieldNameForException["userUid"]);
$this->throwExceptionIfItsAssignedUserToRole($roleUid, $arrayData["USR_UID"], $this->arrayFieldNameForException["userUid"]);
if ($arrayData["USR_UID"] == "00000000000000000000000000000001") {
throw new \Exception(\G::LoadTranslation("ID_ADMINISTRATOR_ROLE_CANT_CHANGED"));
}
//Create
$role = new \Roles();
$arrayData = array_merge(array("ROL_UID" => $roleUid), $arrayData);
$role->assignUserToRole($arrayData);
//Return
if (!$this->formatFieldNameInUppercase) {
$arrayData = array_change_key_case($arrayData, CASE_LOWER);
}
return $arrayData;
} catch (\Exception $e) {
throw $e;
}
}
/**
* Unassign User of the Role
*
* @param string $roleUid Unique id of Role
* @param string $userUid Unique id of User
*
* return void
*/
public function delete($roleUid, $userUid)
{
try {
//Verify data
$process = new \ProcessMaker\BusinessModel\Process();
$role = new \ProcessMaker\BusinessModel\Role();
$role->throwExceptionIfNotExistsRole($roleUid, $this->arrayFieldNameForException["roleUid"]);
$process->throwExceptionIfNotExistsUser($userUid, $this->arrayFieldNameForException["userUid"]);
$this->throwExceptionIfNotItsAssignedUserToRole($roleUid, $userUid, $this->arrayFieldNameForException["userUid"]);
if ($roleUid == "00000000000000000000000000000002" && $userUid == "00000000000000000000000000000001") {
throw new \Exception(\G::LoadTranslation("ID_ADMINISTRATOR_ROLE_CANT_CHANGED"));
}
//Delete
$role = new \Roles();
$role->deleteUserRole($roleUid, $userUid);
} catch (\Exception $e) {
throw $e;
}
}
/**
* Get criteria for User
*
* @param string $roleUid Unique id of Role
* @param array $arrayUserUidExclude Unique id of Users to exclude
*
* return object
*/
public function getUserCriteria($roleUid, array $arrayUserUidExclude = null)
{
try {
$criteria = new \Criteria("rbac");
$criteria->addSelectColumn(\RbacUsersPeer::USR_UID);
$criteria->addSelectColumn(\RbacUsersPeer::USR_USERNAME);
$criteria->addSelectColumn(\RbacUsersPeer::USR_FIRSTNAME);
$criteria->addSelectColumn(\RbacUsersPeer::USR_LASTNAME);
$criteria->addSelectColumn(\RbacUsersPeer::USR_STATUS);
if ($roleUid != "") {
$criteria->addJoin(\UsersRolesPeer::USR_UID, \RbacUsersPeer::USR_UID, \Criteria::LEFT_JOIN);
$criteria->add(\UsersRolesPeer::ROL_UID, $roleUid, \Criteria::EQUAL);
}
$criteria->add(\RbacUsersPeer::USR_USERNAME, "", \Criteria::NOT_EQUAL);
if (!is_null($arrayUserUidExclude) && is_array($arrayUserUidExclude)) {
$criteria->add(\RbacUsersPeer::USR_UID, $arrayUserUidExclude, \Criteria::NOT_IN);
}
return $criteria;
} catch (\Exception $e) {
throw $e;
}
}
/**
* Get data of a User from a record
*
* @param array $record Record
*
* return array Return an array with data User
*/
public function getUserDataFromRecord(array $record)
{
try {
return array(
$this->getFieldNameByFormatFieldName("USR_UID") => $record["USR_UID"],
$this->getFieldNameByFormatFieldName("USR_USERNAME") => $record["USR_USERNAME"],
$this->getFieldNameByFormatFieldName("USR_FIRSTNAME") => $record["USR_FIRSTNAME"] . "",
$this->getFieldNameByFormatFieldName("USR_LASTNAME") => $record["USR_LASTNAME"] . "",
$this->getFieldNameByFormatFieldName("USR_STATUS") => ($record["USR_STATUS"] . "" == "1")? "ACTIVE" : "INACTIVE"
);
} catch (\Exception $e) {
throw $e;
}
}
/**
* Get all Users of a Role
*
* @param string $roleUid Unique id of Role
* @param string $option Option (USERS, AVAILABLE-USERS)
* @param array $arrayFilterData Data of the filters
* @param string $sortField Field name to sort
* @param string $sortDir Direction of sorting (ASC, DESC)
* @param int $start Start
* @param int $limit Limit
*
* 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)
{
try {
$arrayUser = array();
//Verify data
$process = new \ProcessMaker\BusinessModel\Process();
$role = new \ProcessMaker\BusinessModel\Role();
$role->throwExceptionIfNotExistsRole($roleUid, $this->arrayFieldNameForException["roleUid"]);
$process->throwExceptionIfDataNotMetFieldDefinition(
array("OPTION" => $option),
array("OPTION" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array("USERS", "AVAILABLE-USERS"), "fieldNameAux" => "option")),
array("option" => "\$option"),
true
);
$process->throwExceptionIfDataNotMetPagerVarDefinition(array("start" => $start, "limit" => $limit), $this->arrayFieldNameForException);
//Get data
if (!is_null($limit) && $limit . "" == "0") {
return $arrayUser;
}
//SQL
switch ($option) {
case "USERS":
//Criteria
$criteria = $this->getUserCriteria($roleUid);
break;
case "AVAILABLE-USERS":
//Get Uids
$arrayUid = array();
$criteria = $this->getUserCriteria($roleUid);
$rsCriteria = \RbacUsersPeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
while ($rsCriteria->next()) {
$row = $rsCriteria->getRow();
$arrayUid[] = $row["USR_UID"];
}
//Criteria
$criteria = $this->getUserCriteria("", $arrayUid);
break;
}
if (!is_null($arrayFilterData) && is_array($arrayFilterData) && isset($arrayFilterData["filter"]) && trim($arrayFilterData["filter"]) != "") {
$criteria->add(
$criteria->getNewCriterion(\RbacUsersPeer::USR_USERNAME, "%" . $arrayFilterData["filter"] . "%", \Criteria::LIKE)->addOr(
$criteria->getNewCriterion(\RbacUsersPeer::USR_FIRSTNAME, "%" . $arrayFilterData["filter"] . "%", \Criteria::LIKE)->addOr(
$criteria->getNewCriterion(\RbacUsersPeer::USR_LASTNAME, "%" . $arrayFilterData["filter"] . "%", \Criteria::LIKE)))
);
}
//Number records total
$criteriaCount = clone $criteria;
$criteriaCount->clearSelectColumns();
$criteriaCount->addAsColumn("NUM_REC", "COUNT(" . \RbacUsersPeer::USR_UID . ")");
$rsCriteriaCount = \RbacUsersPeer::doSelectRS($criteriaCount);
$rsCriteriaCount->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
$rsCriteriaCount->next();
$row = $rsCriteriaCount->getRow();
$numRecTotal = $row["NUM_REC"];
//SQL
if (!is_null($sortField) && trim($sortField) != "") {
$sortField = strtoupper($sortField);
if (in_array($sortField, array("USR_UID", "USR_USERNAME", "USR_FIRSTNAME", "USR_LASTNAME", "USR_STATUS"))) {
$sortField = \RbacUsersPeer::TABLE_NAME . "." . $sortField;
} else {
$sortField = \RbacUsersPeer::USR_USERNAME;
}
} else {
$sortField = \RbacUsersPeer::USR_USERNAME;
}
if (!is_null($sortDir) && trim($sortDir) != "" && strtoupper($sortDir) == "DESC") {
$criteria->addDescendingOrderByColumn($sortField);
} else {
$criteria->addAscendingOrderByColumn($sortField);
}
if (!is_null($start)) {
$criteria->setOffset((int)($start));
}
if (!is_null($limit)) {
$criteria->setLimit((int)($limit));
}
$rsCriteria = \RbacUsersPeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
while ($rsCriteria->next()) {
$row = $rsCriteria->getRow();
$arrayUser[] = $this->getUserDataFromRecord($row);
}
//Return
return $arrayUser;
} catch (\Exception $e) {
throw $e;
}
}
}

View File

@@ -67,7 +67,7 @@ class WebEntry
*
* return void
*/
public function setArrayFieldNameForException($arrayData)
public function setArrayFieldNameForException(array $arrayData)
{
try {
foreach ($arrayData as $key => $value) {
@@ -175,9 +175,9 @@ class WebEntry
public function throwExceptionIfNotExistsWebEntry($webEntryUid, $fieldNameForException)
{
try {
$webEntry = \WebEntryPeer::retrieveByPK($webEntryUid);
$obj = \WebEntryPeer::retrieveByPK($webEntryUid);
if (is_null($webEntry)) {
if (is_null($obj)) {
throw new \Exception(\G::LoadTranslation("ID_WEB_ENTRY_DOES_NOT_EXIST", array($fieldNameForException, $webEntryUid)));
}
} catch (\Exception $e) {
@@ -215,7 +215,7 @@ class WebEntry
*
* return void Throw exception if data has an invalid value
*/
public function throwExceptionIfDataIsInvalid($webEntryUid, $processUid, $arrayData)
public function throwExceptionIfDataIsInvalid($webEntryUid, $processUid, array $arrayData)
{
try {
//Set variables
@@ -537,7 +537,7 @@ class WebEntry
*
* return array Return data of the new Web Entry created
*/
public function create($processUid, $userUidCreator, $arrayData)
public function create($processUid, $userUidCreator, array $arrayData)
{
try {
//Verify data
@@ -566,7 +566,7 @@ class WebEntry
$webEntry->fromArray($arrayData, \BasePeer::TYPE_FIELDNAME);
$webEntryUid = \G::generateUniqueID();
$webEntryUid = \ProcessMaker\Util\Common::generateUID();
$webEntry->setWeUid($webEntryUid);
$webEntry->setProUid($processUid);
@@ -622,7 +622,7 @@ class WebEntry
*
* return array Return data of the Web Entry updated
*/
public function update($webEntryUid, $userUidUpdater, $arrayData)
public function update($webEntryUid, $userUidUpdater, array $arrayData)
{
try {
//Verify data
@@ -797,7 +797,7 @@ class WebEntry
*
* return array Return an array with data Web Entry
*/
public function getWebEntryDataFromRecord($record)
public function getWebEntryDataFromRecord(array $record)
{
try {
if ($record["WE_METHOD"] == "WS") {
@@ -833,7 +833,7 @@ class WebEntry
$this->getFieldNameByFormatFieldName("WE_CREATE_USR_UID") => $record["WE_CREATE_USR_UID"],
$this->getFieldNameByFormatFieldName("WE_UPDATE_USR_UID") => $record["WE_UPDATE_USR_UID"] . "",
$this->getFieldNameByFormatFieldName("WE_CREATE_DATE") => $webEntryCreateDate,
$this->getFieldNameByFormatFieldName("WE_UPDATE_DATE") => $webEntryUpdateDate . ""
$this->getFieldNameByFormatFieldName("WE_UPDATE_DATE") => $webEntryUpdateDate
);
} catch (\Exception $e) {
throw $e;

View File

@@ -5,7 +5,7 @@ use \ProcessMaker\Services\Api;
use \Luracast\Restler\RestException;
/**
* Group Api Controller
* Calendar Api Controller
*
* @protected
*/

View File

@@ -71,7 +71,7 @@ class WebEntry extends Api
*
* @status 201
*/
public function doPostWebEntry($prj_uid, $request_data)
public function doPostWebEntry($prj_uid, array $request_data)
{
try {
$arrayData = $this->webEntry->create($prj_uid, $this->getUserId(), $request_data);
@@ -91,7 +91,7 @@ class WebEntry extends Api
* @param string $we_uid {@min 32}{@max 32}
* @param array $request_data
*/
public function doPutWebEntry($prj_uid, $we_uid, $request_data)
public function doPutWebEntry($prj_uid, $we_uid, array $request_data)
{
try {
$arrayData = $this->webEntry->update($we_uid, $this->getUserId(), $request_data);

View File

@@ -0,0 +1,111 @@
<?php
namespace ProcessMaker\Services\Api;
use \ProcessMaker\Services\Api;
use \Luracast\Restler\RestException;
/**
* Role Api Controller
*
* @protected
*/
class Role extends Api
{
private $role;
/**
* Constructor of the class
*
* return void
*/
public function __construct()
{
try {
$this->role = new \ProcessMaker\BusinessModel\Role();
$this->role->setFormatFieldNameInUppercase(false);
} catch (\Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
/**
* @url GET
*/
public function index($filter = null, $start = null, $limit = null)
{
try {
$response = $this->role->getRoles(array("filter" => $filter), null, null, $start, $limit);
return $response;
} catch (\Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
/**
* @url GET /:rol_uid
*
* @param string $rol_uid {@min 32}{@max 32}
*/
public function doGet($rol_uid)
{
try {
$response = $this->role->getRole($rol_uid);
return $response;
} catch (\Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
/**
* @url POST
*
* @param array $request_data
*
* @status 201
*/
public function doPost(array $request_data)
{
try {
$arrayData = $this->role->create($request_data);
$response = $arrayData;
return $response;
} catch (\Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
/**
* @url PUT /:rol_uid
*
* @param string $rol_uid {@min 32}{@max 32}
* @param array $request_data
*/
public function doPut($rol_uid, array $request_data)
{
try {
$arrayData = $this->role->update($rol_uid, $request_data);
} catch (\Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
/**
* @url DELETE /:rol_uid
*
* @param string $rol_uid {@min 32}{@max 32}
*/
public function doDelete($rol_uid)
{
try {
$this->role->delete($rol_uid);
} catch (\Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
}

View File

@@ -0,0 +1,81 @@
<?php
namespace ProcessMaker\Services\Api\Role;
use \ProcessMaker\Services\Api;
use \Luracast\Restler\RestException;
/**
* Role\User Api Controller
*
* @protected
*/
class User extends Api
{
private $roleUser;
/**
* Constructor of the class
*
* return void
*/
public function __construct()
{
try {
$this->roleUser = new \ProcessMaker\BusinessModel\Role\User();
$this->roleUser->setFormatFieldNameInUppercase(false);
} catch (\Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
/**
* @url GET /:rol_uid/users
* @url GET /:rol_uid/available-users
*
* @param string $rol_uid {@min 32}{@max 32}
*/
public function doGetUsers($rol_uid, $filter = null, $start = null, $limit = null)
{
try {
$response = $this->roleUser->getUsers($rol_uid, (preg_match("/^.*\/users$/", $this->restler->url))? "USERS" : "AVAILABLE-USERS", array("filter" => $filter), null, null, $start, $limit);
return $response;
} catch (\Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
/**
* @url POST /:rol_uid/user
*
* @param string $rol_uid {@min 32}{@max 32}
* @param array $request_data
*
* @status 201
*/
public function doPostUser($rol_uid, array $request_data)
{
try {
$arrayData = $this->roleUser->create($rol_uid, $request_data);
} catch (\Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
/**
* @url DELETE /:rol_uid/user/:usr_uid
*
* @param string $rol_uid {@min 32}{@max 32}
* @param string $usr_uid {@min 32}{@max 32}
*/
public function doDeleteUser($rol_uid, $usr_uid)
{
try {
$this->roleUser->delete($rol_uid, $usr_uid);
} catch (\Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
}

View File

@@ -70,3 +70,11 @@ debug = 1
input-document = "ProcessMaker\Services\Api\Cases\InputDocument"
output-document = "ProcessMaker\Services\Api\Cases\OutputDocument"
[alias: role]
role = "ProcessMaker\Services\Api\Role"
user = "ProcessMaker\Services\Api\Role\User"
permission = "ProcessMaker\Services\Api\Role\Permission"
[alias: roles]
role = "ProcessMaker\Services\Api\Role"

View File

@@ -122,6 +122,9 @@
</li>
</ul>
</div>
<div class="bpmn_shapes_legend">
<div class="head"></div>
</div>
</section>
</body>

View File

@@ -0,0 +1,5 @@
<!--<iframe name="casesFrame" id="casesFrame" src ="../designer?prj_uid=<?php echo $_SESSION['PROCESS']; ?>&prj_readonly=true&app_uid=<?php echo $_SESSION['APP_UID']; ?>" width="99%" height="768" frameborder="0">
<p>Your browser does not support iframes.</p>
</iframe>
-->
Not supported yet.

View File

@@ -5,6 +5,10 @@
try {
$rootDir = realpath(__DIR__ . "/../../") . DIRECTORY_SEPARATOR;
require $rootDir . "framework/src/Maveriks/Util/ClassLoader.php";
$loader = Maveriks\Util\ClassLoader::getInstance();
$loader->add($rootDir . 'framework/src/', "Maveriks");
if (! is_dir($rootDir . 'vendor')) {
if (file_exists($rootDir . 'composer.phar')) {
throw new Exception(
@@ -22,18 +26,6 @@ try {
}
}
if (! file_exists($rootDir . 'vendor' . DIRECTORY_SEPARATOR . "autoload.php")) {
throw new Exception(
"ERROR: Problems with Vendors!" . PHP_EOL .
"Please execute the following command to repair vendors:" .PHP_EOL.PHP_EOL.
"$>php composer.phar update"
);
}
require $rootDir . "framework/src/Maveriks/Util/ClassLoader.php";
$loader = Maveriks\Util\ClassLoader::getInstance();
$loader->add($rootDir . 'framework/src/', "Maveriks");
$loader->add($rootDir . 'workflow/engine/src/', "ProcessMaker");
//$loader->add($rootDir . "workflow/engine/classes/model/");
$loader->add($rootDir . 'workflow/engine/src/');