Refactoring of classes that where in workflow/engine/src , now all of them have a unique parent namespace \ProcessMaker
This commit is contained in:
717
workflow/engine/src/ProcessMaker/BusinessModel/Calendar.php
Normal file
717
workflow/engine/src/ProcessMaker/BusinessModel/Calendar.php
Normal file
@@ -0,0 +1,717 @@
|
||||
<?php
|
||||
namespace ProcessMaker\BusinessModel;
|
||||
|
||||
class Calendar
|
||||
{
|
||||
private $arrayFieldDefinition = array(
|
||||
"CAL_UID" => array("fieldName" => "CALENDAR_UID", "type" => "string", "required" => false, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "calendarUid"),
|
||||
|
||||
"CAL_NAME" => array("fieldName" => "CALENDAR_NAME", "type" => "string", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "calendarName"),
|
||||
"CAL_DESCRIPTION" => array("fieldName" => "CALENDAR_DESCRIPTION", "type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "calendarDescription"),
|
||||
"CAL_WORK_DAYS" => array("fieldName" => "CALENDAR_WORK_DAYS", "type" => "array", "required" => true, "empty" => false, "defaultValues" => array("SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"), "fieldNameAux" => "calendarWorkDays"),
|
||||
"CAL_STATUS" => array("fieldName" => "CALENDAR_STATUS", "type" => "string", "required" => true, "empty" => false, "defaultValues" => array("ACTIVE", "INACTIVE"), "fieldNameAux" => "calendarStatus"),
|
||||
"CAL_WORK_HOUR" => array("fieldName" => "CALENDAR_WORK_HOUR", "type" => "array", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "calendarWorkHour"),
|
||||
"CAL_HOLIDAY" => array("fieldName" => "CALENDAR_HOLIDAY", "type" => "array", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "calendarHoliday"),
|
||||
|
||||
"CAL_CREATE_DATE" => array("fieldName" => "CALENDAR_CREATE_DATE", "type" => "datetime", "required" => false, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "calendarCreateDate"),
|
||||
"CAL_UPDATE_DATE" => array("fieldName" => "CALENDAR_UPDATE_DATE", "type" => "datetime", "required" => false, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "calendarUpdateDate")
|
||||
);
|
||||
|
||||
private $arrayWorkHourFieldDefinition = array(
|
||||
"DAY" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array("SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT", "ALL"), "fieldNameAux" => "day"),
|
||||
"HOUR_START" => array("type" => "hour", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "hourStart"),
|
||||
"HOUR_END" => array("type" => "hour", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "hourEnd")
|
||||
);
|
||||
|
||||
private $arrayHolidayFieldDefinition = array(
|
||||
"NAME" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "name"),
|
||||
"DATE_START" => array("type" => "date", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "dateStart"),
|
||||
"DATE_END" => array("type" => "date", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "dateEnd")
|
||||
);
|
||||
|
||||
private $formatFieldNameInUppercase = true;
|
||||
|
||||
private $arrayFieldNameForException = array(
|
||||
"filter" => "FILTER",
|
||||
"start" => "START",
|
||||
"limit" => "LIMIT"
|
||||
);
|
||||
private $arrayWorkHourFieldNameForException = array();
|
||||
private $arrayHolidayFieldNameForException = array();
|
||||
|
||||
/**
|
||||
* Constructor of the class
|
||||
*
|
||||
* return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
try {
|
||||
foreach ($this->arrayFieldDefinition as $key => $value) {
|
||||
$this->arrayFieldNameForException[$value["fieldNameAux"]] = $key;
|
||||
}
|
||||
|
||||
foreach ($this->arrayWorkHourFieldDefinition as $key => $value) {
|
||||
$this->arrayWorkHourFieldNameForException[$value["fieldNameAux"]] = $key;
|
||||
}
|
||||
|
||||
foreach ($this->arrayHolidayFieldDefinition as $key => $value) {
|
||||
$this->arrayHolidayFieldNameForException[$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);
|
||||
$this->setArrayWorkHourFieldNameForException($this->arrayWorkHourFieldNameForException);
|
||||
$this->setArrayHolidayFieldNameForException($this->arrayHolidayFieldNameForException);
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set exception messages for fields
|
||||
*
|
||||
* @param array $arrayData Data with the fields
|
||||
*
|
||||
* return void
|
||||
*/
|
||||
public function setArrayFieldNameForException($arrayData)
|
||||
{
|
||||
try {
|
||||
foreach ($arrayData as $key => $value) {
|
||||
$this->arrayFieldNameForException[$key] = $this->getFieldNameByFormatFieldName($value);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set exception messages for fields
|
||||
*
|
||||
* @param array $arrayData Data with the fields
|
||||
*
|
||||
* return void
|
||||
*/
|
||||
public function setArrayWorkHourFieldNameForException($arrayData)
|
||||
{
|
||||
try {
|
||||
foreach ($arrayData as $key => $value) {
|
||||
$this->arrayWorkHourFieldNameForException[$key] = $this->getFieldNameByFormatFieldName($value);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set exception messages for fields
|
||||
*
|
||||
* @param array $arrayData Data with the fields
|
||||
*
|
||||
* return void
|
||||
*/
|
||||
public function setArrayHolidayFieldNameForException($arrayData)
|
||||
{
|
||||
try {
|
||||
foreach ($arrayData as $key => $value) {
|
||||
$this->arrayHolidayFieldNameForException[$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 name of a Calendar
|
||||
*
|
||||
* @param string $calendarName Name
|
||||
* @param string $calendarUidExclude Unique id of Calendar to exclude
|
||||
*
|
||||
* return bool Return true if exists the name of a Calendar, false otherwise
|
||||
*/
|
||||
public function existsName($calendarName, $calendarUidExclude = "")
|
||||
{
|
||||
try {
|
||||
$criteria = new \Criteria("workflow");
|
||||
|
||||
$criteria->addSelectColumn(\CalendarDefinitionPeer::CALENDAR_UID);
|
||||
$criteria->add(\CalendarDefinitionPeer::CALENDAR_STATUS, "DELETED", \Criteria::NOT_EQUAL);
|
||||
|
||||
if ($calendarUidExclude != "") {
|
||||
$criteria->add(\CalendarDefinitionPeer::CALENDAR_UID, $calendarUidExclude, \Criteria::NOT_EQUAL);
|
||||
}
|
||||
|
||||
$criteria->add(\CalendarDefinitionPeer::CALENDAR_NAME, $calendarName, \Criteria::EQUAL);
|
||||
|
||||
$rsCriteria = \CalendarDefinitionPeer::doSelectRS($criteria);
|
||||
|
||||
if ($rsCriteria->next()) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace and Get Work Days
|
||||
*
|
||||
* @param string $workDays Work days
|
||||
* @param bool $toNumber If is true replace to numbers, replace to string otherwise
|
||||
*
|
||||
* return string Return Work days
|
||||
*/
|
||||
public function workDaysReplaceData($workDays, $toNumber = true)
|
||||
{
|
||||
try {
|
||||
$arrayDayString = array("SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT", "ALL");
|
||||
$arrayDayNumber = array(0, 1, 2, 3, 4, 5, 6, 7);
|
||||
|
||||
return ($toNumber)? str_replace($arrayDayString, $arrayDayNumber, $workDays) : str_replace($arrayDayNumber, $arrayDayString, $workDays);
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify if doesn't exists the Calendar in table CALENDAR_DEFINITION
|
||||
*
|
||||
* @param string $calendarUid Unique id of Calendar
|
||||
* @param string $fieldNameForException Field name for the exception
|
||||
*
|
||||
* return void Throw exception if doesn't exists the Calendar in table CALENDAR_DEFINITION
|
||||
*/
|
||||
public function throwExceptionIfNotExistsCalendar($calendarUid, $fieldNameForException)
|
||||
{
|
||||
try {
|
||||
$obj = \CalendarDefinitionPeer::retrieveByPK($calendarUid);
|
||||
|
||||
if (!(is_object($obj) && get_class($obj) == "CalendarDefinition")) {
|
||||
$msg = str_replace(array("{0}", "{1}"), array($fieldNameForException, $calendarUid), "The calendar with {0}: {1} does not exists");
|
||||
|
||||
throw (new \Exception($msg));
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify if exists the name of a Calendar
|
||||
*
|
||||
* @param string $calendarName Name
|
||||
* @param string $fieldNameForException Field name for the exception
|
||||
* @param string $calendarUidExclude Unique id of Calendar to exclude
|
||||
*
|
||||
* return void Throw exception if exists the name of a Calendar
|
||||
*/
|
||||
public function throwExceptionIfExistsName($calendarName, $fieldNameForException, $calendarUidExclude = "")
|
||||
{
|
||||
try {
|
||||
if ($this->existsName($calendarName, $calendarUidExclude)) {
|
||||
$msg = str_replace(array("{0}", "{1}"), array($fieldNameForException, $calendarName), "The calendar name with {0}: \"{1}\" already exists");
|
||||
|
||||
throw (new \Exception($msg));
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Group
|
||||
*
|
||||
* @param array $arrayData Data
|
||||
*
|
||||
* return array Return data of the new Group created
|
||||
*/
|
||||
public function create($arrayData)
|
||||
{
|
||||
try {
|
||||
$arrayData = \G::array_change_key_case2($arrayData, CASE_UPPER);
|
||||
|
||||
unset($arrayData["CAL_UID"]);
|
||||
|
||||
//Verify data
|
||||
$process = new \ProcessMaker\BusinessModel\Process();
|
||||
|
||||
$process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $this->arrayFieldDefinition, $this->arrayFieldNameForException, true);
|
||||
|
||||
$this->throwExceptionIfExistsName($arrayData["CAL_NAME"], $this->arrayFieldNameForException["calendarName"]);
|
||||
|
||||
if (isset($arrayData["CAL_WORK_DAYS"]) && count($arrayData["CAL_WORK_DAYS"]) < 3) {
|
||||
throw (new \Exception(\G::LoadTranslation("ID_MOST_AT_LEAST_3_DAY")));
|
||||
}
|
||||
|
||||
if (isset($arrayData["CAL_WORK_HOUR"])) {
|
||||
foreach ($arrayData["CAL_WORK_HOUR"] as $value) {
|
||||
$process->throwExceptionIfDataNotMetFieldDefinition($value, $this->arrayWorkHourFieldDefinition, $this->arrayWorkHourFieldNameForException, true);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($arrayData["CAL_HOLIDAY"])) {
|
||||
foreach ($arrayData["CAL_HOLIDAY"] as $value) {
|
||||
$process->throwExceptionIfDataNotMetFieldDefinition($value, $this->arrayHolidayFieldDefinition, $this->arrayHolidayFieldNameForException, true);
|
||||
}
|
||||
}
|
||||
|
||||
//Set variables
|
||||
$arrayCalendarWorkHour = array();
|
||||
|
||||
if (isset($arrayData["CAL_WORK_HOUR"])) {
|
||||
foreach ($arrayData["CAL_WORK_HOUR"] as $value) {
|
||||
if ($value["DAY"] != "ALL" && !in_array($value["DAY"], $arrayData["CAL_WORK_DAYS"])) {
|
||||
throw (new \Exception(str_replace(array("{0}", "{1}"), array($this->arrayWorkHourFieldNameForException["day"], $this->arrayFieldNameForException["calendarWorkDays"]), "Value specified for \"{0}\" does not exists in \"{1}\"")));
|
||||
}
|
||||
|
||||
$arrayCalendarWorkHour[] = array(
|
||||
"CALENDAR_BUSINESS_DAY" => $this->workDaysReplaceData($value["DAY"]),
|
||||
"CALENDAR_BUSINESS_START" => $value["HOUR_START"],
|
||||
"CALENDAR_BUSINESS_END" => $value["HOUR_END"]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$arrayCalendarHoliday = array();
|
||||
|
||||
if (isset($arrayData["CAL_HOLIDAY"])) {
|
||||
foreach ($arrayData["CAL_HOLIDAY"] as $value) {
|
||||
$arrayCalendarHoliday[] = array(
|
||||
"CALENDAR_HOLIDAY_NAME" => $value["NAME"],
|
||||
"CALENDAR_HOLIDAY_START" => $value["DATE_START"],
|
||||
"CALENDAR_HOLIDAY_END" => $value["DATE_END"]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$arrayDataAux = array();
|
||||
$arrayDataAux["CALENDAR_UID"] = \G::generateUniqueID();
|
||||
$arrayDataAux["CALENDAR_NAME"] = $arrayData["CAL_NAME"];
|
||||
|
||||
if (isset($arrayData["CAL_DESCRIPTION"])) {
|
||||
$arrayDataAux["CALENDAR_DESCRIPTION"] = $arrayData["CAL_DESCRIPTION"];
|
||||
}
|
||||
|
||||
$arrayDataAux["CALENDAR_WORK_DAYS"] = explode("|", $this->workDaysReplaceData(implode("|", $arrayData["CAL_WORK_DAYS"])));
|
||||
$arrayDataAux["CALENDAR_STATUS"] = $arrayData["CAL_STATUS"];
|
||||
|
||||
$arrayDataAux["BUSINESS_DAY"] = $arrayCalendarWorkHour;
|
||||
$arrayDataAux["HOLIDAY"] = $arrayCalendarHoliday;
|
||||
|
||||
//Create
|
||||
$calendarDefinition = new \CalendarDefinition();
|
||||
|
||||
$calendarDefinition->saveCalendarInfo($arrayDataAux);
|
||||
|
||||
//Return
|
||||
$arrayData = array_merge(array("CAL_UID" => $arrayDataAux["CALENDAR_UID"]), $arrayData);
|
||||
|
||||
if (!$this->formatFieldNameInUppercase) {
|
||||
$arrayData = \G::array_change_key_case2($arrayData, CASE_LOWER);
|
||||
}
|
||||
|
||||
return $arrayData;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update Calendar
|
||||
*
|
||||
* @param string $calendarUid Unique id of Calendar
|
||||
* @param array $arrayData Data
|
||||
*
|
||||
* return array Return data of the Calendar updated
|
||||
*/
|
||||
public function update($calendarUid, $arrayData)
|
||||
{
|
||||
try {
|
||||
$arrayData = \G::array_change_key_case2($arrayData, CASE_UPPER);
|
||||
|
||||
//Verify data
|
||||
$process = new \ProcessMaker\BusinessModel\Process();
|
||||
|
||||
$this->throwExceptionIfNotExistsCalendar($calendarUid, $this->arrayFieldNameForException["calendarUid"]);
|
||||
|
||||
$process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $this->arrayFieldDefinition, $this->arrayFieldNameForException, false);
|
||||
|
||||
if (isset($arrayData["CAL_NAME"])) {
|
||||
$this->throwExceptionIfExistsName($arrayData["CAL_NAME"], $this->arrayFieldNameForException["calendarName"], $calendarUid);
|
||||
}
|
||||
|
||||
if (isset($arrayData["CAL_WORK_DAYS"]) && count($arrayData["CAL_WORK_DAYS"]) < 3) {
|
||||
throw (new \Exception(\G::LoadTranslation("ID_MOST_AT_LEAST_3_DAY")));
|
||||
}
|
||||
|
||||
if (isset($arrayData["CAL_WORK_HOUR"])) {
|
||||
foreach ($arrayData["CAL_WORK_HOUR"] as $value) {
|
||||
$process->throwExceptionIfDataNotMetFieldDefinition($value, $this->arrayWorkHourFieldDefinition, $this->arrayWorkHourFieldNameForException, true);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($arrayData["CAL_HOLIDAY"])) {
|
||||
foreach ($arrayData["CAL_HOLIDAY"] as $value) {
|
||||
$process->throwExceptionIfDataNotMetFieldDefinition($value, $this->arrayHolidayFieldDefinition, $this->arrayHolidayFieldNameForException, true);
|
||||
}
|
||||
}
|
||||
|
||||
//Set variables
|
||||
$arrayCalendarData = \G::array_change_key_case2($this->getCalendar($calendarUid), CASE_UPPER);
|
||||
|
||||
$calendarWorkDays = (isset($arrayData["CAL_WORK_DAYS"]))? $arrayData["CAL_WORK_DAYS"] : $arrayCalendarData["CAL_WORK_DAYS"];
|
||||
|
||||
$arrayCalendarWorkHour = array();
|
||||
$arrayAux = (isset($arrayData["CAL_WORK_HOUR"]))? $arrayData["CAL_WORK_HOUR"] : $arrayCalendarData["CAL_WORK_HOUR"];
|
||||
|
||||
foreach ($arrayAux as $value) {
|
||||
if (isset($arrayData["CAL_WORK_HOUR"]) && $value["DAY"] != "ALL" && !in_array($value["DAY"], $calendarWorkDays)) {
|
||||
throw (new \Exception(str_replace(array("{0}", "{1}"), array($this->arrayWorkHourFieldNameForException["day"], $this->arrayFieldNameForException["calendarWorkDays"]), "Value specified for \"{0}\" does not exists in \"{1}\"")));
|
||||
}
|
||||
|
||||
$arrayCalendarWorkHour[] = array(
|
||||
"CALENDAR_BUSINESS_DAY" => $this->workDaysReplaceData($value["DAY"]),
|
||||
"CALENDAR_BUSINESS_START" => $value["HOUR_START"],
|
||||
"CALENDAR_BUSINESS_END" => $value["HOUR_END"]
|
||||
);
|
||||
}
|
||||
|
||||
$arrayCalendarHoliday = array();
|
||||
$arrayAux = (isset($arrayData["CAL_HOLIDAY"]))? $arrayData["CAL_HOLIDAY"] : $arrayCalendarData["CAL_HOLIDAY"];
|
||||
|
||||
foreach ($arrayAux as $value) {
|
||||
$arrayCalendarHoliday[] = array(
|
||||
"CALENDAR_HOLIDAY_NAME" => $value["NAME"],
|
||||
"CALENDAR_HOLIDAY_START" => $value["DATE_START"],
|
||||
"CALENDAR_HOLIDAY_END" => $value["DATE_END"]
|
||||
);
|
||||
}
|
||||
|
||||
$arrayDataAux = array();
|
||||
$arrayDataAux["CALENDAR_UID"] = $calendarUid;
|
||||
$arrayDataAux["CALENDAR_NAME"] = (isset($arrayData["CAL_NAME"]))? $arrayData["CAL_NAME"] : $arrayCalendarData["CAL_NAME"];
|
||||
$arrayDataAux["CALENDAR_DESCRIPTION"] = (isset($arrayData["CAL_DESCRIPTION"]))? $arrayData["CAL_DESCRIPTION"] : $arrayCalendarData["CAL_DESCRIPTION"];
|
||||
$arrayDataAux["CALENDAR_WORK_DAYS"] = explode("|", $this->workDaysReplaceData(implode("|", $calendarWorkDays)));
|
||||
$arrayDataAux["CALENDAR_STATUS"] = (isset($arrayData["CAL_STATUS"]))? $arrayData["CAL_STATUS"] : $arrayCalendarData["CAL_STATUS"];
|
||||
|
||||
$arrayDataAux["BUSINESS_DAY"] = $arrayCalendarWorkHour;
|
||||
$arrayDataAux["HOLIDAY"] = $arrayCalendarHoliday;
|
||||
|
||||
//Update
|
||||
$calendarDefinition = new \CalendarDefinition();
|
||||
|
||||
$calendarDefinition->saveCalendarInfo($arrayDataAux);
|
||||
|
||||
//Return
|
||||
if (!$this->formatFieldNameInUppercase) {
|
||||
$arrayData = \G::array_change_key_case2($arrayData, CASE_LOWER);
|
||||
}
|
||||
|
||||
return $arrayData;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete Calendar
|
||||
*
|
||||
* @param string $calendarUid Unique id of Calendar
|
||||
*
|
||||
* return void
|
||||
*/
|
||||
public function delete($calendarUid)
|
||||
{
|
||||
try {
|
||||
//Verify data
|
||||
$calendarDefinition = new \CalendarDefinition();
|
||||
|
||||
$this->throwExceptionIfNotExistsCalendar($calendarUid, $this->arrayFieldNameForException["calendarUid"]);
|
||||
|
||||
$arrayAux = $calendarDefinition->getAllCounterByCalendar("USER");
|
||||
$nU = (isset($arrayAux[$calendarUid]))? $arrayAux[$calendarUid] : 0;
|
||||
$arrayAux = $calendarDefinition->getAllCounterByCalendar("TASK");
|
||||
$nT = (isset($arrayAux[$calendarUid]))? $arrayAux[$calendarUid] : 0;
|
||||
$arrayAux = $calendarDefinition->getAllCounterByCalendar("PROCESS");
|
||||
$nP = (isset($arrayAux[$calendarUid]))? $arrayAux[$calendarUid] : 0;
|
||||
|
||||
if ($nU + $nT + $nP > 0) {
|
||||
throw (new \Exception(\G::LoadTranslation("ID_MSG_CANNOT_DELETE_CALENDAR")));
|
||||
}
|
||||
|
||||
//Delete
|
||||
$calendarDefinition->deleteCalendar($calendarUid);
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get criteria for Calendar
|
||||
*
|
||||
* return object
|
||||
*/
|
||||
public function getCalendarCriteria()
|
||||
{
|
||||
try {
|
||||
$criteria = new \Criteria("workflow");
|
||||
|
||||
$criteria->addSelectColumn(\CalendarDefinitionPeer::CALENDAR_UID);
|
||||
$criteria->addSelectColumn(\CalendarDefinitionPeer::CALENDAR_NAME);
|
||||
$criteria->addSelectColumn(\CalendarDefinitionPeer::CALENDAR_DESCRIPTION);
|
||||
$criteria->addSelectColumn(\CalendarDefinitionPeer::CALENDAR_WORK_DAYS);
|
||||
$criteria->addSelectColumn(\CalendarDefinitionPeer::CALENDAR_STATUS);
|
||||
$criteria->addSelectColumn(\CalendarDefinitionPeer::CALENDAR_CREATE_DATE);
|
||||
$criteria->addSelectColumn(\CalendarDefinitionPeer::CALENDAR_UPDATE_DATE);
|
||||
$criteria->add(\CalendarDefinitionPeer::CALENDAR_STATUS, "DELETED", \Criteria::NOT_EQUAL);
|
||||
|
||||
return $criteria;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data of a Calendar from a record
|
||||
*
|
||||
* @param array $record Record
|
||||
*
|
||||
* return array Return an array with data Calendar
|
||||
*/
|
||||
public function getCalendarDataFromRecord($record)
|
||||
{
|
||||
try {
|
||||
$calendarBusinessHours = new \CalendarBusinessHours();
|
||||
$calendarHolidays = new \CalendarHolidays();
|
||||
|
||||
$arrayCalendarWorkHour = array();
|
||||
$arrayData = $calendarBusinessHours->getCalendarBusinessHours($record["CALENDAR_UID"]);
|
||||
|
||||
foreach ($arrayData as $value) {
|
||||
$arrayCalendarWorkHour[] = array(
|
||||
$this->getFieldNameByFormatFieldName("DAY") => $this->workDaysReplaceData($value["CALENDAR_BUSINESS_DAY"] . "", false),
|
||||
$this->getFieldNameByFormatFieldName("HOUR_START") => $value["CALENDAR_BUSINESS_START"] . "",
|
||||
$this->getFieldNameByFormatFieldName("HOUR_END") => $value["CALENDAR_BUSINESS_END"] . "",
|
||||
);
|
||||
}
|
||||
|
||||
$arrayCalendarHoliday = array();
|
||||
$arrayData = $calendarHolidays->getCalendarHolidays($record["CALENDAR_UID"]);
|
||||
|
||||
foreach ($arrayData as $value) {
|
||||
$arrayCalendarHoliday[] = array(
|
||||
$this->getFieldNameByFormatFieldName("NAME") => $value["CALENDAR_HOLIDAY_NAME"] . "",
|
||||
$this->getFieldNameByFormatFieldName("DATE_START") => $value["CALENDAR_HOLIDAY_START"] . "",
|
||||
$this->getFieldNameByFormatFieldName("DATE_END") => $value["CALENDAR_HOLIDAY_END"] . "",
|
||||
);
|
||||
}
|
||||
|
||||
return array(
|
||||
$this->getFieldNameByFormatFieldName("CAL_UID") => $record["CALENDAR_UID"],
|
||||
$this->getFieldNameByFormatFieldName("CAL_NAME") => $record["CALENDAR_NAME"],
|
||||
$this->getFieldNameByFormatFieldName("CAL_DESCRIPTION") => $record["CALENDAR_DESCRIPTION"] . "",
|
||||
$this->getFieldNameByFormatFieldName("CAL_WORK_DAYS") => explode("|", $this->workDaysReplaceData($record["CALENDAR_WORK_DAYS"] . "", false)),
|
||||
$this->getFieldNameByFormatFieldName("CAL_STATUS") => $record["CALENDAR_STATUS"],
|
||||
$this->getFieldNameByFormatFieldName("CAL_WORK_HOUR") => $arrayCalendarWorkHour,
|
||||
$this->getFieldNameByFormatFieldName("CAL_HOLIDAY") => $arrayCalendarHoliday,
|
||||
$this->getFieldNameByFormatFieldName("CAL_CREATE_DATE") => $record["CALENDAR_CREATE_DATE"] . "",
|
||||
$this->getFieldNameByFormatFieldName("CAL_UPDATE_DATE") => $record["CALENDAR_UPDATE_DATE"] . "",
|
||||
$this->getFieldNameByFormatFieldName("CAL_TOTAL_USERS") => (int)($record["CALENDAR_TOTAL_USERS"]),
|
||||
$this->getFieldNameByFormatFieldName("CAL_TOTAL_PROCESSES") => (int)($record["CALENDAR_TOTAL_PROCESSES"]),
|
||||
$this->getFieldNameByFormatFieldName("CAL_TOTAL_TASKS") => (int)($record["CALENDAR_TOTAL_TASKS"])
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all Calendars
|
||||
*
|
||||
* @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 Calendars
|
||||
*/
|
||||
public function getCalendars($arrayFilterData = null, $sortField = null, $sortDir = null, $start = null, $limit = null)
|
||||
{
|
||||
try {
|
||||
$arrayCalendar = 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 $arrayCalendar;
|
||||
}
|
||||
|
||||
//Set variables
|
||||
$calendar = new \CalendarDefinition();
|
||||
|
||||
$arrayTotalUsersByCalendar = $calendar->getAllCounterByCalendar("USER");
|
||||
$arrayTotalProcessesByCalendar = $calendar->getAllCounterByCalendar("PROCESS");
|
||||
$arrayTotalTasksByCalendar = $calendar->getAllCounterByCalendar("TASK");
|
||||
|
||||
//SQL
|
||||
$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);
|
||||
}
|
||||
|
||||
//Number records total
|
||||
$criteriaCount = clone $criteria;
|
||||
|
||||
$criteriaCount->clearSelectColumns();
|
||||
$criteriaCount->addSelectColumn("COUNT(" . \CalendarDefinitionPeer::CALENDAR_UID . ") AS NUM_REC");
|
||||
|
||||
$rsCriteriaCount = \CalendarDefinitionPeer::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);
|
||||
$sortField = (isset($this->arrayFieldDefinition[$sortField]["fieldName"]))? $this->arrayFieldDefinition[$sortField]["fieldName"] : $sortField;
|
||||
|
||||
switch ($sortField) {
|
||||
case "CALENDAR_UID":
|
||||
case "CALENDAR_NAME":
|
||||
case "CALENDAR_DESCRIPTION":
|
||||
case "CALENDAR_WORK_DAYS":
|
||||
case "CALENDAR_STATUS":
|
||||
case "CALENDAR_CREATE_DATE":
|
||||
case "CALENDAR_UPDATE_DATE":
|
||||
$sortField = \CalendarDefinitionPeer::TABLE_NAME . "." . $sortField;
|
||||
break;
|
||||
default:
|
||||
$sortField = \CalendarDefinitionPeer::CALENDAR_NAME;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
$sortField = \CalendarDefinitionPeer::CALENDAR_NAME;
|
||||
}
|
||||
|
||||
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 = \CalendarDefinitionPeer::doSelectRS($criteria);
|
||||
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
|
||||
while ($rsCriteria->next()) {
|
||||
$row = $rsCriteria->getRow();
|
||||
|
||||
$row["CALENDAR_TOTAL_USERS"] = (isset($arrayTotalUsersByCalendar[$row["CALENDAR_UID"]]))? $arrayTotalUsersByCalendar[$row["CALENDAR_UID"]] : 0;
|
||||
$row["CALENDAR_TOTAL_PROCESSES"] = (isset($arrayTotalProcessesByCalendar[$row["CALENDAR_UID"]]))? $arrayTotalProcessesByCalendar[$row["CALENDAR_UID"]] : 0;
|
||||
$row["CALENDAR_TOTAL_TASKS"] = (isset($arrayTotalTasksByCalendar[$row["CALENDAR_UID"]]))? $arrayTotalTasksByCalendar[$row["CALENDAR_UID"]] : 0;
|
||||
|
||||
$arrayCalendar[] = $this->getCalendarDataFromRecord($row);
|
||||
}
|
||||
|
||||
//Return
|
||||
return $arrayCalendar;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data of a Calendar
|
||||
*
|
||||
* @param string $calendarUid Unique id of Calendar
|
||||
*
|
||||
* return array Return an array with data of a Calendar
|
||||
*/
|
||||
public function getCalendar($calendarUid)
|
||||
{
|
||||
try {
|
||||
//Verify data
|
||||
$this->throwExceptionIfNotExistsCalendar($calendarUid, $this->arrayFieldNameForException["calendarUid"]);
|
||||
|
||||
//Get data
|
||||
//Set variables
|
||||
$calendar = new \CalendarDefinition();
|
||||
|
||||
$arrayTotalUsersByCalendar = $calendar->getAllCounterByCalendar("USER");
|
||||
$arrayTotalProcessesByCalendar = $calendar->getAllCounterByCalendar("PROCESS");
|
||||
$arrayTotalTasksByCalendar = $calendar->getAllCounterByCalendar("TASK");
|
||||
|
||||
//SQL
|
||||
$criteria = $this->getCalendarCriteria();
|
||||
|
||||
$criteria->add(\CalendarDefinitionPeer::CALENDAR_UID, $calendarUid, \Criteria::EQUAL);
|
||||
|
||||
$rsCriteria = \CalendarDefinitionPeer::doSelectRS($criteria);
|
||||
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
|
||||
$rsCriteria->next();
|
||||
|
||||
$row = $rsCriteria->getRow();
|
||||
|
||||
$row["CALENDAR_TOTAL_USERS"] = (isset($arrayTotalUsersByCalendar[$calendarUid]))? $arrayTotalUsersByCalendar[$calendarUid] : 0;
|
||||
$row["CALENDAR_TOTAL_PROCESSES"] = (isset($arrayTotalProcessesByCalendar[$calendarUid]))? $arrayTotalProcessesByCalendar[$calendarUid] : 0;
|
||||
$row["CALENDAR_TOTAL_TASKS"] = (isset($arrayTotalTasksByCalendar[$calendarUid]))? $arrayTotalTasksByCalendar[$calendarUid] : 0;
|
||||
|
||||
//Return
|
||||
return $this->getCalendarDataFromRecord($row);
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
841
workflow/engine/src/ProcessMaker/BusinessModel/CaseScheduler.php
Normal file
841
workflow/engine/src/ProcessMaker/BusinessModel/CaseScheduler.php
Normal file
@@ -0,0 +1,841 @@
|
||||
<?php
|
||||
namespace ProcessMaker\BusinessModel;
|
||||
|
||||
use \G;
|
||||
|
||||
class CaseScheduler
|
||||
{
|
||||
/**
|
||||
* Return case scheduler of a project
|
||||
* @param string $sProcessUID
|
||||
* @return array
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function getCaseSchedulers($sProcessUID = '')
|
||||
{
|
||||
try {
|
||||
$oCriteria = new \Criteria( 'workflow' );
|
||||
$oCriteria->clearSelectColumns();
|
||||
$oCriteria->addSelectColumn( \CaseSchedulerPeer::SCH_UID );
|
||||
$oCriteria->addSelectColumn( \CaseSchedulerPeer::SCH_NAME );
|
||||
$oCriteria->addSelectColumn( \CaseSchedulerPeer::SCH_DEL_USER_NAME );
|
||||
$oCriteria->addSelectColumn( \CaseSchedulerPeer::SCH_DEL_USER_UID );
|
||||
$oCriteria->addSelectColumn( \CaseSchedulerPeer::PRO_UID );
|
||||
$oCriteria->addSelectColumn( \CaseSchedulerPeer::TAS_UID );
|
||||
$oCriteria->addSelectColumn( \CaseSchedulerPeer::SCH_TIME_NEXT_RUN );
|
||||
$oCriteria->addSelectColumn( \CaseSchedulerPeer::SCH_LAST_RUN_TIME );
|
||||
$oCriteria->addSelectColumn( \CaseSchedulerPeer::SCH_STATE );
|
||||
$oCriteria->addSelectColumn( \CaseSchedulerPeer::SCH_LAST_STATE );
|
||||
$oCriteria->addSelectColumn( \CaseSchedulerPeer::USR_UID );
|
||||
$oCriteria->addSelectColumn( \CaseSchedulerPeer::SCH_OPTION );
|
||||
$oCriteria->addSelectColumn( \CaseSchedulerPeer::SCH_START_TIME );
|
||||
$oCriteria->addSelectColumn( \CaseSchedulerPeer::SCH_START_DATE );
|
||||
$oCriteria->addSelectColumn( \CaseSchedulerPeer::SCH_DAYS_PERFORM_TASK );
|
||||
$oCriteria->addSelectColumn( \CaseSchedulerPeer::SCH_EVERY_DAYS );
|
||||
$oCriteria->addSelectColumn( \CaseSchedulerPeer::SCH_WEEK_DAYS );
|
||||
$oCriteria->addSelectColumn( \CaseSchedulerPeer::SCH_START_DAY );
|
||||
$oCriteria->addSelectColumn( \CaseSchedulerPeer::SCH_MONTHS );
|
||||
$oCriteria->addSelectColumn( \CaseSchedulerPeer::SCH_END_DATE );
|
||||
$oCriteria->addSelectColumn( \CaseSchedulerPeer::SCH_REPEAT_EVERY );
|
||||
$oCriteria->addSelectColumn( \CaseSchedulerPeer::SCH_REPEAT_UNTIL );
|
||||
$oCriteria->addSelectColumn( \CaseSchedulerPeer::SCH_REPEAT_STOP_IF_RUNNING );
|
||||
$oCriteria->addSelectColumn( \CaseSchedulerPeer::CASE_SH_PLUGIN_UID );
|
||||
$oCriteria->add( \CaseSchedulerPeer::PRO_UID, $sProcessUID );
|
||||
$oDataset = \CaseSchedulerPeer::doSelectRS( $oCriteria );
|
||||
$oDataset->setFetchmode( \ResultSet::FETCHMODE_ASSOC );
|
||||
$oDataset->next();
|
||||
$aRows = array();
|
||||
while ($aRow = $oDataset->getRow()) {
|
||||
$aRow = array_change_key_case($aRow, CASE_LOWER);
|
||||
$aRows[] = $aRow;
|
||||
$oDataset->next();
|
||||
}
|
||||
return $aRows;
|
||||
} catch (Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return case scheduler of a project
|
||||
* @param string $sProcessUID
|
||||
* @param string $sCaseSchedulerUID
|
||||
* @return array
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function getCaseScheduler($sProcessUID = '', $sCaseSchedulerUID = '')
|
||||
{
|
||||
try {
|
||||
$oCaseSchedulerTest = \CaseSchedulerPeer::retrieveByPK( $sCaseSchedulerUID );
|
||||
if (is_null($oCaseSchedulerTest)) {
|
||||
throw (new \Exception( 'This id: '. $sCaseSchedulerUID .' does not correspond to a registered case scheduler'));
|
||||
}
|
||||
$oCriteria = new \Criteria( 'workflow' );
|
||||
$oCriteria->clearSelectColumns();
|
||||
$oCriteria->addSelectColumn( \CaseSchedulerPeer::SCH_UID );
|
||||
$oCriteria->addSelectColumn( \CaseSchedulerPeer::SCH_NAME );
|
||||
$oCriteria->addSelectColumn( \CaseSchedulerPeer::SCH_DEL_USER_NAME );
|
||||
$oCriteria->addSelectColumn( \CaseSchedulerPeer::SCH_DEL_USER_UID );
|
||||
$oCriteria->addSelectColumn( \CaseSchedulerPeer::PRO_UID );
|
||||
$oCriteria->addSelectColumn( \CaseSchedulerPeer::TAS_UID );
|
||||
$oCriteria->addSelectColumn( \CaseSchedulerPeer::SCH_TIME_NEXT_RUN );
|
||||
$oCriteria->addSelectColumn( \CaseSchedulerPeer::SCH_LAST_RUN_TIME );
|
||||
$oCriteria->addSelectColumn( \CaseSchedulerPeer::SCH_STATE );
|
||||
$oCriteria->addSelectColumn( \CaseSchedulerPeer::SCH_LAST_STATE );
|
||||
$oCriteria->addSelectColumn( \CaseSchedulerPeer::USR_UID );
|
||||
$oCriteria->addSelectColumn( \CaseSchedulerPeer::SCH_OPTION );
|
||||
$oCriteria->addSelectColumn( \CaseSchedulerPeer::SCH_START_TIME );
|
||||
$oCriteria->addSelectColumn( \CaseSchedulerPeer::SCH_START_DATE );
|
||||
$oCriteria->addSelectColumn( \CaseSchedulerPeer::SCH_DAYS_PERFORM_TASK );
|
||||
$oCriteria->addSelectColumn( \CaseSchedulerPeer::SCH_EVERY_DAYS );
|
||||
$oCriteria->addSelectColumn( \CaseSchedulerPeer::SCH_WEEK_DAYS );
|
||||
$oCriteria->addSelectColumn( \CaseSchedulerPeer::SCH_START_DAY );
|
||||
$oCriteria->addSelectColumn( \CaseSchedulerPeer::SCH_MONTHS );
|
||||
$oCriteria->addSelectColumn( \CaseSchedulerPeer::SCH_END_DATE );
|
||||
$oCriteria->addSelectColumn( \CaseSchedulerPeer::SCH_REPEAT_EVERY );
|
||||
$oCriteria->addSelectColumn( \CaseSchedulerPeer::SCH_REPEAT_UNTIL );
|
||||
$oCriteria->addSelectColumn( \CaseSchedulerPeer::SCH_REPEAT_STOP_IF_RUNNING );
|
||||
$oCriteria->addSelectColumn( \CaseSchedulerPeer::CASE_SH_PLUGIN_UID );
|
||||
$oCriteria->add( \CaseSchedulerPeer::PRO_UID, $sProcessUID );
|
||||
$oCriteria->add( \CaseSchedulerPeer::SCH_UID, $sCaseSchedulerUID );
|
||||
$oDataset = \CaseSchedulerPeer::doSelectRS( $oCriteria );
|
||||
$oDataset->setFetchmode( \ResultSet::FETCHMODE_ASSOC );
|
||||
$oDataset->next();
|
||||
$aRows = array();
|
||||
while ($aRow = $oDataset->getRow()) {
|
||||
$aRow = array_change_key_case($aRow, CASE_LOWER);
|
||||
$aRows = $aRow;
|
||||
$oDataset->next();
|
||||
}
|
||||
return $aRows;
|
||||
} catch (Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data of unique ids of a Task (Unique id of Process)
|
||||
*
|
||||
* @param string $taskUid Unique id of Task
|
||||
*
|
||||
* return array
|
||||
*/
|
||||
public function getTaskUid($taskUid)
|
||||
{
|
||||
try {
|
||||
$criteria = new \Criteria("workflow");
|
||||
$criteria->addSelectColumn(\TaskPeer::TAS_UID);
|
||||
$criteria->add(\TaskPeer::TAS_UID, $taskUid, \Criteria::EQUAL);
|
||||
$rsCriteria = \TaskPeer::doSelectRS($criteria);
|
||||
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
$rsCriteria->next();
|
||||
return $rsCriteria->getRow();
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the name exists in the case Scheduler
|
||||
*
|
||||
* @param string $processUid Unique id of Process
|
||||
* @param string $name Name
|
||||
*
|
||||
* return bool Return true if the name exists, false otherwise
|
||||
*/
|
||||
public function existsName($processUid, $name)
|
||||
{
|
||||
try {
|
||||
$criteria = new \Criteria("workflow");
|
||||
$criteria->addSelectColumn(\CaseSchedulerPeer::TAS_UID);
|
||||
$criteria->add(\CaseSchedulerPeer::SCH_NAME, $name, \Criteria::EQUAL);
|
||||
$rsCriteria = \CaseSchedulerPeer::doSelectRS($criteria);
|
||||
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
$rsCriteria->next();
|
||||
return $rsCriteria->getRow();
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the name exists in the case Scheduler
|
||||
*
|
||||
* @param string $processUid Unique id of Process
|
||||
* @param string $name Name
|
||||
*
|
||||
* return bool Return true if the name exists, false otherwise
|
||||
*/
|
||||
public function existsNameUpdate($schUid, $name)
|
||||
{
|
||||
try {
|
||||
$criteria = new \Criteria("workflow");
|
||||
$criteria->addSelectColumn(\CaseSchedulerPeer::TAS_UID);
|
||||
$criteria->add(\CaseSchedulerPeer::SCH_NAME, $name, \Criteria::EQUAL);
|
||||
$criteria->add(\CaseSchedulerPeer::SCH_UID, $schUid, \Criteria::NOT_EQUAL);
|
||||
$rsCriteria = \CaseSchedulerPeer::doSelectRS($criteria);
|
||||
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
$rsCriteria->next();
|
||||
return $rsCriteria->getRow();
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the user exists
|
||||
*
|
||||
* @param string $userName Name
|
||||
* @param string $sTaskUID Task
|
||||
*
|
||||
* return message
|
||||
*/
|
||||
public function getUser($userName, $sTaskUID)
|
||||
{
|
||||
try {
|
||||
$sTASKS = $sTaskUID;
|
||||
$sWS_USER = trim( $userName );
|
||||
$oCriteria = new \Criteria( 'workflow' );
|
||||
$oCriteria->addSelectColumn( \UsersPeer::USR_UID );
|
||||
$oCriteria->addSelectColumn( \TaskUserPeer::USR_UID );
|
||||
$oCriteria->addSelectColumn( \TaskUserPeer::TAS_UID );
|
||||
$oCriteria->addSelectColumn( \UsersPeer::USR_USERNAME );
|
||||
$oCriteria->addSelectColumn( \UsersPeer::USR_FIRSTNAME );
|
||||
$oCriteria->addSelectColumn( \UsersPeer::USR_LASTNAME );
|
||||
$oCriteria->addJoin( \TaskUserPeer::USR_UID, \UsersPeer::USR_UID, \Criteria::LEFT_JOIN );
|
||||
$oCriteria->add( \TaskUserPeer::TAS_UID, $sTASKS );
|
||||
$oCriteria->add( \UsersPeer::USR_USERNAME, $sWS_USER );
|
||||
$userIsAssigned = \TaskUserPeer::doCount( $oCriteria );
|
||||
if ($userIsAssigned < 1) {
|
||||
$oCriteria = new \Criteria( 'workflow' );
|
||||
$oCriteria->addSelectColumn( \UsersPeer::USR_UID );
|
||||
$oCriteria->addJoin( \UsersPeer::USR_UID, \GroupUserPeer::USR_UID, \Criteria::LEFT_JOIN );
|
||||
$oCriteria->addJoin( \GroupUserPeer::GRP_UID, \TaskUserPeer::USR_UID, \Criteria::LEFT_JOIN );
|
||||
$oCriteria->add( \TaskUserPeer::TAS_UID, $sTASKS );
|
||||
$oCriteria->add( \UsersPeer::USR_USERNAME, $sWS_USER );
|
||||
$userIsAssigned = \GroupUserPeer::doCount( $oCriteria );
|
||||
if (! ($userIsAssigned >= 1)) {
|
||||
throw (new \Exception( "The User \'" . $sWS_USER . "\' doesn't have the activity \'" . $sTASKS . "\' assigned"));
|
||||
}
|
||||
}
|
||||
$oDataset = \TaskUserPeer::doSelectRS($oCriteria);
|
||||
$oDataset->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
$oDataset->next();
|
||||
while ($aRow = $oDataset->getRow()) {
|
||||
$messageCode = $aRow['USR_UID'];
|
||||
$oDataset->next();
|
||||
}
|
||||
return $messageCode;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new case scheduler of a project
|
||||
* @param string $sProcessUID
|
||||
* @param array $aData
|
||||
* @param string $userUID
|
||||
* @return array
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function addCaseScheduler($sProcessUID, $aData, $userUID)
|
||||
{
|
||||
try {
|
||||
require_once(PATH_TRUNK . "workflow" . PATH_SEP . "engine" . PATH_SEP . "classes" . PATH_SEP . "model" . PATH_SEP . "CaseScheduler.php");
|
||||
$aData['sch_repeat_stop_if_running'] = '0';
|
||||
$aData['case_sh_plugin_uid'] = null;
|
||||
$aData = array_change_key_case($aData, CASE_UPPER);
|
||||
$sOption = $aData['SCH_OPTION'];
|
||||
if (empty($aData)) {
|
||||
die( 'the information sended is empty!' );
|
||||
}
|
||||
$arrayTaskUid = $this->getTaskUid($aData['TAS_UID']);
|
||||
if (empty($arrayTaskUid)) {
|
||||
throw (new \Exception( 'Task not found for id: '. $aData['TAS_UID']));
|
||||
}
|
||||
if ($aData['SCH_NAME']=='') {
|
||||
throw (new \Exception( '\'sch_name\' can\'t be empty'));
|
||||
}
|
||||
if ($this->existsName($sProcessUID, $aData['SCH_NAME'])) {
|
||||
throw (new \Exception( 'Duplicate Case Scheduler name'));
|
||||
}
|
||||
$mUser = $this->getUser($aData['SCH_DEL_USER_NAME'], $aData['TAS_UID']);
|
||||
$oUser = \UsersPeer::retrieveByPK( $mUser );
|
||||
if (is_null($oUser)) {
|
||||
throw (new \Exception($mUser));
|
||||
}
|
||||
$oUserPass = $oUser->getUsrPassword();
|
||||
$aData['SCH_DEL_USER_PASS'] = $oUserPass;
|
||||
if ($sOption != '5') {
|
||||
$pattern="/^([0-1][0-9]|[2][0-3])[\:]([0-5][0-9])$/";
|
||||
if (!preg_match($pattern, $aData['SCH_START_TIME'])) {
|
||||
throw (new \Exception( 'Invalid value specified for \'sch_start_time\'. Expecting time in HH:MM format (The time can not be increased to 23:59)'));
|
||||
}
|
||||
}
|
||||
$patternDate="/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/";
|
||||
if ($sOption == '1' || $sOption == '2' || $sOption == '3') {
|
||||
if (!preg_match($patternDate, $aData['SCH_START_DATE'])) {
|
||||
throw (new \Exception( 'Invalid value specified for \'sch_start_date\'. Expecting date in \'YYYY-MM-DD\' format, such as \'2014-01-01\''));
|
||||
}
|
||||
}
|
||||
if ($sOption == '1' || $sOption == '2' || $sOption == '3') {
|
||||
if (!preg_match($patternDate, $aData['SCH_END_DATE'])) {
|
||||
throw (new \Exception( 'Invalid value specified for \'sch_end_date\'. Expecting date in \'YYYY-MM-DD\' format, such as \'2014-01-01\''));
|
||||
}
|
||||
}
|
||||
if ($sOption == '1' || $sOption == '2' || $sOption == '3') {
|
||||
if ($aData['SCH_START_DATE'] == "") {
|
||||
throw (new \Exception( '\'sch_start_date\' can\'t be null'));
|
||||
}
|
||||
}
|
||||
if ($sOption == '2') {
|
||||
$aData['SCH_EVERY_DAYS'] = 1;
|
||||
} else {
|
||||
$aData['SCH_EVERY_DAYS'] = 0;
|
||||
}
|
||||
$oCaseScheduler = new \CaseScheduler();
|
||||
$aData['SCH_UID'] = \G::generateUniqueID();
|
||||
$aData['PRO_UID'] = $sProcessUID;
|
||||
$aData['SCH_STATE'] = 'ACTIVE';
|
||||
$aData['SCH_LAST_STATE'] = 'CREATED'; // 'ACTIVE';
|
||||
$aData['USR_UID'] = $userUID;
|
||||
$aData['SCH_DEL_USER_UID'] = $aData['USR_UID'];
|
||||
$sTimeTmp = $aData['SCH_START_TIME'];
|
||||
$nActualTime = $aData['SCH_START_TIME']; // time();
|
||||
$sValue = '';
|
||||
$sDaysPerformTask = '';
|
||||
$sWeeks = '';
|
||||
$sMonths = '';
|
||||
$sMonths = '';
|
||||
$sStartDay = '';
|
||||
$nSW = 0;
|
||||
$aData['SCH_DAYS_PERFORM_TASK'] = '';
|
||||
switch ($sOption) {
|
||||
case '1': // If the option is zero, set by default 1
|
||||
$aData['SCH_DAYS_PERFORM_TASK'] = '1';
|
||||
$sValue = $aData['SCH_DAYS_PERFORM_TASK'];
|
||||
switch ($sValue) {
|
||||
case '1':
|
||||
$aData['SCH_DAYS_PERFORM_TASK'] = $aData['SCH_DAYS_PERFORM_TASK'] . '|1';
|
||||
$aData['SCH_MONTHS'] ='0|0|0|0|0|0|0|0|0|0|0|0';
|
||||
$aData['SCH_WEEK_DAYS'] ='0|0|0|0|0|0|0';
|
||||
break;
|
||||
case '2':
|
||||
$aData['SCH_OPTION'] = '2';
|
||||
$aData['SCH_EVERY_DAYS'] = '1'; //check
|
||||
$aData['SCH_WEEK_DAYS'] = '1|2|3|4|5|'; //check
|
||||
break;
|
||||
case '3': // Every [n] Days
|
||||
$sDaysPerformTask = $aData['SCH_DAYS_PERFORM_TASK'];
|
||||
$aData['SCH_DAYS_PERFORM_TASK'] = $aData['SCH_DAYS_PERFORM_TASK'];
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case '2': // If the option is zero, set by default 1
|
||||
if ($aData['SCH_WEEK_DAYS'] == "") {
|
||||
throw (new \Exception( '\'sch_week_days\' can\'t be null'));
|
||||
} else {
|
||||
$weeks = $aData['SCH_WEEK_DAYS'];
|
||||
$weeks = explode("|", $weeks);
|
||||
foreach ($weeks as $row) {
|
||||
if ($row == "1" || $row == "2" || $row == "3" || $row == "4" || $row == "5"|| $row == "6" || $row == "7") {
|
||||
$aData['SCH_WEEK_DAYS'] = $aData['SCH_WEEK_DAYS'];
|
||||
} else {
|
||||
throw (new \Exception( 'Invalid value specified for \'sch_week_days\''));
|
||||
}
|
||||
}
|
||||
}
|
||||
$aData['SCH_MONTHS'] ='0|0|0|0|0|0|0|0|0|0|0|0';
|
||||
if (empty( $aData['SCH_EVERY_DAYS'] )) {
|
||||
$nEveryDays = 1;
|
||||
} else {
|
||||
$nEveryDays = $aData['SCH_EVERY_DAYS'];
|
||||
}
|
||||
$aData['SCH_EVERY_DAYS'] = $nEveryDays;
|
||||
$sWeeks = '';
|
||||
if (! empty( $aData['SCH_WEEK_DAYS'] )) {
|
||||
$aWeekDays = $aData['SCH_WEEK_DAYS'];
|
||||
}
|
||||
$sStartTime = $aData['SCH_START_TIME'];
|
||||
$sWeeks = $aData['SCH_WEEK_DAYS'] . '|';
|
||||
break;
|
||||
case '3':
|
||||
$nStartDay = $aData['SCH_START_DAY'];
|
||||
if ($nStartDay == "") {
|
||||
throw (new \Exception( '\'sch_start_day\' can\'t be null'));
|
||||
}
|
||||
if ($nStartDay == 1) {
|
||||
if ($aData['SCH_START_DAY_OPT_1'] == "") {
|
||||
throw (new \Exception( '\'sch_start_day_opt_1\' can\'t be null'));
|
||||
}
|
||||
$temp = $aData['SCH_START_DAY_OPT_1'];
|
||||
$temp = (int)$temp;
|
||||
if ($temp >= 1 && $temp <= 31) {
|
||||
$aData['SCH_START_DAY_OPT_1'] = $aData['SCH_START_DAY_OPT_1'];
|
||||
} else {
|
||||
throw (new \Exception( 'Invalid value specified for \'sch_start_day_opt_1\'. Must be between 1 and 31'));
|
||||
}
|
||||
$aData['SCH_START_DAY'] = $nStartDay . '|' . $aData['SCH_START_DAY_OPT_1'];
|
||||
} else {
|
||||
if ($aData['SCH_START_DAY_OPT_2'] == "") {
|
||||
throw (new \Exception( '\'sch_start_day_opt_2\' can\'t be null'));
|
||||
}
|
||||
$aData['SCH_START_DAY'] = $nStartDay . '|' . $aData['SCH_START_DAY_OPT_2'];
|
||||
$optionTwo = $aData['SCH_START_DAY_OPT_2']{0};
|
||||
if ($optionTwo == "1" || $optionTwo == "2" || $optionTwo == "3" || $optionTwo == "4" || $optionTwo == "5") {
|
||||
$aData['SCH_START_DAY_OPT_2'] = $aData['SCH_START_DAY_OPT_2'];
|
||||
} else {
|
||||
throw (new \Exception( 'Invalid value specified for \'sch_start_day_opt_2\''));
|
||||
}
|
||||
$pipelineTwo = $aData['SCH_START_DAY_OPT_2']{1};
|
||||
if ($pipelineTwo == "|") {
|
||||
$aData['SCH_START_DAY_OPT_2'] = $aData['SCH_START_DAY_OPT_2'];
|
||||
} else {
|
||||
throw (new \Exception( 'Invalid value specified for \'sch_start_day_opt_2\''));
|
||||
}
|
||||
$dayTwo = $aData['SCH_START_DAY_OPT_2']{2};
|
||||
if ($dayTwo == "1" || $dayTwo == "2" || $dayTwo == "3" || $dayTwo == "4" || $dayTwo == "5" || $dayTwo == "6" || $dayTwo == "7") {
|
||||
$aData['SCH_START_DAY_OPT_2'] = $aData['SCH_START_DAY_OPT_2'];
|
||||
} else {
|
||||
throw (new \Exception( 'Invalid value specified for \'sch_start_day_opt_2\''));
|
||||
}
|
||||
}
|
||||
if ($nStartDay == "") {
|
||||
throw (new \Exception( '\'sch_start_day\' can\'t be null'));
|
||||
}
|
||||
$sMonths = '';
|
||||
if ($aData['SCH_MONTHS'] == "") {
|
||||
throw (new \Exception( '\'sch_months\' can\'t be null'));
|
||||
}
|
||||
if (! empty( $aData['SCH_MONTHS'] )) {
|
||||
$aMonths = $aData['SCH_MONTHS'];
|
||||
$aMonths = explode("|", $aMonths);
|
||||
foreach ($aMonths as $row) {
|
||||
if ($row == "1" || $row == "2" || $row == "3" || $row == "4" || $row == "5"|| $row == "6" || $row == "7"|| $row == "8" || $row == "9" || $row == "10"|| $row == "11" || $row == "12") {
|
||||
$aData['SCH_MONTHS'] = $aData['SCH_MONTHS'];
|
||||
} else {
|
||||
throw (new \Exception( 'Invalid value specified for \'sch_months\''));
|
||||
}
|
||||
}
|
||||
}
|
||||
$sMonths = $aData['SCH_MONTHS'];
|
||||
$sStartDay = $aData['SCH_START_DAY'];
|
||||
$sValue = $nStartDay;
|
||||
break;
|
||||
}
|
||||
if (($sOption != '1') && ($sOption != '4') && ($sOption != '5')) {
|
||||
$sDateTmp = '';
|
||||
if ($sStartDay == '') {
|
||||
$sStartDay = date('Y-m-d');
|
||||
} else {
|
||||
$size = strlen($aData['SCH_START_DAY']);
|
||||
if ($size > 4) {
|
||||
$aaStartDay = explode( "|", $aData['SCH_START_DAY'] );
|
||||
$aaStartDay[0] = $aaStartDay[0];
|
||||
$aaStartDay[1] = $aaStartDay[1];
|
||||
$aaStartDay[2]= ($aaStartDay[2] == 7 ? 1 : $aaStartDay[2]);
|
||||
$sStartDay = $aaStartDay[0].'|'.$aaStartDay[1].'|'.$aaStartDay[2];
|
||||
}
|
||||
}
|
||||
$dCurrentDay = date("d");
|
||||
$dCurrentMonth = date("m");
|
||||
$aStartDay = explode( "|", $aData['SCH_START_DAY'] );
|
||||
if ($sOption == '3' && $aStartDay[0] == '1') {
|
||||
$monthsArray = explode( "|", $sMonths );
|
||||
foreach ($monthsArray as $row) {
|
||||
if ($dCurrentMonth == $row && $dCurrentDay < $aStartDay[1]) {
|
||||
$startTime = $aData['SCH_START_TIME'] . ":00";
|
||||
$aData['SCH_TIME_NEXT_RUN'] = date('Y') . '-' . $row . '-' . $aStartDay[1] . ' ' . $startTime;
|
||||
break;
|
||||
} else {
|
||||
$aData['SCH_TIME_NEXT_RUN'] = $oCaseScheduler->updateNextRun( $sOption, $sValue, $nActualTime, $sDaysPerformTask, $sWeeks, $sStartDay, $sMonths, $sDateTmp );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$aData['SCH_TIME_NEXT_RUN'] = $oCaseScheduler->updateNextRun( $sOption, $sValue, $nActualTime, $sDaysPerformTask, $sWeeks, $sStartDay, $sMonths, $sDateTmp );
|
||||
}
|
||||
} else {
|
||||
if ($sOption == '4') {
|
||||
$sDateTmp = date('Y-m-d');
|
||||
$aData['SCH_START_TIME'] = date('Y-m-d', strtotime( $sDateTmp )) . ' ' . date('H:i:s', strtotime( $sTimeTmp ));
|
||||
$aData['SCH_START_DATE'] = $aData['SCH_START_TIME'];
|
||||
$aData['SCH_END_DATE'] = $aData['SCH_START_TIME'];
|
||||
}
|
||||
$aData['SCH_TIME_NEXT_RUN'] = $aData['SCH_START_TIME'];
|
||||
if ($sOption == '5') {
|
||||
if ($aData['SCH_START_DATE'] != '') {
|
||||
$sDateTmp = $aData['SCH_START_DATE'];
|
||||
} else {
|
||||
$sDateTmp = date('Y-m-d');
|
||||
$aData['SCH_START_DATE'] = $sDateTmp;
|
||||
}
|
||||
$aData['SCH_END_DATE'] = date('Y-m-d', strtotime( $sDateTmp )) . ' ' . date('H:i:s', strtotime( $sTimeTmp ));
|
||||
$aData['SCH_START_TIME'] = time();
|
||||
$aData['SCH_START_DATE'] = $aData['SCH_START_TIME'];
|
||||
if ($aData['SCH_REPEAT_EVERY'] == "") {
|
||||
throw (new \Exception( '\'sch_repeat_every\' can\'t be null'));
|
||||
}
|
||||
$patternHour="/^([0-1][0-9]|[2][0-3])[\.]([0-5][0-9])$/";
|
||||
if (!preg_match($patternHour, $aData['SCH_REPEAT_EVERY'])) {
|
||||
throw (new \Exception( 'Invalid value specified for \'sch_repeat_every\'. Expecting time in HH.MM format'));
|
||||
}
|
||||
$nextRun = $aData['SCH_REPEAT_EVERY'] * 60 * 60;
|
||||
$aData['SCH_REPEAT_EVERY'] = $aData['SCH_REPEAT_EVERY'];
|
||||
$date = $aData['SCH_START_TIME'];
|
||||
$date += $nextRun;
|
||||
$date = date("Y-m-d H:i", $date);
|
||||
$aData['SCH_TIME_NEXT_RUN'] = $date;
|
||||
}
|
||||
}
|
||||
if (trim( $aData['SCH_END_DATE'] ) != '') {
|
||||
$aData['SCH_END_DATE'] = $aData['SCH_END_DATE'];
|
||||
}
|
||||
if (! empty( $aData['SCH_REPEAT_TASK_CHK'] )) {
|
||||
$nOptEvery = $aData['SCH_REPEAT_EVERY_OPT'];
|
||||
if ($nOptEvery == 2) {
|
||||
$aData['SCH_REPEAT_EVERY'] = $aData['SCH_REPEAT_EVERY'] * 60;
|
||||
} else {
|
||||
$aData['SCH_REPEAT_EVERY'] = $aData['SCH_REPEAT_EVERY'];
|
||||
}
|
||||
}
|
||||
if ((isset( $aData['CASE_SH_PLUGIN_UID'] )) && ($aData['CASE_SH_PLUGIN_UID'] != "")) {
|
||||
$aData['CASE_SH_PLUGIN_UID'] = $aData['CASE_SH_PLUGIN_UID'];
|
||||
}
|
||||
// check this data
|
||||
$aData['SCH_REPEAT_UNTIL'] = '';
|
||||
$aData['SCH_REPEAT_STOP_IF_RUNNING'] = '0';
|
||||
$aData['CASE_SH_PLUGIN_UID'] = null;
|
||||
//
|
||||
$oCaseScheduler->create( $aData );
|
||||
$oCriteria = $this->getCaseScheduler($sProcessUID, $aData['SCH_UID']);
|
||||
return $oCriteria;
|
||||
} catch (Exception $oException) {
|
||||
die( $oException->getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update case scheduler for a project
|
||||
* @param string $sProcessUID
|
||||
* @param array $aData
|
||||
* @param string $userUID
|
||||
* @param string $sSchUID
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function updateCaseScheduler($sProcessUID, $aData, $userUID, $sSchUID = '')
|
||||
{
|
||||
try {
|
||||
require_once(PATH_TRUNK . "workflow" . PATH_SEP . "engine" . PATH_SEP . "classes" . PATH_SEP . "model" . PATH_SEP . "CaseScheduler.php");
|
||||
$aData = array_change_key_case($aData, CASE_UPPER);
|
||||
if (empty( $aData )) {
|
||||
die( 'The information sended is empty!' );
|
||||
}
|
||||
$oCaseScheduler = new \CaseScheduler();
|
||||
$aFields = $oCaseScheduler->Load($sSchUID);
|
||||
$sOption = $aFields['SCH_OPTION'];
|
||||
$aData['SCH_OPTION'] = $sOption;
|
||||
$aData['sch_repeat_stop_if_running'] = '0';
|
||||
$aData['case_sh_plugin_uid'] = null;
|
||||
$aData = array_change_key_case($aData, CASE_UPPER);
|
||||
if (empty($aData)) {
|
||||
die( 'the information sended is empty!' );
|
||||
}
|
||||
$arrayTaskUid = $this->getTaskUid($aData['TAS_UID']);
|
||||
if (empty($arrayTaskUid)) {
|
||||
throw (new \Exception( 'Task not found for id: '. $aData['TAS_UID']));
|
||||
}
|
||||
if ($aData['SCH_NAME']=='') {
|
||||
throw (new \Exception( '\'sch_name\' can\'t be empty'));
|
||||
}
|
||||
if ($this->existsNameUpdate($sSchUID, $aData['SCH_NAME'])) {
|
||||
throw (new \Exception( 'Duplicate Case Scheduler name'));
|
||||
}
|
||||
$mUser = $this->getUser($aData['SCH_DEL_USER_NAME'], $aData['TAS_UID']);
|
||||
$oUser = \UsersPeer::retrieveByPK( $mUser );
|
||||
if (is_null($oUser)) {
|
||||
throw (new \Exception($mUser));
|
||||
}
|
||||
$oUserPass = $oUser->getUsrPassword();
|
||||
$aData['SCH_DEL_USER_PASS'] = $oUserPass;
|
||||
if ($sOption != '5') {
|
||||
$pattern="/^([0-1][0-9]|[2][0-3])[\:]([0-5][0-9])$/";
|
||||
if (!preg_match($pattern, $aData['SCH_START_TIME'])) {
|
||||
throw (new \Exception( 'Invalid value specified for \'sch_start_time\'. Expecting time in HH:MM format (The time can not be increased to 23:59)'));
|
||||
}
|
||||
}
|
||||
$patternDate="/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/";
|
||||
if ($sOption == '1' || $sOption == '2' || $sOption == '3') {
|
||||
if (!preg_match($patternDate, $aData['SCH_START_DATE'])) {
|
||||
throw (new \Exception( 'Invalid value specified for \'sch_start_date\'. Expecting date in \'YYYY-MM-DD\' format, such as \'2014-01-01\''));
|
||||
}
|
||||
}
|
||||
if ($sOption == '1' || $sOption == '2' || $sOption == '3') {
|
||||
if (!preg_match($patternDate, $aData['SCH_END_DATE'])) {
|
||||
throw (new \Exception( 'Invalid value specified for \'sch_end_date\'. Expecting date in \'YYYY-MM-DD\' format, such as \'2014-01-01\''));
|
||||
}
|
||||
}
|
||||
if ($sOption == '1' || $sOption == '2' || $sOption == '3') {
|
||||
if ($aData['SCH_START_DATE'] == "") {
|
||||
throw (new \Exception( '\'sch_start_date\' can\'t be null'));
|
||||
}
|
||||
}
|
||||
if ($sOption == '2') {
|
||||
$aData['SCH_EVERY_DAYS'] = 1;
|
||||
} else {
|
||||
$aData['SCH_EVERY_DAYS'] = 0;
|
||||
}
|
||||
$oCaseScheduler = new \CaseScheduler();
|
||||
$aData['SCH_UID'] = $sSchUID;
|
||||
$aData['PRO_UID'] = $sProcessUID;
|
||||
if ($aData['SCH_STATE'] == "" || $aData['SCH_STATE'] == null) {
|
||||
throw (new \Exception( '\'sch_state\' can\'t be null'));
|
||||
} else {
|
||||
if ($aData['SCH_STATE'] == 'ACTIVE') {
|
||||
$aData['SCH_LAST_STATE'] = 'CREATED';
|
||||
} else {
|
||||
$aData['SCH_LAST_STATE'] = 'ACTIVE';
|
||||
}
|
||||
}
|
||||
$aData['USR_UID'] = $userUID;
|
||||
$aData['SCH_DEL_USER_UID'] = $aData['USR_UID'];
|
||||
$sTimeTmp = $aData['SCH_START_TIME'];
|
||||
$nActualTime = $aData['SCH_START_TIME']; // time();
|
||||
$sValue = '';
|
||||
$sDaysPerformTask = '';
|
||||
$sWeeks = '';
|
||||
$sMonths = '';
|
||||
$sMonths = '';
|
||||
$sStartDay = '';
|
||||
$nSW = 0;
|
||||
$aData['SCH_DAYS_PERFORM_TASK'] = '';
|
||||
switch ($sOption) {
|
||||
case '1': // If the option is zero, set by default 1
|
||||
$aData['SCH_DAYS_PERFORM_TASK'] = '1';
|
||||
$sValue = $aData['SCH_DAYS_PERFORM_TASK'];
|
||||
switch ($sValue) {
|
||||
case '1':
|
||||
$aData['SCH_DAYS_PERFORM_TASK'] = $aData['SCH_DAYS_PERFORM_TASK'] . '|1';
|
||||
$aData['SCH_MONTHS'] ='0|0|0|0|0|0|0|0|0|0|0|0';
|
||||
$aData['SCH_WEEK_DAYS'] ='0|0|0|0|0|0|0';
|
||||
break;
|
||||
case '2':
|
||||
$aData['SCH_OPTION'] = '2';
|
||||
$aData['SCH_EVERY_DAYS'] = '1'; //check
|
||||
$aData['SCH_WEEK_DAYS'] = '1|2|3|4|5|'; //check
|
||||
break;
|
||||
case '3': // Every [n] Days
|
||||
$sDaysPerformTask = $aData['SCH_DAYS_PERFORM_TASK'];
|
||||
$aData['SCH_DAYS_PERFORM_TASK'] = $aData['SCH_DAYS_PERFORM_TASK'];
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case '2': // If the option is zero, set by default 1
|
||||
if ($aData['SCH_WEEK_DAYS'] == "") {
|
||||
throw (new \Exception( '\'sch_week_days\' can\'t be null'));
|
||||
} else {
|
||||
$weeks = $aData['SCH_WEEK_DAYS'];
|
||||
$weeks = explode("|", $weeks);
|
||||
foreach ($weeks as $row) {
|
||||
if ($row == "1" || $row == "2" || $row == "3" || $row == "4" || $row == "5"|| $row == "6" || $row == "7") {
|
||||
$aData['SCH_WEEK_DAYS'] = $aData['SCH_WEEK_DAYS'];
|
||||
} else {
|
||||
throw (new \Exception( 'Invalid value specified for \'sch_week_days\''));
|
||||
}
|
||||
}
|
||||
}
|
||||
$aData['SCH_MONTHS'] ='0|0|0|0|0|0|0|0|0|0|0|0';
|
||||
if (empty( $aData['SCH_EVERY_DAYS'] )) {
|
||||
$nEveryDays = 1;
|
||||
} else {
|
||||
$nEveryDays = $aData['SCH_EVERY_DAYS'];
|
||||
}
|
||||
$aData['SCH_EVERY_DAYS'] = $nEveryDays;
|
||||
$sWeeks = '';
|
||||
if (! empty( $aData['SCH_WEEK_DAYS'] )) {
|
||||
$aWeekDays = $aData['SCH_WEEK_DAYS'];
|
||||
}
|
||||
$sStartTime = $aData['SCH_START_TIME'];
|
||||
$sWeeks = $aData['SCH_WEEK_DAYS'] . '|';
|
||||
break;
|
||||
case '3':
|
||||
$nStartDay = $aData['SCH_START_DAY'];
|
||||
if ($nStartDay == "") {
|
||||
throw (new \Exception( '\'sch_start_day\' can\'t be null'));
|
||||
}
|
||||
if ($nStartDay == 1) {
|
||||
if ($aData['SCH_START_DAY_OPT_1'] == "") {
|
||||
throw (new \Exception( '\'sch_start_day_opt_1\' can\'t be null'));
|
||||
}
|
||||
$temp = $aData['SCH_START_DAY_OPT_1'];
|
||||
$temp = (int)$temp;
|
||||
if ($temp >= 1 && $temp <= 31) {
|
||||
$aData['SCH_START_DAY_OPT_1'] = $aData['SCH_START_DAY_OPT_1'];
|
||||
} else {
|
||||
throw (new \Exception( 'Invalid value specified for \'sch_start_day_opt_1\'. Must be between 1 and 31'));
|
||||
}
|
||||
$aData['SCH_START_DAY'] = $nStartDay . '|' . $aData['SCH_START_DAY_OPT_1'];
|
||||
} else {
|
||||
if ($aData['SCH_START_DAY_OPT_2'] == "") {
|
||||
throw (new \Exception( '\'sch_start_day_opt_2\' can\'t be null'));
|
||||
}
|
||||
$aData['SCH_START_DAY'] = $nStartDay . '|' . $aData['SCH_START_DAY_OPT_2'];
|
||||
$optionTwo = $aData['SCH_START_DAY_OPT_2']{0};
|
||||
if ($optionTwo == "1" || $optionTwo == "2" || $optionTwo == "3" || $optionTwo == "4" || $optionTwo == "5") {
|
||||
$aData['SCH_START_DAY_OPT_2'] = $aData['SCH_START_DAY_OPT_2'];
|
||||
} else {
|
||||
throw (new \Exception( 'Invalid value specified for \'sch_start_day_opt_2\''));
|
||||
}
|
||||
$pipelineTwo = $aData['SCH_START_DAY_OPT_2']{1};
|
||||
if ($pipelineTwo == "|") {
|
||||
$aData['SCH_START_DAY_OPT_2'] = $aData['SCH_START_DAY_OPT_2'];
|
||||
} else {
|
||||
throw (new \Exception( 'Invalid value specified for \'sch_start_day_opt_2\''));
|
||||
}
|
||||
$dayTwo = $aData['SCH_START_DAY_OPT_2']{2};
|
||||
if ($dayTwo == "1" || $dayTwo == "2" || $dayTwo == "3" || $dayTwo == "4" || $dayTwo == "5" || $dayTwo == "6" || $dayTwo == "7") {
|
||||
$aData['SCH_START_DAY_OPT_2'] = $aData['SCH_START_DAY_OPT_2'];
|
||||
} else {
|
||||
throw (new \Exception( 'Invalid value specified for \'sch_start_day_opt_2\''));
|
||||
}
|
||||
}
|
||||
if ($nStartDay == "") {
|
||||
throw (new \Exception( '\'sch_start_day\' can\'t be null'));
|
||||
}
|
||||
$sMonths = '';
|
||||
if ($aData['SCH_MONTHS'] == "") {
|
||||
throw (new \Exception( '\'sch_months\' can\'t be null'));
|
||||
}
|
||||
if (! empty( $aData['SCH_MONTHS'] )) {
|
||||
$aMonths = $aData['SCH_MONTHS'];
|
||||
$aMonths = explode("|", $aMonths);
|
||||
foreach ($aMonths as $row) {
|
||||
if ($row == "1" || $row == "2" || $row == "3" || $row == "4" || $row == "5"|| $row == "6" || $row == "7"|| $row == "8" || $row == "9" || $row == "10"|| $row == "11" || $row == "12") {
|
||||
$aData['SCH_MONTHS'] = $aData['SCH_MONTHS'];
|
||||
} else {
|
||||
throw (new \Exception( 'Invalid value specified for \'sch_months\''));
|
||||
}
|
||||
}
|
||||
}
|
||||
$sMonths = $aData['SCH_MONTHS'];
|
||||
$sStartDay = $aData['SCH_START_DAY'];
|
||||
$sValue = $nStartDay;
|
||||
break;
|
||||
}
|
||||
if (($sOption != '1') && ($sOption != '4') && ($sOption != '5')) {
|
||||
if ($sStartDay == '') {
|
||||
$sStartDay = date('Y-m-d');
|
||||
} else {
|
||||
$size = strlen($aData['SCH_START_DAY']);
|
||||
if ($size > 4) {
|
||||
$aaStartDay = explode( "|", $aData['SCH_START_DAY'] );
|
||||
$aaStartDay[0] = $aaStartDay[0];
|
||||
$aaStartDay[1] = $aaStartDay[1];
|
||||
$aaStartDay[2]= ($aaStartDay[2] == 7 ? 1 : $aaStartDay[2]);
|
||||
$sStartDay = $aaStartDay[0].'|'.$aaStartDay[1].'|'.$aaStartDay[2];
|
||||
}
|
||||
}
|
||||
$dCurrentDay = date("d");
|
||||
$dCurrentMonth = date("m");
|
||||
$aStartDay = explode( "|", $aData['SCH_START_DAY'] );
|
||||
$sDateTmp = '';
|
||||
if ($sOption == '3' && $aStartDay[0] == '1') {
|
||||
$monthsArray = explode( "|", $sMonths );
|
||||
foreach ($monthsArray as $row) {
|
||||
if ($dCurrentMonth == $row && $dCurrentDay < $aStartDay[1]) {
|
||||
$startTime = $aData['SCH_START_TIME'] . ":00";
|
||||
$aData['SCH_TIME_NEXT_RUN'] = date('Y') . '-' . $row . '-' . $aStartDay[1] . ' ' . $startTime;
|
||||
break;
|
||||
} else {
|
||||
$aData['SCH_TIME_NEXT_RUN'] = $oCaseScheduler->updateNextRun( $sOption, $sValue, $nActualTime, $sDaysPerformTask, $sWeeks, $sStartDay, $sMonths, $sDateTmp );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$aData['SCH_TIME_NEXT_RUN'] = $oCaseScheduler->updateNextRun( $sOption, $sValue, $nActualTime, $sDaysPerformTask, $sWeeks, $sStartDay, $sMonths, $sDateTmp );
|
||||
}
|
||||
} else {
|
||||
if ($sOption == '4') {
|
||||
$sDateTmp = date('Y-m-d');
|
||||
$aData['SCH_START_TIME'] = date('Y-m-d', strtotime( $sDateTmp )) . ' ' . date('H:i:s', strtotime( $sTimeTmp ));
|
||||
$aData['SCH_START_DATE'] = $aData['SCH_START_TIME'];
|
||||
$aData['SCH_END_DATE'] = $aData['SCH_START_TIME'];
|
||||
}
|
||||
$aData['SCH_TIME_NEXT_RUN'] = $aData['SCH_START_TIME'];
|
||||
if ($sOption == '5') {
|
||||
if ($aData['SCH_START_DATE'] != '') {
|
||||
$sDateTmp = $aData['SCH_START_DATE'];
|
||||
} else {
|
||||
$sDateTmp = date('Y-m-d');
|
||||
$aData['SCH_START_DATE'] = $sDateTmp;
|
||||
}
|
||||
$aData['SCH_END_DATE'] = date('Y-m-d', strtotime($sDateTmp)) . ' ' . date('H:i:s', strtotime($sTimeTmp));
|
||||
$aData['SCH_START_TIME'] = time();
|
||||
$aData['SCH_START_DATE'] = $aData['SCH_START_TIME'];
|
||||
if ($aData['SCH_REPEAT_EVERY'] == "") {
|
||||
throw (new \Exception( '\'sch_repeat_every\' can\'t be null'));
|
||||
}
|
||||
$patternHour="/^([0-1][0-9]|[2][0-3])[\.]([0-5][0-9])$/";
|
||||
if (!preg_match($patternHour, $aData['SCH_REPEAT_EVERY'])) {
|
||||
throw (new \Exception( 'Invalid value specified for \'sch_repeat_every\'. Expecting time in HH.MM format'));
|
||||
}
|
||||
$nextRun = $aData['SCH_REPEAT_EVERY'] * 60 * 60;
|
||||
$aData['SCH_REPEAT_EVERY'] = $aData['SCH_REPEAT_EVERY'];
|
||||
$date = $aData['SCH_START_TIME'];
|
||||
$date += $nextRun;
|
||||
$date = date("Y-m-d H:i", $date);
|
||||
$aData['SCH_TIME_NEXT_RUN'] = $date;
|
||||
}
|
||||
}
|
||||
if (trim( $aData['SCH_END_DATE'] ) != '') {
|
||||
$aData['SCH_END_DATE'] = $aData['SCH_END_DATE'];
|
||||
}
|
||||
if (! empty( $aData['SCH_REPEAT_TASK_CHK'] )) {
|
||||
$nOptEvery = $aData['SCH_REPEAT_EVERY_OPT'];
|
||||
if ($nOptEvery == 2) {
|
||||
$aData['SCH_REPEAT_EVERY'] = $aData['SCH_REPEAT_EVERY'] * 60;
|
||||
} else {
|
||||
$aData['SCH_REPEAT_EVERY'] = $aData['SCH_REPEAT_EVERY'];
|
||||
}
|
||||
}
|
||||
if ((isset( $aData['CASE_SH_PLUGIN_UID'] )) && ($aData['CASE_SH_PLUGIN_UID'] != "")) {
|
||||
$aData['CASE_SH_PLUGIN_UID'] = $aData['CASE_SH_PLUGIN_UID'];
|
||||
}
|
||||
// check this data
|
||||
$aData['SCH_REPEAT_UNTIL'] = '';
|
||||
$aData['SCH_REPEAT_STOP_IF_RUNNING'] = '0';
|
||||
$aData['CASE_SH_PLUGIN_UID'] = null;
|
||||
//
|
||||
$oCaseScheduler->Update($aData);
|
||||
$oCriteria = $this->getCaseScheduler($sProcessUID, $sSchUID);
|
||||
return $oCriteria;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a case scheduler of a project
|
||||
*
|
||||
* @param string $sSchUID
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function deleteCaseScheduler($sSchUID)
|
||||
{
|
||||
try {
|
||||
require_once(PATH_TRUNK . "workflow" . PATH_SEP . "engine" . PATH_SEP . "classes" . PATH_SEP . "model" . PATH_SEP . "CaseScheduler.php");
|
||||
$oCaseScheduler = new \CaseScheduler();
|
||||
if (!isset($sSchUID)) {
|
||||
return;
|
||||
}
|
||||
$oCaseScheduler->remove($sSchUID);
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
382
workflow/engine/src/ProcessMaker/BusinessModel/CaseTracker.php
Normal file
382
workflow/engine/src/ProcessMaker/BusinessModel/CaseTracker.php
Normal file
@@ -0,0 +1,382 @@
|
||||
<?php
|
||||
namespace ProcessMaker\BusinessModel;
|
||||
|
||||
class CaseTracker
|
||||
{
|
||||
/**
|
||||
* Update Case Tracker data of a Process
|
||||
*
|
||||
* @param string $processUid Unique id of Process
|
||||
* @param array $arrayData Data
|
||||
*
|
||||
* return array Return data of the Case Tracker updated
|
||||
*/
|
||||
public function update($processUid, $arrayData)
|
||||
{
|
||||
try {
|
||||
$arrayDataIni = $arrayData;
|
||||
|
||||
//Verify data
|
||||
$process = new \Process();
|
||||
|
||||
if (!$process->exists($processUid)) {
|
||||
throw (new \Exception(str_replace(array("{0}", "{1}"), array($processUid, "PROCESS"), "The UID \"{0}\" does not exist in table {1}")));
|
||||
}
|
||||
|
||||
//Update
|
||||
$caseTracker = new \CaseTracker();
|
||||
|
||||
$arrayData = array("PRO_UID" => $processUid);
|
||||
|
||||
if (isset($arrayDataIni["map_type"])) {
|
||||
$arrayData["CT_MAP_TYPE"] = $arrayDataIni["map_type"];
|
||||
}
|
||||
|
||||
if (isset($arrayDataIni["routing_history"])) {
|
||||
$arrayData["CT_DERIVATION_HISTORY"] = (int)($arrayDataIni["routing_history"]);
|
||||
}
|
||||
|
||||
if (isset($arrayDataIni["message_history"])) {
|
||||
$arrayData["CT_MESSAGE_HISTORY"] = (int)($arrayDataIni["message_history"]);
|
||||
}
|
||||
|
||||
$result = $caseTracker->update($arrayData);
|
||||
|
||||
$arrayData = $arrayDataIni;
|
||||
|
||||
//Return
|
||||
return $arrayData;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Case Tracker data of a Process
|
||||
*
|
||||
* @param string $processUid Unique id of Process
|
||||
*
|
||||
* return array Return an array with data of Case Tracker of a Process
|
||||
*/
|
||||
public function getCaseTracker($processUid)
|
||||
{
|
||||
try {
|
||||
$arrayCaseTracker = array();
|
||||
|
||||
//Verify data
|
||||
$process = new \Process();
|
||||
|
||||
if (!$process->exists($processUid)) {
|
||||
throw (new \Exception(str_replace(array("{0}", "{1}"), array($processUid, "PROCESS"), "The UID \"{0}\" does not exist in table {1}")));
|
||||
}
|
||||
|
||||
//Get data
|
||||
$criteria = new \Criteria();
|
||||
|
||||
$criteria->add(\CaseTrackerPeer::PRO_UID, $processUid, \Criteria::EQUAL);
|
||||
|
||||
$rsCriteria = \CaseTrackerPeer::doSelectRS($criteria);
|
||||
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
|
||||
if ($rsCriteria->next()) {
|
||||
$row = $rsCriteria->getRow();
|
||||
|
||||
$arrayCaseTracker = $row;
|
||||
} else {
|
||||
$caseTracker = new \CaseTracker();
|
||||
|
||||
$arrayCaseTracker = array(
|
||||
"PRO_UID" => $processUid,
|
||||
"CT_MAP_TYPE" => "PROCESSMAP",
|
||||
"CT_DERIVATION_HISTORY" => 1,
|
||||
"CT_MESSAGE_HISTORY" => 1
|
||||
);
|
||||
|
||||
$caseTracker->create($arrayCaseTracker);
|
||||
}
|
||||
|
||||
return array(
|
||||
"map_type" => $arrayCaseTracker["CT_MAP_TYPE"],
|
||||
"routing_history" => (int)($arrayCaseTracker["CT_DERIVATION_HISTORY"]),
|
||||
"message_history" => (int)($arrayCaseTracker["CT_MESSAGE_HISTORY"])
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get available Case Tracker Objects of a Process
|
||||
*
|
||||
* @param string $processUid Unique id of Process
|
||||
*
|
||||
* return array Return an array with the Case Tracker Objects available of a Process
|
||||
*/
|
||||
public function getAvailableCaseTrackerObjects($processUid)
|
||||
{
|
||||
try {
|
||||
$arrayAvailableCaseTrackerObject = array();
|
||||
|
||||
//Verify data
|
||||
$process = new \Process();
|
||||
|
||||
if (!$process->exists($processUid)) {
|
||||
throw (new \Exception(str_replace(array("{0}", "{1}"), array($processUid, "PROCESS"), "The UID \"{0}\" does not exist in table {1}")));
|
||||
}
|
||||
|
||||
//Get Uids
|
||||
$arrayDynaFormUid = array();
|
||||
$arrayInputDocumentUid = array();
|
||||
$arrayOutputDocumentUid = array();
|
||||
|
||||
$criteria = new \Criteria("workflow");
|
||||
|
||||
$criteria->add(\CaseTrackerObjectPeer::PRO_UID, $processUid, \Criteria::EQUAL);
|
||||
|
||||
$rsCriteria = \CaseTrackerObjectPeer::doSelectRS($criteria);
|
||||
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
|
||||
while ($rsCriteria->next()) {
|
||||
$row = $rsCriteria->getRow();
|
||||
|
||||
switch ($row["CTO_TYPE_OBJ"]) {
|
||||
case "DYNAFORM":
|
||||
$arrayDynaFormUid[] = $row["CTO_UID_OBJ"];
|
||||
break;
|
||||
case "INPUT_DOCUMENT":
|
||||
$arrayInputDocumentUid[] = $row["CTO_UID_OBJ"];
|
||||
break;
|
||||
case "OUTPUT_DOCUMENT":
|
||||
$arrayOutputDocumentUid[] = $row["CTO_UID_OBJ"];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//Array DB
|
||||
$arrayCaseTrackerObject = array();
|
||||
|
||||
$delimiter = \DBAdapter::getStringDelimiter();
|
||||
|
||||
//DynaForms
|
||||
$criteria = new \Criteria("workflow");
|
||||
|
||||
$criteria->addSelectColumn(\DynaformPeer::DYN_UID);
|
||||
$criteria->addAsColumn("DYN_TITLE", "CT.CON_VALUE");
|
||||
$criteria->addAsColumn("DYN_DESCRIPTION", "CD.CON_VALUE");
|
||||
|
||||
$criteria->addAlias("CT", \ContentPeer::TABLE_NAME);
|
||||
$criteria->addAlias("CD", \ContentPeer::TABLE_NAME);
|
||||
|
||||
$arrayCondition = array();
|
||||
$arrayCondition[] = array(\DynaformPeer::DYN_UID, "CT.CON_ID", \Criteria::EQUAL);
|
||||
$arrayCondition[] = array("CT.CON_CATEGORY", $delimiter . "DYN_TITLE" . $delimiter, \Criteria::EQUAL);
|
||||
$arrayCondition[] = array("CT.CON_LANG", $delimiter . SYS_LANG . $delimiter, \Criteria::EQUAL);
|
||||
$criteria->addJoinMC($arrayCondition, \Criteria::LEFT_JOIN);
|
||||
|
||||
$arrayCondition = array();
|
||||
$arrayCondition[] = array(\DynaformPeer::DYN_UID, "CD.CON_ID", \Criteria::EQUAL);
|
||||
$arrayCondition[] = array("CD.CON_CATEGORY", $delimiter . "DYN_DESCRIPTION" . $delimiter, \Criteria::EQUAL);
|
||||
$arrayCondition[] = array("CD.CON_LANG", $delimiter . SYS_LANG . $delimiter, \Criteria::EQUAL);
|
||||
$criteria->addJoinMC($arrayCondition, \Criteria::LEFT_JOIN);
|
||||
|
||||
$criteria->add(\DynaformPeer::PRO_UID, $processUid, \Criteria::EQUAL);
|
||||
$criteria->add(\DynaformPeer::DYN_UID, $arrayDynaFormUid, \Criteria::NOT_IN);
|
||||
$criteria->add(\DynaformPeer::DYN_TYPE, "xmlform", \Criteria::EQUAL);
|
||||
|
||||
$rsCriteria = \DynaformPeer::doSelectRS($criteria);
|
||||
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
|
||||
while ($rsCriteria->next()) {
|
||||
$row = $rsCriteria->getRow();
|
||||
|
||||
if ($row["DYN_TITLE"] . "" == "") {
|
||||
//There is no transaltion for this Document name, try to get/regenerate the label
|
||||
$row["DYN_TITLE"] = \Content::Load("DYN_TITLE", "", $row["DYN_UID"], SYS_LANG);
|
||||
}
|
||||
|
||||
$arrayCaseTrackerObject[] = array(
|
||||
"obj_uid" => $row["DYN_UID"],
|
||||
"obj_title" => $row["DYN_TITLE"],
|
||||
"obj_description" => $row["DYN_DESCRIPTION"],
|
||||
"obj_type" => "DYNAFORM"
|
||||
);
|
||||
}
|
||||
|
||||
//InputDocuments
|
||||
$criteria = new \Criteria("workflow");
|
||||
|
||||
$criteria->addSelectColumn(\InputDocumentPeer::INP_DOC_UID);
|
||||
$criteria->addAsColumn("INP_DOC_TITLE", "CT.CON_VALUE");
|
||||
$criteria->addAsColumn("INP_DOC_DESCRIPTION", "CD.CON_VALUE");
|
||||
|
||||
$criteria->addAlias("CT", \ContentPeer::TABLE_NAME);
|
||||
$criteria->addAlias("CD", \ContentPeer::TABLE_NAME);
|
||||
|
||||
$arrayCondition = array();
|
||||
$arrayCondition[] = array(\InputDocumentPeer::INP_DOC_UID, "CT.CON_ID", \Criteria::EQUAL);
|
||||
$arrayCondition[] = array("CT.CON_CATEGORY", $delimiter . "INP_DOC_TITLE" . $delimiter, \Criteria::EQUAL);
|
||||
$arrayCondition[] = array("CT.CON_LANG", $delimiter . SYS_LANG . $delimiter, \Criteria::EQUAL);
|
||||
$criteria->addJoinMC($arrayCondition, \Criteria::LEFT_JOIN);
|
||||
|
||||
$arrayCondition = array();
|
||||
$arrayCondition[] = array(\InputDocumentPeer::INP_DOC_UID, "CD.CON_ID", \Criteria::EQUAL);
|
||||
$arrayCondition[] = array("CD.CON_CATEGORY", $delimiter . "INP_DOC_DESCRIPTION" . $delimiter, \Criteria::EQUAL);
|
||||
$arrayCondition[] = array("CD.CON_LANG", $delimiter . SYS_LANG . $delimiter, \Criteria::EQUAL);
|
||||
$criteria->addJoinMC($arrayCondition, \Criteria::LEFT_JOIN);
|
||||
|
||||
$criteria->add(\InputDocumentPeer::PRO_UID, $processUid, \Criteria::EQUAL);
|
||||
$criteria->add(\InputDocumentPeer::INP_DOC_UID, $arrayInputDocumentUid, \Criteria::NOT_IN);
|
||||
|
||||
$rsCriteria = \InputDocumentPeer::doSelectRS($criteria);
|
||||
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
|
||||
while ($rsCriteria->next()) {
|
||||
$row = $rsCriteria->getRow();
|
||||
|
||||
if ($row["INP_DOC_TITLE"] . "" == "") {
|
||||
//There is no transaltion for this Document name, try to get/regenerate the label
|
||||
$row["INP_DOC_TITLE"] = \Content::Load("INP_DOC_TITLE", "", $row["INP_DOC_UID"], SYS_LANG);
|
||||
}
|
||||
|
||||
$arrayCaseTrackerObject[] = array(
|
||||
"obj_uid" => $row["INP_DOC_UID"],
|
||||
"obj_title" => $row["INP_DOC_TITLE"],
|
||||
"obj_description" => $row["INP_DOC_DESCRIPTION"],
|
||||
"obj_type" => "INPUT_DOCUMENT"
|
||||
);
|
||||
}
|
||||
|
||||
//OutputDocuments
|
||||
$criteria = new \Criteria("workflow");
|
||||
|
||||
$criteria->addSelectColumn(\OutputDocumentPeer::OUT_DOC_UID);
|
||||
$criteria->addAsColumn("OUT_DOC_TITLE", "CT.CON_VALUE");
|
||||
$criteria->addAsColumn("OUT_DOC_DESCRIPTION", "CD.CON_VALUE");
|
||||
|
||||
$criteria->addAlias("CT", \ContentPeer::TABLE_NAME);
|
||||
$criteria->addAlias("CD", \ContentPeer::TABLE_NAME);
|
||||
|
||||
$arrayCondition = array();
|
||||
$arrayCondition[] = array(\OutputDocumentPeer::OUT_DOC_UID, "CT.CON_ID", \Criteria::EQUAL);
|
||||
$arrayCondition[] = array("CT.CON_CATEGORY", $delimiter . "OUT_DOC_TITLE" . $delimiter, \Criteria::EQUAL);
|
||||
$arrayCondition[] = array("CT.CON_LANG", $delimiter . SYS_LANG . $delimiter, \Criteria::EQUAL);
|
||||
$criteria->addJoinMC($arrayCondition, \Criteria::LEFT_JOIN);
|
||||
|
||||
$arrayCondition = array();
|
||||
$arrayCondition[] = array(\OutputDocumentPeer::OUT_DOC_UID, "CD.CON_ID", \Criteria::EQUAL);
|
||||
$arrayCondition[] = array("CD.CON_CATEGORY", $delimiter . "OUT_DOC_DESCRIPTION" . $delimiter, \Criteria::EQUAL);
|
||||
$arrayCondition[] = array("CD.CON_LANG", $delimiter . SYS_LANG . $delimiter, \Criteria::EQUAL);
|
||||
$criteria->addJoinMC($arrayCondition, \Criteria::LEFT_JOIN);
|
||||
|
||||
$criteria->add(\OutputDocumentPeer::PRO_UID, $processUid, \Criteria::EQUAL);
|
||||
$criteria->add(\OutputDocumentPeer::OUT_DOC_UID, $arrayOutputDocumentUid, \Criteria::NOT_IN);
|
||||
|
||||
$rsCriteria = \OutputDocumentPeer::doSelectRS($criteria);
|
||||
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
|
||||
while ($rsCriteria->next()) {
|
||||
$row = $rsCriteria->getRow();
|
||||
|
||||
if ($row["OUT_DOC_TITLE"] . "" == "") {
|
||||
//There is no transaltion for this Document name, try to get/regenerate the label
|
||||
$row["OUT_DOC_TITLE"] = \Content::Load("OUT_DOC_TITLE", "", $row["OUT_DOC_UID"], SYS_LANG);
|
||||
}
|
||||
|
||||
$arrayCaseTrackerObject[] = array(
|
||||
"obj_uid" => $row["OUT_DOC_UID"],
|
||||
"obj_title" => $row["OUT_DOC_TITLE"],
|
||||
"obj_description" => $row["OUT_DOC_DESCRIPTION"],
|
||||
"obj_type" => "OUTPUT_DOCUMENT"
|
||||
);
|
||||
}
|
||||
|
||||
$arrayCaseTrackerObject = \ProcessMaker\Util\ArrayUtil::sort(
|
||||
$arrayCaseTrackerObject,
|
||||
array("obj_type", "obj_title"),
|
||||
SORT_ASC
|
||||
);
|
||||
|
||||
return $arrayCaseTrackerObject;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all Case Tracker Objects of a Process
|
||||
*
|
||||
* @param string $processUid Unique id of Process
|
||||
*
|
||||
* return array Return an array with all Case Tracker Objects of a Process
|
||||
*/
|
||||
public function getCaseTrackerObjects($processUid)
|
||||
{
|
||||
try {
|
||||
$arrayCaseTrackerObject = array();
|
||||
|
||||
//Verify data
|
||||
$process = new \Process();
|
||||
|
||||
if (!$process->exists($processUid)) {
|
||||
throw (new \Exception(str_replace(array("{0}", "{1}"), array($processUid, "PROCESS"), "The UID \"{0}\" does not exist in table {1}")));
|
||||
}
|
||||
|
||||
$dynaform = new \Dynaform();
|
||||
$inputDocument = new \InputDocument();
|
||||
$outputDocument = new \OutputDocument();
|
||||
|
||||
$arrayCaseTrackerObject = array();
|
||||
|
||||
$criteria = new \Criteria("workflow");
|
||||
$criteria->add(\CaseTrackerObjectPeer::PRO_UID, $processUid, \Criteria::EQUAL);
|
||||
|
||||
$rsCriteria = \CaseTrackerObjectPeer::doSelectRS($criteria);
|
||||
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
|
||||
while ($rsCriteria->next()) {
|
||||
$row = $rsCriteria->getRow();
|
||||
|
||||
$titleObj = "";
|
||||
$descriptionObj = "";
|
||||
|
||||
switch ($row["CTO_TYPE_OBJ"]) {
|
||||
case "DYNAFORM":
|
||||
$arrayData = $dynaform->load($row["CTO_UID_OBJ"]);
|
||||
|
||||
$titleObj = $arrayData["DYN_TITLE"];
|
||||
$descriptionObj = $arrayData["DYN_DESCRIPTION"];
|
||||
break;
|
||||
case "INPUT_DOCUMENT":
|
||||
$arrayData = $inputDocument->getByUid($row["CTO_UID_OBJ"]);
|
||||
|
||||
$titleObj = $arrayData["INP_DOC_TITLE"];
|
||||
$descriptionObj = $arrayData["INP_DOC_DESCRIPTION"];
|
||||
break;
|
||||
case "OUTPUT_DOCUMENT":
|
||||
$arrayData = $outputDocument->getByUid($row["CTO_UID_OBJ"]);
|
||||
|
||||
$titleObj = $arrayData["OUT_DOC_TITLE"];
|
||||
$descriptionObj = $arrayData["OUT_DOC_DESCRIPTION"];
|
||||
break;
|
||||
}
|
||||
|
||||
$arrayCaseTrackerObject[] = array(
|
||||
"cto_uid" => $row["CTO_UID"],
|
||||
"cto_type_obj" => $row["CTO_TYPE_OBJ"],
|
||||
"cto_uid_obj" => $row["CTO_UID_OBJ"],
|
||||
"cto_condition" => $row["CTO_CONDITION"],
|
||||
"cto_position" => (int)($row["CTO_POSITION"]),
|
||||
"obj_title" => $titleObj,
|
||||
"obj_description" => $descriptionObj
|
||||
);
|
||||
}
|
||||
|
||||
$arrayCaseTrackerObject = \ProcessMaker\Util\ArrayUtil::sort($arrayCaseTrackerObject, array("cto_position"), SORT_ASC);
|
||||
|
||||
return $arrayCaseTrackerObject;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,391 @@
|
||||
<?php
|
||||
namespace ProcessMaker\BusinessModel;
|
||||
|
||||
class CaseTrackerObject
|
||||
{
|
||||
/**
|
||||
* Verify if exists the record in table CASE_TRACKER_OBJECT
|
||||
*
|
||||
* @param string $processUid Unique id of Process
|
||||
* @param string $type Type of Step (DYNAFORM, INPUT_DOCUMENT, OUTPUT_DOCUMENT)
|
||||
* @param string $objectUid Unique id of Object
|
||||
* @param int $position Position
|
||||
* @param string $caseTrackerObjectUidExclude Unique id of Case Tracker Object to exclude
|
||||
*
|
||||
* return bool Return true if exists the record in table CASE_TRACKER_OBJECT, false otherwise
|
||||
*/
|
||||
public function existsRecord($processUid, $type, $objectUid, $position = 0, $caseTrackerObjectUidExclude = "")
|
||||
{
|
||||
try {
|
||||
$criteria = new \Criteria("workflow");
|
||||
|
||||
$criteria->addSelectColumn(\CaseTrackerObjectPeer::CTO_UID);
|
||||
$criteria->add(\CaseTrackerObjectPeer::PRO_UID, $processUid, \Criteria::EQUAL);
|
||||
|
||||
if ($caseTrackerObjectUidExclude != "") {
|
||||
$criteria->add(\CaseTrackerObjectPeer::CTO_UID, $caseTrackerObjectUidExclude, \Criteria::NOT_EQUAL);
|
||||
}
|
||||
|
||||
if ($type != "") {
|
||||
$criteria->add(\CaseTrackerObjectPeer::CTO_TYPE_OBJ, $type, \Criteria::EQUAL);
|
||||
}
|
||||
|
||||
if ($objectUid != "") {
|
||||
$criteria->add(\CaseTrackerObjectPeer::CTO_UID_OBJ, $objectUid, \Criteria::EQUAL);
|
||||
}
|
||||
|
||||
if ($position > 0) {
|
||||
$criteria->add(\CaseTrackerObjectPeer::CTO_POSITION, $position, \Criteria::EQUAL);
|
||||
}
|
||||
|
||||
$rsCriteria = \CaseTrackerObjectPeer::doSelectRS($criteria);
|
||||
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
|
||||
if ($rsCriteria->next()) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Case Tracker Object for a Process
|
||||
*
|
||||
* @param string $processUid Unique id of Process
|
||||
* @param array $arrayData Data
|
||||
*
|
||||
* return array Return data of the new Case Tracker Object created
|
||||
*/
|
||||
public function create($processUid, $arrayData)
|
||||
{
|
||||
try {
|
||||
$arrayData = array_change_key_case($arrayData, CASE_UPPER);
|
||||
|
||||
unset($arrayData["CTO_UID"]);
|
||||
|
||||
//Verify data
|
||||
$process = new \Process();
|
||||
|
||||
if (!$process->exists($processUid)) {
|
||||
throw (new \Exception(str_replace(array("{0}", "{1}"), array($processUid, "PROCESS"), "The UID \"{0}\" doesn't exist in table {1}")));
|
||||
}
|
||||
|
||||
if (!isset($arrayData["CTO_TYPE_OBJ"])) {
|
||||
throw (new \Exception(str_replace(array("{0}"), array(strtolower("CTO_TYPE_OBJ")), "The \"{0}\" attribute is not defined")));
|
||||
}
|
||||
|
||||
if (!isset($arrayData["CTO_UID_OBJ"])) {
|
||||
throw (new \Exception(str_replace(array("{0}"), array(strtolower("CTO_UID_OBJ")), "The \"{0}\" attribute is not defined")));
|
||||
}
|
||||
|
||||
$step = new \ProcessMaker\BusinessModel\Step();
|
||||
|
||||
$msg = $step->existsObjectUid($arrayData["CTO_TYPE_OBJ"], $arrayData["CTO_UID_OBJ"]);
|
||||
|
||||
if ($msg != "") {
|
||||
throw (new \Exception($msg));
|
||||
}
|
||||
|
||||
if ($this->existsRecord($processUid, $arrayData["CTO_TYPE_OBJ"], $arrayData["CTO_UID_OBJ"])) {
|
||||
throw (new \Exception(str_replace(array("{0}", "{1}"), array($processUid . ", " . $arrayData["CTO_TYPE_OBJ"] . ", " . $arrayData["CTO_UID_OBJ"], "CASE_TRACKER_OBJECT"), "The record \"{0}\", exists in table {1}")));
|
||||
}
|
||||
|
||||
$ctoPosition = $arrayData["CTO_POSITION"];
|
||||
$criteria = new \Criteria("workflow");
|
||||
$criteria->add(\CaseTrackerObjectPeer::PRO_UID, $processUid);
|
||||
$arrayData["CTO_POSITION"] = \CaseTrackerObjectPeer::doCount($criteria) + 1;
|
||||
|
||||
//Create
|
||||
$caseTrackerObject = new \CaseTrackerObject();
|
||||
|
||||
$arrayData["PRO_UID"] = $processUid;
|
||||
$caseTrackerObjectUid = $caseTrackerObject->create($arrayData);
|
||||
|
||||
$arrayData["CTO_POSITION"] = $ctoPosition;
|
||||
$arrayData["CTO_UID"] = $caseTrackerObjectUid;
|
||||
$arrayDataUpdate = array_change_key_case($arrayData, CASE_LOWER);
|
||||
$this->update($caseTrackerObjectUid, $arrayDataUpdate);
|
||||
|
||||
//Return
|
||||
unset($arrayData["PRO_UID"]);
|
||||
|
||||
$arrayData = array_change_key_case($arrayData, CASE_LOWER);
|
||||
|
||||
unset($arrayData["cto_uid"]);
|
||||
|
||||
return array_merge(array("cto_uid" => $caseTrackerObjectUid), $arrayData);
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update Case Tracker Object
|
||||
*
|
||||
* @param string $caseTrackerObjectUid Unique id of Case Tracker Object
|
||||
* @param array $arrayData Data
|
||||
*
|
||||
* return array Return data of the Case Tracker Object updated
|
||||
*/
|
||||
public function update($caseTrackerObjectUid, $arrayData)
|
||||
{
|
||||
try {
|
||||
$arrayData = array_change_key_case($arrayData, CASE_UPPER);
|
||||
|
||||
$caseTrackerObject = new \CaseTrackerObject();
|
||||
|
||||
$arrayCaseTrackerObjectData = $caseTrackerObject->load($caseTrackerObjectUid);
|
||||
|
||||
//Uids
|
||||
$processUid = $arrayCaseTrackerObjectData["PRO_UID"];
|
||||
|
||||
//Verify data
|
||||
if (!$caseTrackerObject->caseTrackerObjectExists($caseTrackerObjectUid)) {
|
||||
throw (new \Exception(str_replace(array("{0}", "{1}"), array($caseTrackerObjectUid, "CASE_TRACKER_OBJECT"), "The UID \"{0}\" doesn't exist in table {1}")));
|
||||
}
|
||||
|
||||
if (isset($arrayData["CTO_TYPE_OBJ"]) && !isset($arrayData["CTO_UID_OBJ"])) {
|
||||
throw (new \Exception(str_replace(array("{0}"), array(strtolower("CTO_UID_OBJ")), "The \"{0}\" attribute is not defined")));
|
||||
}
|
||||
|
||||
if (!isset($arrayData["CTO_TYPE_OBJ"]) && isset($arrayData["CTO_UID_OBJ"])) {
|
||||
throw (new \Exception(str_replace(array("{0}"), array(strtolower("CTO_TYPE_OBJ")), "The \"{0}\" attribute is not defined")));
|
||||
}
|
||||
|
||||
if (isset($arrayData["CTO_TYPE_OBJ"]) && isset($arrayData["CTO_UID_OBJ"])) {
|
||||
$step = new \ProcessMaker\BusinessModel\Step();
|
||||
|
||||
$msg = $step->existsObjectUid($arrayData["CTO_TYPE_OBJ"], $arrayData["CTO_UID_OBJ"]);
|
||||
|
||||
if ($msg != "") {
|
||||
throw (new \Exception($msg));
|
||||
}
|
||||
|
||||
if ($this->existsRecord($processUid, $arrayData["CTO_TYPE_OBJ"], $arrayData["CTO_UID_OBJ"], 0, $caseTrackerObjectUid)) {
|
||||
throw (new \Exception(str_replace(array("{0}", "{1}"), array($processUid . ", " . $arrayData["CTO_TYPE_OBJ"] . ", " . $arrayData["CTO_UID_OBJ"], "CASE_TRACKER_OBJECT"), "The record \"{0}\", exists in table {1}")));
|
||||
}
|
||||
}
|
||||
|
||||
//Flags
|
||||
$flagDataOject = (isset($arrayData["CTO_TYPE_OBJ"]) && isset($arrayData["CTO_UID_OBJ"]))? 1 : 0;
|
||||
$flagDataCondition = (isset($arrayData["CTO_CONDITION"]))? 1 : 0;
|
||||
$flagDataPosition = (isset($arrayData["CTO_POSITION"]))? 1 : 0;
|
||||
|
||||
//Update
|
||||
$tempPosition = (isset($arrayData["CTO_POSITION"])) ? $arrayData["CTO_POSITION"] : $arrayCaseTrackerObjectData["CTO_POSITION"];
|
||||
$arrayData["CTO_POSITION"] = $arrayCaseTrackerObjectData["CTO_POSITION"];
|
||||
$arrayData["CTO_UID"] = $caseTrackerObjectUid;
|
||||
$arrayData = array_merge($arrayCaseTrackerObjectData, $arrayData);
|
||||
$caseTrackerObject->update($arrayData);
|
||||
|
||||
if ($tempPosition != $arrayCaseTrackerObjectData["CTO_POSITION"]) {
|
||||
$this->moveCaseTrackerObject($caseTrackerObjectUid, $arrayData['PRO_UID'], $tempPosition);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Return
|
||||
unset($arrayData["CTO_UID"]);
|
||||
|
||||
if ($flagDataOject == 0) {
|
||||
unset($arrayData["CTO_TYPE_OBJ"]);
|
||||
unset($arrayData["CTO_UID_OBJ"]);
|
||||
}
|
||||
|
||||
if ($flagDataCondition == 0) {
|
||||
unset($arrayData["CTO_CONDITION"]);
|
||||
}
|
||||
|
||||
if ($flagDataPosition == 0) {
|
||||
unset($arrayData["CTO_POSITION"]);
|
||||
}
|
||||
|
||||
unset($arrayData["PRO_UID"]);
|
||||
|
||||
return array_change_key_case($arrayData, CASE_LOWER);
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete Case Tracker Object
|
||||
*
|
||||
* @param string $caseTrackerObjectUid Unique id of Case Tracker Object
|
||||
*
|
||||
* return void
|
||||
*/
|
||||
public function delete($caseTrackerObjectUid)
|
||||
{
|
||||
try {
|
||||
$caseTrackerObject = new \CaseTrackerObject();
|
||||
|
||||
$arrayCaseTrackerObjectData = $caseTrackerObject->load($caseTrackerObjectUid);
|
||||
|
||||
//Uids
|
||||
$processUid = $arrayCaseTrackerObjectData["PRO_UID"];
|
||||
|
||||
//Verify data
|
||||
if (!$caseTrackerObject->caseTrackerObjectExists($caseTrackerObjectUid)) {
|
||||
throw (new \Exception(str_replace(array("{0}", "{1}"), array($caseTrackerObjectUid, "CASE_TRACKER_OBJECT"), "The UID \"{0}\" doesn't exist in table {1}")));
|
||||
}
|
||||
|
||||
//Delete
|
||||
$result = $caseTrackerObject->remove($caseTrackerObjectUid);
|
||||
|
||||
$caseTrackerObject->reorderPositions($processUid, $arrayCaseTrackerObjectData["CTO_POSITION"]);
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data of a Case Tracker Object
|
||||
*
|
||||
* @param string $caseTrackerObjectUid Unique id of Case Tracker Object
|
||||
*
|
||||
* return array Return an array with data of a Case Tracker Object
|
||||
*/
|
||||
public function getCaseTrackerObject($caseTrackerObjectUid)
|
||||
{
|
||||
try {
|
||||
//Verify data
|
||||
$caseTrackerObject = new \CaseTrackerObject();
|
||||
|
||||
if (!$caseTrackerObject->caseTrackerObjectExists($caseTrackerObjectUid)) {
|
||||
throw (new \Exception(str_replace(array("{0}", "{1}"), array($caseTrackerObjectUid, "CASE_TRACKER_OBJECT"), "The UID \"{0}\" doesn't exist in table {1}")));
|
||||
}
|
||||
|
||||
//Get data
|
||||
$dynaform = new \Dynaform();
|
||||
$inputDocument = new \InputDocument();
|
||||
$outputDocument = new \OutputDocument();
|
||||
|
||||
$criteria = new \Criteria("workflow");
|
||||
|
||||
$criteria->add(\CaseTrackerObjectPeer::CTO_UID, $caseTrackerObjectUid, \Criteria::EQUAL);
|
||||
|
||||
$rsCriteria = \CaseTrackerObjectPeer::doSelectRS($criteria);
|
||||
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
|
||||
$rsCriteria->next();
|
||||
|
||||
$row = $rsCriteria->getRow();
|
||||
|
||||
$titleObj = "";
|
||||
$descriptionObj = "";
|
||||
|
||||
switch ($row["CTO_TYPE_OBJ"]) {
|
||||
case "DYNAFORM":
|
||||
$arrayData = $dynaform->load($row["CTO_UID_OBJ"]);
|
||||
|
||||
$titleObj = $arrayData["DYN_TITLE"];
|
||||
$descriptionObj = $arrayData["DYN_DESCRIPTION"];
|
||||
break;
|
||||
case "INPUT_DOCUMENT":
|
||||
$arrayData = $inputDocument->getByUid($row["CTO_UID_OBJ"]);
|
||||
|
||||
$titleObj = $arrayData["INP_DOC_TITLE"];
|
||||
$descriptionObj = $arrayData["INP_DOC_DESCRIPTION"];
|
||||
break;
|
||||
case "OUTPUT_DOCUMENT":
|
||||
$arrayData = $outputDocument->getByUid($row["CTO_UID_OBJ"]);
|
||||
|
||||
$titleObj = $arrayData["OUT_DOC_TITLE"];
|
||||
$descriptionObj = $arrayData["OUT_DOC_DESCRIPTION"];
|
||||
break;
|
||||
}
|
||||
|
||||
return array(
|
||||
"cto_uid" => $row["CTO_UID"],
|
||||
"cto_type_obj" => $row["CTO_TYPE_OBJ"],
|
||||
"cto_uid_obj" => $row["CTO_UID_OBJ"],
|
||||
"cto_condition" => $row["CTO_CONDITION"],
|
||||
"cto_position" => (int)($row["CTO_POSITION"]),
|
||||
"obj_title" => $titleObj,
|
||||
"obj_description" => $descriptionObj
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate Process Uid
|
||||
* @var string $cto_uid. Uid for Process
|
||||
* @var string $pro_uid. Uid for Task
|
||||
* @var string $cto_pos. Position for Step
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function moveCaseTrackerObject($cto_uid, $pro_uid, $cto_pos) {
|
||||
$aCaseTrackerObject = CaseTracker::getCaseTrackerObjects($pro_uid);
|
||||
|
||||
foreach ($aCaseTrackerObject as $dataCaseTracker) {
|
||||
if ($dataCaseTracker['cto_uid'] == $cto_uid) {
|
||||
$prStepPos = (int)$dataCaseTracker['cto_position'];
|
||||
}
|
||||
}
|
||||
$seStepPos = $cto_pos;
|
||||
|
||||
//Principal Step is up
|
||||
if ($prStepPos == $seStepPos) {
|
||||
return true;
|
||||
} elseif ($prStepPos < $seStepPos) {
|
||||
$modPos = 'UP';
|
||||
$newPos = $seStepPos;
|
||||
$iniPos = $prStepPos+1;
|
||||
$finPos = $seStepPos;
|
||||
} else {
|
||||
$modPos = 'DOWN';
|
||||
$newPos = $seStepPos;
|
||||
$iniPos = $seStepPos;
|
||||
$finPos = $prStepPos-1;
|
||||
}
|
||||
|
||||
$range = range($iniPos, $finPos);
|
||||
foreach ($aCaseTrackerObject as $dataCaseTracker) {
|
||||
if ((in_array($dataCaseTracker['cto_position'], $range)) && ($dataCaseTracker['cto_uid'] != $cto_uid)) {
|
||||
$caseTrackerObjectIds[] = $dataCaseTracker['cto_uid'];
|
||||
$caseTrackerObjectPos[] = $dataCaseTracker['cto_position'];
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($caseTrackerObjectIds as $key => $value) {
|
||||
if ($modPos == 'UP') {
|
||||
$tempPos = ((int)$caseTrackerObjectPos[$key])-1;
|
||||
$this->changePosCaseTrackerObject($value, $tempPos);
|
||||
} else {
|
||||
$tempPos = ((int)$caseTrackerObjectPos[$key])+1;
|
||||
$this->changePosCaseTrackerObject($value, $tempPos);
|
||||
}
|
||||
}
|
||||
$this->changePosCaseTrackerObject($cto_uid, $newPos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate Process Uid
|
||||
* @var string $pro_uid. Uid for process
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function changePosCaseTrackerObject ($cto_uid, $pos)
|
||||
{
|
||||
$data = array(
|
||||
'CTO_UID' => $cto_uid,
|
||||
'CTO_POSITION' => $pos
|
||||
);
|
||||
$oCaseTrackerObject = new \CaseTrackerObject();
|
||||
$oCaseTrackerObject->update($data);
|
||||
}
|
||||
}
|
||||
|
||||
1492
workflow/engine/src/ProcessMaker/BusinessModel/Cases.php
Normal file
1492
workflow/engine/src/ProcessMaker/BusinessModel/Cases.php
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,222 @@
|
||||
<?php
|
||||
namespace ProcessMaker\BusinessModel\Cases;
|
||||
|
||||
class InputDocument
|
||||
{
|
||||
/**
|
||||
* Get data of Cases InputDocument
|
||||
*
|
||||
* @param string $applicationUid
|
||||
* @param string $userUid
|
||||
*
|
||||
* return array Return an array with data of an InputDocument
|
||||
*/
|
||||
public function getCasesInputDocuments($applicationUid, $userUid)
|
||||
{
|
||||
try {
|
||||
$sApplicationUID = $applicationUid;
|
||||
$sUserUID = $userUid;
|
||||
\G::LoadClass('case');
|
||||
$oCase = new \Cases();
|
||||
$fields = $oCase->loadCase( $sApplicationUID );
|
||||
$sProcessUID = $fields['PRO_UID'];
|
||||
$sTaskUID = '';
|
||||
$oCaseRest = new \ProcessMaker\BusinessModel\Cases();
|
||||
$oCaseRest->getAllUploadedDocumentsCriteria( $sProcessUID, $sApplicationUID, $sTaskUID, $sUserUID);
|
||||
$result = array ();
|
||||
global $_DBArray;
|
||||
foreach ($_DBArray['inputDocuments'] as $key => $row) {
|
||||
if (isset( $row['DOC_VERSION'] )) {
|
||||
$docrow = array ();
|
||||
$docrow['app_doc_uid'] = $row['APP_DOC_UID'];
|
||||
$docrow['app_doc_filename'] = $row['APP_DOC_FILENAME'];
|
||||
$docrow['doc_uid'] = $row['DOC_UID'];
|
||||
$docrow['app_doc_version'] = $row['DOC_VERSION'];
|
||||
$docrow['app_doc_create_date'] = $row['CREATE_DATE'];
|
||||
$docrow['app_doc_create_user'] = $row['CREATED_BY'];
|
||||
$docrow['app_doc_type'] = $row['TYPE'];
|
||||
$docrow['app_doc_index'] = $row['APP_DOC_INDEX'];
|
||||
$docrow['app_doc_link'] = 'cases/' . $row['DOWNLOAD_LINK'];
|
||||
$result[] = $docrow;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data of Cases InputDocument
|
||||
*
|
||||
* @param string $applicationUid
|
||||
* @param string $userUid
|
||||
* @param string $inputDocumentUid
|
||||
*
|
||||
* return array Return an array with data of an InputDocument
|
||||
*/
|
||||
public function getCasesInputDocument($applicationUid, $userUid, $inputDocumentUid)
|
||||
{
|
||||
try {
|
||||
$sApplicationUID = $applicationUid;
|
||||
$sUserUID = $userUid;
|
||||
\G::LoadClass('case');
|
||||
$oCase = new \Cases();
|
||||
$fields = $oCase->loadCase( $sApplicationUID );
|
||||
$sProcessUID = $fields['PRO_UID'];
|
||||
$sTaskUID = '';
|
||||
$oCaseRest = new \ProcessMaker\BusinessModel\Cases();
|
||||
$oCaseRest->getAllUploadedDocumentsCriteria( $sProcessUID, $sApplicationUID, $sTaskUID, $sUserUID );
|
||||
$result = array ();
|
||||
global $_DBArray;
|
||||
foreach ($_DBArray['inputDocuments'] as $key => $row) {
|
||||
if (isset( $row['DOC_VERSION'] )) {
|
||||
$docrow = array ();
|
||||
$docrow['app_doc_uid'] = $row['APP_DOC_UID'];
|
||||
$docrow['app_doc_filename'] = $row['APP_DOC_FILENAME'];
|
||||
$docrow['doc_uid'] = $row['DOC_UID'];
|
||||
$docrow['app_doc_version'] = $row['DOC_VERSION'];
|
||||
$docrow['app_doc_create_date'] = $row['CREATE_DATE'];
|
||||
$docrow['app_doc_create_user'] = $row['CREATED_BY'];
|
||||
$docrow['app_doc_type'] = $row['TYPE'];
|
||||
$docrow['app_doc_index'] = $row['APP_DOC_INDEX'];
|
||||
$docrow['app_doc_link'] = 'cases/' . $row['DOWNLOAD_LINK'];
|
||||
if ($docrow['app_doc_uid'] == $inputDocumentUid) {
|
||||
$result = $docrow;
|
||||
}
|
||||
}
|
||||
}
|
||||
$oResponse = json_decode(json_encode($result), false);
|
||||
return $oResponse;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete InputDocument
|
||||
*
|
||||
* @param string $inputDocumentUid
|
||||
*
|
||||
* return array Return an array with data of an InputDocument
|
||||
*/
|
||||
public function removeInputDocument($inputDocumentUid)
|
||||
{
|
||||
try {
|
||||
$oAppDocument = \AppDocumentPeer::retrieveByPK( $inputDocumentUid, 1 );
|
||||
if (is_null( $oAppDocument ) || $oAppDocument->getAppDocStatus() == 'DELETED') {
|
||||
throw (new \Exception('This input document with id: '.$inputDocumentUid.' doesn\'t exist!'));
|
||||
}
|
||||
\G::LoadClass('wsBase');
|
||||
$ws = new \wsBase();
|
||||
$ws->removeDocument($inputDocumentUid);
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data of Cases InputDocument
|
||||
*
|
||||
* @param string $applicationUid
|
||||
* @param string $taskUid
|
||||
* @param string $appDocComment
|
||||
* @param string $inputDocumentUid
|
||||
* @param string $userUid
|
||||
*
|
||||
* return array Return an array with data of an InputDocument
|
||||
*/
|
||||
public function addCasesInputDocument($applicationUid, $taskUid, $appDocComment, $inputDocumentUid, $userUid)
|
||||
{
|
||||
try {
|
||||
if ((isset( $_FILES['form'] )) && ($_FILES['form']['error'] != 0)) {
|
||||
$code = $_FILES['form']['error'];
|
||||
switch ($code) {
|
||||
case UPLOAD_ERR_INI_SIZE:
|
||||
$message = \G::LoadTranslation( 'ID_UPLOAD_ERR_INI_SIZE' );
|
||||
break;
|
||||
case UPLOAD_ERR_FORM_SIZE:
|
||||
$message = \G::LoadTranslation( 'ID_UPLOAD_ERR_FORM_SIZE' );
|
||||
break;
|
||||
case UPLOAD_ERR_PARTIAL:
|
||||
$message = \G::LoadTranslation( 'ID_UPLOAD_ERR_PARTIAL' );
|
||||
break;
|
||||
case UPLOAD_ERR_NO_FILE:
|
||||
$message = \G::LoadTranslation( 'ID_UPLOAD_ERR_NO_FILE' );
|
||||
break;
|
||||
case UPLOAD_ERR_NO_TMP_DIR:
|
||||
$message = \G::LoadTranslation( 'ID_UPLOAD_ERR_NO_TMP_DIR' );
|
||||
break;
|
||||
case UPLOAD_ERR_CANT_WRITE:
|
||||
$message = \G::LoadTranslation( 'ID_UPLOAD_ERR_CANT_WRITE' );
|
||||
break;
|
||||
case UPLOAD_ERR_EXTENSION:
|
||||
$message = \G::LoadTranslation( 'ID_UPLOAD_ERR_EXTENSION' );
|
||||
break;
|
||||
default:
|
||||
$message = \G::LoadTranslation( 'ID_UPLOAD_ERR_UNKNOWN' );
|
||||
break;
|
||||
}
|
||||
\G::SendMessageText( $message, "ERROR" );
|
||||
$backUrlObj = explode( "sys" . SYS_SYS, $_SERVER['HTTP_REFERER'] );
|
||||
\G::header( "location: " . "/sys" . SYS_SYS . $backUrlObj[1] );
|
||||
die();
|
||||
}
|
||||
\G::LoadClass("case");
|
||||
$appDocUid = \G::generateUniqueID();
|
||||
$docVersion = '';
|
||||
$appDocType = 'INPUT';
|
||||
$case = new \Cases();
|
||||
$delIndex = \AppDelegation::getCurrentIndex($applicationUid);
|
||||
$case->thisIsTheCurrentUser($applicationUid, $delIndex, $userUid, "REDIRECT", "casesListExtJs");
|
||||
//Load the fields
|
||||
$arrayField = $case->loadCase($applicationUid);
|
||||
$arrayField["APP_DATA"] = array_merge($arrayField["APP_DATA"], \G::getSystemConstants());
|
||||
//Triggers
|
||||
$arrayTrigger = $case->loadTriggers($taskUid, "INPUT_DOCUMENT", $inputDocumentUid, "AFTER");
|
||||
//Add Input Document
|
||||
if (!$_FILES["form"]["error"]) {
|
||||
$_FILES["form"]["error"] = 0;
|
||||
}
|
||||
if (isset($_FILES) && isset($_FILES["form"]) && count($_FILES["form"]) > 0) {
|
||||
$appDocUid = $case->addInputDocument(
|
||||
$inputDocumentUid,
|
||||
$appDocUid,
|
||||
$docVersion,
|
||||
$appDocType,
|
||||
$appDocComment,
|
||||
'',
|
||||
$applicationUid,
|
||||
$delIndex,
|
||||
$taskUid,
|
||||
$userUid,
|
||||
"xmlform",
|
||||
$_FILES["form"]["name"],
|
||||
$_FILES["form"]["error"],
|
||||
$_FILES["form"]["tmp_name"]
|
||||
);
|
||||
}
|
||||
//Trigger - Execute after - Start
|
||||
$arrayField["APP_DATA"] = $case->executeTriggers(
|
||||
$taskUid,
|
||||
"INPUT_DOCUMENT",
|
||||
$inputDocumentUid,
|
||||
"AFTER",
|
||||
$arrayField["APP_DATA"]
|
||||
);
|
||||
//Trigger - Execute after - End
|
||||
|
||||
//Save data
|
||||
$arrayData = array();
|
||||
$arrayData["APP_NUMBER"] = $arrayField["APP_NUMBER"];
|
||||
//$arrayData["APP_PROC_STATUS"] = $arrayField["APP_PROC_STATUS"];
|
||||
$arrayData["APP_DATA"] = $arrayField["APP_DATA"];
|
||||
$arrayData["DEL_INDEX"] = $delIndex;
|
||||
$arrayData["TAS_UID"] = $taskUid;
|
||||
$case->updateCase($applicationUid, $arrayData);
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,626 @@
|
||||
<?php
|
||||
namespace ProcessMaker\BusinessModel\Cases;
|
||||
|
||||
class OutputDocument
|
||||
{
|
||||
/**
|
||||
* Get data of Cases OutputDocument
|
||||
*
|
||||
* @param string $applicationUid
|
||||
* @param string $userUid
|
||||
*
|
||||
* return array Return an array with data of an OutputDocument
|
||||
*/
|
||||
public function getCasesOutputDocuments($applicationUid, $userUid)
|
||||
{
|
||||
try {
|
||||
\G::LoadClass('case');
|
||||
$oCase = new \Cases();
|
||||
$fields = $oCase->loadCase( $applicationUid );
|
||||
$sProcessUID = $fields['PRO_UID'];
|
||||
$sTaskUID = '';
|
||||
$oCriteria = new \ProcessMaker\BusinessModel\Cases();
|
||||
$oCriteria->getAllGeneratedDocumentsCriteria( $sProcessUID, $applicationUid, $sTaskUID, $userUid);
|
||||
$result = array ();
|
||||
global $_DBArray;
|
||||
foreach ($_DBArray['outputDocuments'] as $key => $row) {
|
||||
if (isset( $row['DOC_VERSION'] )) {
|
||||
$docrow = array ();
|
||||
$docrow['app_doc_uid'] = $row['APP_DOC_UID'];
|
||||
$docrow['app_doc_filename'] = $row['DOWNLOAD_FILE'];
|
||||
$docrow['doc_uid'] = $row['DOC_UID'];
|
||||
$docrow['app_doc_version'] = $row['DOC_VERSION'];
|
||||
$docrow['app_doc_create_date'] = $row['CREATE_DATE'];
|
||||
$docrow['app_doc_create_user'] = $row['CREATED_BY'];
|
||||
$docrow['app_doc_type'] = $row['TYPE'];
|
||||
$docrow['app_doc_index'] = $row['APP_DOC_INDEX'];
|
||||
$docrow['app_doc_link'] = 'cases/' . $row['DOWNLOAD_LINK'];
|
||||
$result[] = $docrow;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data of Cases OutputDocument
|
||||
*
|
||||
* @param string $applicationUid
|
||||
* @param string $userUid
|
||||
* @param string $applicationDocumentUid
|
||||
*
|
||||
* return object Return an object with data of an OutputDocument
|
||||
*/
|
||||
public function getCasesOutputDocument($applicationUid, $userUid, $applicationDocumentUid)
|
||||
{
|
||||
try {
|
||||
$sApplicationUID = $applicationUid;
|
||||
$sUserUID = $userUid;
|
||||
\G::LoadClass('case');
|
||||
$oCase = new \Cases();
|
||||
$fields = $oCase->loadCase( $sApplicationUID );
|
||||
$sProcessUID = $fields['PRO_UID'];
|
||||
$sTaskUID = '';
|
||||
$oCaseRest = new \ProcessMaker\BusinessModel\Cases();
|
||||
$oCaseRest->getAllGeneratedDocumentsCriteria( $sProcessUID, $sApplicationUID, $sTaskUID, $sUserUID );
|
||||
$result = array ();
|
||||
global $_DBArray;
|
||||
foreach ($_DBArray['outputDocuments'] as $key => $row) {
|
||||
if (isset( $row['DOC_VERSION'] )) {
|
||||
$docrow = array ();
|
||||
$docrow['app_doc_uid'] = $row['APP_DOC_UID'];
|
||||
$docrow['app_doc_filename'] = $row['DOWNLOAD_FILE'];
|
||||
$docrow['doc_uid'] = $row['DOC_UID'];
|
||||
$docrow['app_doc_version'] = $row['DOC_VERSION'];
|
||||
$docrow['app_doc_create_date'] = $row['CREATE_DATE'];
|
||||
$docrow['app_doc_create_user'] = $row['CREATED_BY'];
|
||||
$docrow['app_doc_type'] = $row['TYPE'];
|
||||
$docrow['app_doc_index'] = $row['APP_DOC_INDEX'];
|
||||
$docrow['app_doc_link'] = 'cases/' . $row['DOWNLOAD_LINK'];
|
||||
if ($docrow['app_doc_uid'] == $applicationDocumentUid) {
|
||||
$result = $docrow;
|
||||
}
|
||||
}
|
||||
}
|
||||
$oResponse = json_decode(json_encode($result), false);
|
||||
return $oResponse;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete OutputDocument
|
||||
*
|
||||
* @param string $applicationDocumentUid
|
||||
*
|
||||
*/
|
||||
public function removeOutputDocument($applicationDocumentUid)
|
||||
{
|
||||
try {
|
||||
$oAppDocument = \AppDocumentPeer::retrieveByPK( $applicationDocumentUid, 1 );
|
||||
if (is_null( $oAppDocument ) || $oAppDocument->getAppDocStatus() == 'DELETED') {
|
||||
throw (new \Exception('This output document with id: '.$applicationDocumentUid.' doesn\'t exist!'));
|
||||
}
|
||||
\G::LoadClass('wsBase');
|
||||
$ws = new \wsBase();
|
||||
$ws->removeDocument($applicationDocumentUid);
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data of Cases OutputDocument
|
||||
*
|
||||
* @param string $applicationUid
|
||||
* @param string $outputDocumentUid
|
||||
* @param string $userUid
|
||||
*
|
||||
* return object Return an object with data of an OutputDocument
|
||||
*/
|
||||
public function addCasesOutputDocument($applicationUid, $outputDocumentUid, $userUid)
|
||||
{
|
||||
try {
|
||||
$sApplication = $applicationUid;
|
||||
$index = \AppDelegation::getCurrentIndex($applicationUid);
|
||||
$sUserLogged = $userUid;
|
||||
$outputID = $outputDocumentUid;
|
||||
$g = new \G();
|
||||
$g->sessionVarSave();
|
||||
\G::LoadClass( 'case' );
|
||||
$oCase = new \Cases();
|
||||
$oCase->thisIsTheCurrentUser( $sApplication, $index, $sUserLogged, '', 'casesListExtJs' );
|
||||
//require_once 'classes/model/OutputDocument.php';
|
||||
$oOutputDocument = new \OutputDocument();
|
||||
$aOD = $oOutputDocument->load( $outputID );
|
||||
$Fields = $oCase->loadCase( $sApplication );
|
||||
$sFilename = preg_replace( '[^A-Za-z0-9_]', '_', \G::replaceDataField( $aOD['OUT_DOC_FILENAME'], $Fields['APP_DATA'] ) );
|
||||
require_once (PATH_TRUNK . "workflow" . PATH_SEP . "engine" . PATH_SEP . "classes" . PATH_SEP . "model" . PATH_SEP . "AppFolder.php");
|
||||
require_once (PATH_TRUNK . "workflow" . PATH_SEP . "engine" . PATH_SEP . "classes" . PATH_SEP . "model" . PATH_SEP . "AppDocument.php");
|
||||
//Get the Custom Folder ID (create if necessary)
|
||||
$oFolder = new \AppFolder();
|
||||
$folderId = $oFolder->createFromPath( $aOD['OUT_DOC_DESTINATION_PATH'], $sApplication );
|
||||
//Tags
|
||||
$fileTags = $oFolder->parseTags( $aOD['OUT_DOC_TAGS'], $sApplication );
|
||||
//Get last Document Version and apply versioning if is enabled
|
||||
$oAppDocument = new \AppDocument();
|
||||
$lastDocVersion = $oAppDocument->getLastDocVersion( $outputID, $sApplication );
|
||||
$oCriteria = new \Criteria( 'workflow' );
|
||||
$oCriteria->add( \AppDocumentPeer::APP_UID, $sApplication );
|
||||
$oCriteria->add( \AppDocumentPeer::DOC_UID, $outputID );
|
||||
$oCriteria->add( \AppDocumentPeer::DOC_VERSION, $lastDocVersion );
|
||||
$oCriteria->add( \AppDocumentPeer::APP_DOC_TYPE, 'OUTPUT' );
|
||||
$oDataset = \AppDocumentPeer::doSelectRS( $oCriteria );
|
||||
$oDataset->setFetchmode( \ResultSet::FETCHMODE_ASSOC );
|
||||
$oDataset->next();
|
||||
if (($aOD['OUT_DOC_VERSIONING']) && ($lastDocVersion != 0)) {
|
||||
//Create new Version of current output
|
||||
$lastDocVersion ++;
|
||||
if ($aRow = $oDataset->getRow()) {
|
||||
$aFields = array ('APP_DOC_UID' => $aRow['APP_DOC_UID'],'APP_UID' => $sApplication,'DEL_INDEX' => $index,'DOC_UID' => $outputID,'DOC_VERSION' => $lastDocVersion + 1,'USR_UID' => $sUserLogged,'APP_DOC_TYPE' => 'OUTPUT','APP_DOC_CREATE_DATE' => date( 'Y-m-d H:i:s' ),'APP_DOC_FILENAME' => $sFilename,'FOLDER_UID' => $folderId,'APP_DOC_TAGS' => $fileTags);
|
||||
$oAppDocument = new \AppDocument();
|
||||
$oAppDocument->create( $aFields );
|
||||
$sDocUID = $aRow['APP_DOC_UID'];
|
||||
}
|
||||
} else {
|
||||
////No versioning so Update a current Output or Create new if no exist
|
||||
if ($aRow = $oDataset->getRow()) {
|
||||
//Update
|
||||
$aFields = array ('APP_DOC_UID' => $aRow['APP_DOC_UID'],'APP_UID' => $sApplication,'DEL_INDEX' => $index,'DOC_UID' => $outputID,'DOC_VERSION' => $lastDocVersion,'USR_UID' => $sUserLogged,'APP_DOC_TYPE' => 'OUTPUT','APP_DOC_CREATE_DATE' => date( 'Y-m-d H:i:s' ),'APP_DOC_FILENAME' => $sFilename,'FOLDER_UID' => $folderId,'APP_DOC_TAGS' => $fileTags
|
||||
);
|
||||
$oAppDocument = new \AppDocument();
|
||||
$oAppDocument->update( $aFields );
|
||||
$sDocUID = $aRow['APP_DOC_UID'];
|
||||
} else {
|
||||
//we are creating the appdocument row
|
||||
//create
|
||||
if ($lastDocVersion == 0) {
|
||||
$lastDocVersion ++;
|
||||
}
|
||||
$aFields = array ('APP_UID' => $sApplication,'DEL_INDEX' => $index,'DOC_UID' => $outputID,'DOC_VERSION' => $lastDocVersion,'USR_UID' => $sUserLogged,'APP_DOC_TYPE' => 'OUTPUT','APP_DOC_CREATE_DATE' => date( 'Y-m-d H:i:s' ),'APP_DOC_FILENAME' => $sFilename,'FOLDER_UID' => $folderId,'APP_DOC_TAGS' => $fileTags
|
||||
);
|
||||
$oAppDocument = new \AppDocument();
|
||||
$aFields['APP_DOC_UID'] = $sDocUID = $oAppDocument->create( $aFields );
|
||||
}
|
||||
}
|
||||
$sFilename = $aFields['APP_DOC_UID'] . "_" . $lastDocVersion;
|
||||
$pathOutput = PATH_DOCUMENT . \G::getPathFromUID($sApplication) . PATH_SEP . 'outdocs' . PATH_SEP; //G::pr($sFilename);die;
|
||||
\G::mk_dir( $pathOutput );
|
||||
$aProperties = array ();
|
||||
if (! isset( $aOD['OUT_DOC_MEDIA'] )) {
|
||||
$aOD['OUT_DOC_MEDIA'] = 'Letter';
|
||||
}
|
||||
if (! isset( $aOD['OUT_DOC_LEFT_MARGIN'] )) {
|
||||
$aOD['OUT_DOC_LEFT_MARGIN'] = '15';
|
||||
}
|
||||
if (! isset( $aOD['OUT_DOC_RIGHT_MARGIN'] )) {
|
||||
$aOD['OUT_DOC_RIGHT_MARGIN'] = '15';
|
||||
}
|
||||
if (! isset( $aOD['OUT_DOC_TOP_MARGIN'] )) {
|
||||
$aOD['OUT_DOC_TOP_MARGIN'] = '15';
|
||||
}
|
||||
if (! isset( $aOD['OUT_DOC_BOTTOM_MARGIN'] )) {
|
||||
$aOD['OUT_DOC_BOTTOM_MARGIN'] = '15';
|
||||
}
|
||||
$aProperties['media'] = $aOD['OUT_DOC_MEDIA'];
|
||||
$aProperties['margins'] = array ('left' => $aOD['OUT_DOC_LEFT_MARGIN'],'right' => $aOD['OUT_DOC_RIGHT_MARGIN'],'top' => $aOD['OUT_DOC_TOP_MARGIN'],'bottom' => $aOD['OUT_DOC_BOTTOM_MARGIN']
|
||||
);
|
||||
if (isset($aOD['OUT_DOC_REPORT_GENERATOR'])) {
|
||||
$aProperties['report_generator'] = $aOD['OUT_DOC_REPORT_GENERATOR'];
|
||||
}
|
||||
$this->generate( $outputID, $Fields['APP_DATA'], $pathOutput, $sFilename, $aOD['OUT_DOC_TEMPLATE'], (boolean) $aOD['OUT_DOC_LANDSCAPE'], $aOD['OUT_DOC_GENERATE'], $aProperties , $applicationUid);
|
||||
//Plugin Hook PM_UPLOAD_DOCUMENT for upload document
|
||||
//G::LoadClass('plugin');
|
||||
$oPluginRegistry = & \PMPluginRegistry::getSingleton();
|
||||
if ($oPluginRegistry->existsTrigger( PM_UPLOAD_DOCUMENT ) && class_exists( 'uploadDocumentData' )) {
|
||||
$triggerDetail = $oPluginRegistry->getTriggerInfo( PM_UPLOAD_DOCUMENT );
|
||||
$aFields['APP_DOC_PLUGIN'] = $triggerDetail->sNamespace;
|
||||
$oAppDocument1 = new \AppDocument();
|
||||
$oAppDocument1->update( $aFields );
|
||||
$sPathName = PATH_DOCUMENT . \G::getPathFromUID($sApplication) . PATH_SEP;
|
||||
$oData['APP_UID'] = $sApplication;
|
||||
$oData['ATTACHMENT_FOLDER'] = true;
|
||||
switch ($aOD['OUT_DOC_GENERATE']) {
|
||||
case "BOTH":
|
||||
$documentData = new \uploadDocumentData( $sApplication, $sUserLogged, $pathOutput . $sFilename . '.pdf', $sFilename . '.pdf', $sDocUID, $oAppDocument->getDocVersion() );
|
||||
$documentData->sFileType = "PDF";
|
||||
$documentData->bUseOutputFolder = true;
|
||||
$uploadReturn = $oPluginRegistry->executeTriggers( PM_UPLOAD_DOCUMENT, $documentData );
|
||||
if ($uploadReturn) {
|
||||
//Only delete if the file was saved correctly
|
||||
unlink( $pathOutput . $sFilename . '.pdf' );
|
||||
}
|
||||
$documentData = new \uploadDocumentData( $sApplication, $sUserLogged, $pathOutput . $sFilename . '.doc', $sFilename . '.doc', $sDocUID, $oAppDocument->getDocVersion() );
|
||||
$documentData->sFileType = "DOC";
|
||||
$documentData->bUseOutputFolder = true;
|
||||
$uploadReturn = $oPluginRegistry->executeTriggers( PM_UPLOAD_DOCUMENT, $documentData );
|
||||
if ($uploadReturn) {
|
||||
//Only delete if the file was saved correctly
|
||||
unlink( $pathOutput . $sFilename . '.doc' );
|
||||
}
|
||||
break;
|
||||
case "PDF":
|
||||
$documentData = new \uploadDocumentData( $sApplication, $sUserLogged, $pathOutput . $sFilename . '.pdf', $sFilename . '.pdf', $sDocUID, $oAppDocument->getDocVersion() );
|
||||
$documentData->sFileType = "PDF";
|
||||
$documentData->bUseOutputFolder = true;
|
||||
$uploadReturn = $oPluginRegistry->executeTriggers( PM_UPLOAD_DOCUMENT, $documentData );
|
||||
if ($uploadReturn) {
|
||||
//Only delete if the file was saved correctly
|
||||
unlink( $pathOutput . $sFilename . '.pdf' );
|
||||
}
|
||||
break;
|
||||
case "DOC":
|
||||
$documentData = new \uploadDocumentData( $sApplication, $sUserLogged, $pathOutput . $sFilename . '.doc', $sFilename . '.doc', $sDocUID, $oAppDocument->getDocVersion() );
|
||||
$documentData->sFileType = "DOC";
|
||||
$documentData->bUseOutputFolder = true;
|
||||
$uploadReturn = $oPluginRegistry->executeTriggers( PM_UPLOAD_DOCUMENT, $documentData );
|
||||
if ($uploadReturn) {
|
||||
//Only delete if the file was saved correctly
|
||||
unlink( $pathOutput . $sFilename . '.doc' );
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
$g->sessionVarRestore();
|
||||
$response = $this->getCasesOutputDocument($applicationUid, $userUid, $sDocUID);
|
||||
return $response;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Generate the output document
|
||||
* @param string $sUID
|
||||
* @param array $aFields
|
||||
* @param string $sPath
|
||||
* @return variant
|
||||
*/
|
||||
public function generate($sUID, $aFields, $sPath, $sFilename, $sContent, $sLandscape = false, $sTypeDocToGener = 'BOTH', $aProperties = array(), $sApplication)
|
||||
{
|
||||
if (($sUID != '') && is_array($aFields) && ($sPath != '')) {
|
||||
$sContent = \G::replaceDataGridField($sContent, $aFields);
|
||||
\G::verifyPath($sPath, true);
|
||||
//Start - Create .doc
|
||||
$oFile = fopen($sPath . $sFilename . '.doc', 'wb');
|
||||
$size = array();
|
||||
$size["Letter"] = "216mm 279mm";
|
||||
$size["Legal"] = "216mm 357mm";
|
||||
$size["Executive"] = "184mm 267mm";
|
||||
$size["B5"] = "182mm 257mm";
|
||||
$size["Folio"] = "216mm 330mm";
|
||||
$size["A0Oversize"] = "882mm 1247mm";
|
||||
$size["A0"] = "841mm 1189mm";
|
||||
$size["A1"] = "594mm 841mm";
|
||||
$size["A2"] = "420mm 594mm";
|
||||
$size["A3"] = "297mm 420mm";
|
||||
$size["A4"] = "210mm 297mm";
|
||||
$size["A5"] = "148mm 210mm";
|
||||
$size["A6"] = "105mm 148mm";
|
||||
$size["A7"] = "74mm 105mm";
|
||||
$size["A8"] = "52mm 74mm";
|
||||
$size["A9"] = "37mm 52mm";
|
||||
$size["A10"] = "26mm 37mm";
|
||||
$size["Screenshot640"] = "640mm 480mm";
|
||||
$size["Screenshot800"] = "800mm 600mm";
|
||||
$size["Screenshot1024"] = "1024mm 768mm";
|
||||
$sizeLandscape["Letter"] = "279mm 216mm";
|
||||
$sizeLandscape["Legal"] = "357mm 216mm";
|
||||
$sizeLandscape["Executive"] = "267mm 184mm";
|
||||
$sizeLandscape["B5"] = "257mm 182mm";
|
||||
$sizeLandscape["Folio"] = "330mm 216mm";
|
||||
$sizeLandscape["A0Oversize"] = "1247mm 882mm";
|
||||
$sizeLandscape["A0"] = "1189mm 841mm";
|
||||
$sizeLandscape["A1"] = "841mm 594mm";
|
||||
$sizeLandscape["A2"] = "594mm 420mm";
|
||||
$sizeLandscape["A3"] = "420mm 297mm";
|
||||
$sizeLandscape["A4"] = "297mm 210mm";
|
||||
$sizeLandscape["A5"] = "210mm 148mm";
|
||||
$sizeLandscape["A6"] = "148mm 105mm";
|
||||
$sizeLandscape["A7"] = "105mm 74mm";
|
||||
$sizeLandscape["A8"] = "74mm 52mm";
|
||||
$sizeLandscape["A9"] = "52mm 37mm";
|
||||
$sizeLandscape["A10"] = "37mm 26mm";
|
||||
$sizeLandscape["Screenshot640"] = "480mm 640mm";
|
||||
$sizeLandscape["Screenshot800"] = "600mm 800mm";
|
||||
$sizeLandscape["Screenshot1024"] = "768mm 1024mm";
|
||||
if (!isset($aProperties['media'])) {
|
||||
$aProperties['media'] = 'Letter';
|
||||
}
|
||||
if ($sLandscape) {
|
||||
$media = $sizeLandscape[$aProperties['media']];
|
||||
} else {
|
||||
$media = $size[$aProperties['media']];
|
||||
}
|
||||
$marginLeft = '15';
|
||||
if (isset($aProperties['margins']['left'])) {
|
||||
$marginLeft = $aProperties['margins']['left'];
|
||||
}
|
||||
$marginRight = '15';
|
||||
if (isset($aProperties['margins']['right'])) {
|
||||
$marginRight = $aProperties['margins']['right'];
|
||||
}
|
||||
$marginTop = '15';
|
||||
if (isset($aProperties['margins']['top'])) {
|
||||
$marginTop = $aProperties['margins']['top'];
|
||||
}
|
||||
$marginBottom = '15';
|
||||
if (isset($aProperties['margins']['bottom'])) {
|
||||
$marginBottom = $aProperties['margins']['bottom'];
|
||||
}
|
||||
fwrite($oFile, '<html xmlns:v="urn:schemas-microsoft-com:vml"
|
||||
xmlns:o="urn:schemas-microsoft-com:office:office"
|
||||
xmlns:w="urn:schemas-microsoft-com:office:word"
|
||||
xmlns="http://www.w3.org/TR/REC-html40">
|
||||
<head>
|
||||
<meta http-equiv=Content-Type content="text/html; charset=utf-8">
|
||||
<meta name=ProgId content=Word.Document>
|
||||
<meta name=Generator content="Microsoft Word 9">
|
||||
<meta name=Originator content="Microsoft Word 9">
|
||||
<!--[if !mso]>
|
||||
<style>
|
||||
v\:* {behavior:url(#default#VML);}
|
||||
o\:* {behavior:url(#default#VML);}
|
||||
w\:* {behavior:url(#default#VML);}
|
||||
.shape {behavior:url(#default#VML);}
|
||||
</style>
|
||||
<![endif]-->
|
||||
<!--[if gte mso 9]><xml>
|
||||
<w:WordDocument>
|
||||
<w:View>Print</w:View>
|
||||
<w:DoNotHyphenateCaps/>
|
||||
<w:PunctuationKerning/>
|
||||
<w:DrawingGridHorizontalSpacing>9.35 pt</w:DrawingGridHorizontalSpacing>
|
||||
<w:DrawingGridVerticalSpacing>9.35 pt</w:DrawingGridVerticalSpacing>
|
||||
</w:WordDocument>
|
||||
</xml><![endif]-->
|
||||
|
||||
<style>
|
||||
<!--
|
||||
@page WordSection1
|
||||
{size:' . $media . ';
|
||||
margin-left:' . $marginLeft . 'mm;
|
||||
margin-right:' . $marginRight . 'mm;
|
||||
margin-bottom:' . $marginBottom . 'mm;
|
||||
margin-top:' . $marginTop . 'mm;
|
||||
mso-header-margin:35.4pt;
|
||||
mso-footer-margin:35.4pt;
|
||||
mso-paper-source:0;}
|
||||
div.WordSection1
|
||||
{page:WordSection1;}
|
||||
-->
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class=WordSection1>');
|
||||
fwrite($oFile, $sContent);
|
||||
fwrite($oFile, "\n</div></body></html>\n\n");
|
||||
fclose($oFile);
|
||||
/* End - Create .doc */
|
||||
if ($sTypeDocToGener == 'BOTH' || $sTypeDocToGener == 'PDF') {
|
||||
$oFile = fopen($sPath . $sFilename . '.html', 'wb');
|
||||
fwrite($oFile, $sContent);
|
||||
fclose($oFile);
|
||||
/* Start - Create .pdf */
|
||||
if (isset($aProperties['report_generator'])) {
|
||||
switch ($aProperties['report_generator']) {
|
||||
case 'TCPDF':
|
||||
$o = new \OutputDocument();
|
||||
if (strlen($sContent) == 0) {
|
||||
libxml_use_internal_errors(true);
|
||||
$o->generateTcpdf($sUID, $aFields, $sPath, $sFilename, ' ', $sLandscape, $aProperties);
|
||||
libxml_use_internal_errors(false);
|
||||
} else {
|
||||
$o->generateTcpdf($sUID, $aFields, $sPath, $sFilename, $sContent, $sLandscape, $aProperties);
|
||||
}
|
||||
break;
|
||||
case 'HTML2PDF':
|
||||
default:
|
||||
$this->generateHtml2ps_pdf($sUID, $aFields, $sPath, $sFilename, $sContent, $sLandscape, $aProperties, $sApplication);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
$this->generateHtml2ps_pdf($sUID, $aFields, $sPath, $sFilename, $sContent, $sLandscape, $aProperties);
|
||||
}
|
||||
}
|
||||
//end if $sTypeDocToGener
|
||||
/* End - Create .pdf */
|
||||
} else {
|
||||
return \PEAR::raiseError(
|
||||
null, G_ERROR_USER_UID, null, null, 'You tried to call to a generate method without send the Output Document UID, fields to use and the file path!', 'G_Error', true
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Generate Html2ps_pdf
|
||||
* @param string $sUID
|
||||
* @param array $aFields
|
||||
* @param string $sPath
|
||||
* @param string $sApplication
|
||||
* @return variant
|
||||
*/
|
||||
public function generateHtml2ps_pdf($sUID, $aFields, $sPath, $sFilename, $sContent, $sLandscape = false, $aProperties = array(), $sApplication)
|
||||
{
|
||||
define("MAX_FREE_FRACTION", 1);
|
||||
define('PATH_OUTPUT_FILE_DIRECTORY', PATH_HTML . 'files/' . $sApplication . '/outdocs/');
|
||||
\G::verifyPath(PATH_OUTPUT_FILE_DIRECTORY, true);
|
||||
require_once (PATH_THIRDPARTY . 'html2ps_pdf/config.inc.php');
|
||||
require_once (PATH_THIRDPARTY . 'html2ps_pdf/pipeline.factory.class.php');
|
||||
parse_config_file(PATH_THIRDPARTY . 'html2ps_pdf/html2ps.config');
|
||||
$GLOBALS['g_config'] = array(
|
||||
'cssmedia' => 'screen',
|
||||
'media' => 'Letter',
|
||||
'scalepoints' => false,
|
||||
'renderimages' => true,
|
||||
'renderfields' => true,
|
||||
'renderforms' => false,
|
||||
'pslevel' => 3,
|
||||
'renderlinks' => true,
|
||||
'pagewidth' => 800,
|
||||
'landscape' => $sLandscape,
|
||||
'method' => 'fpdf',
|
||||
'margins' => array('left' => 15, 'right' => 15, 'top' => 15, 'bottom' => 15,),
|
||||
'encoding' => '',
|
||||
'ps2pdf' => false,
|
||||
'compress' => true,
|
||||
'output' => 2,
|
||||
'pdfversion' => '1.3',
|
||||
'transparency_workaround' => false,
|
||||
'imagequality_workaround' => false,
|
||||
'draw_page_border' => isset($_REQUEST['pageborder']),
|
||||
'debugbox' => false,
|
||||
'html2xhtml' => true,
|
||||
'mode' => 'html',
|
||||
'smartpagebreak' => true
|
||||
);
|
||||
$GLOBALS['g_config'] = array_merge($GLOBALS['g_config'], $aProperties);
|
||||
$g_media = \Media::predefined($GLOBALS['g_config']['media']);
|
||||
$g_media->set_landscape($GLOBALS['g_config']['landscape']);
|
||||
$g_media->set_margins($GLOBALS['g_config']['margins']);
|
||||
$g_media->set_pixels($GLOBALS['g_config']['pagewidth']);
|
||||
if (isset($GLOBALS['g_config']['pdfSecurity'])) {
|
||||
if (isset($GLOBALS['g_config']['pdfSecurity']['openPassword']) &&
|
||||
$GLOBALS['g_config']['pdfSecurity']['openPassword'] != ""
|
||||
) {
|
||||
$GLOBALS['g_config']['pdfSecurity']['openPassword'] = G::decrypt(
|
||||
$GLOBALS['g_config']['pdfSecurity']['openPassword'], $sUID
|
||||
);
|
||||
}
|
||||
if (isset($GLOBALS['g_config']['pdfSecurity']['ownerPassword']) &&
|
||||
$GLOBALS['g_config']['pdfSecurity']['ownerPassword'] != ""
|
||||
) {
|
||||
$GLOBALS['g_config']['pdfSecurity']['ownerPassword'] = G::decrypt(
|
||||
$GLOBALS['g_config']['pdfSecurity']['ownerPassword'], $sUID
|
||||
);
|
||||
}
|
||||
$g_media->set_security($GLOBALS['g_config']['pdfSecurity']);
|
||||
require_once(HTML2PS_DIR . 'pdf.fpdf.encryption.php');
|
||||
}
|
||||
$pipeline = new \Pipeline();
|
||||
if (extension_loaded('curl')) {
|
||||
require_once(HTML2PS_DIR . 'fetcher.url.curl.class.php');
|
||||
$pipeline->fetchers = array(new \FetcherURLCurl());
|
||||
if (isset($proxy)) {
|
||||
if ($proxy != '') {
|
||||
$pipeline->fetchers[0]->set_proxy($proxy);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
require_once(HTML2PS_DIR . 'fetcher.url.class.php');
|
||||
$pipeline->fetchers[] = new \FetcherURL();
|
||||
}
|
||||
$pipeline->data_filters[] = new \DataFilterDoctype();
|
||||
$pipeline->data_filters[] = new \DataFilterUTF8($GLOBALS['g_config']['encoding']);
|
||||
if ($GLOBALS['g_config']['html2xhtml']) {
|
||||
$pipeline->data_filters[] = new \DataFilterHTML2XHTML();
|
||||
} else {
|
||||
$pipeline->data_filters[] = new \DataFilterXHTML2XHTML();
|
||||
}
|
||||
$pipeline->parser = new \ParserXHTML();
|
||||
$pipeline->pre_tree_filters = array();
|
||||
$header_html = '';
|
||||
$footer_html = '';
|
||||
$filter = new \PreTreeFilterHeaderFooter($header_html, $footer_html);
|
||||
$pipeline->pre_tree_filters[] = $filter;
|
||||
|
||||
if ($GLOBALS['g_config']['renderfields']) {
|
||||
$pipeline->pre_tree_filters[] = new \PreTreeFilterHTML2PSFields();
|
||||
}
|
||||
if ($GLOBALS['g_config']['method'] === 'ps') {
|
||||
$pipeline->layout_engine = new \LayoutEnginePS();
|
||||
} else {
|
||||
$pipeline->layout_engine = new \LayoutEngineDefault();
|
||||
}
|
||||
$pipeline->post_tree_filters = array();
|
||||
if ($GLOBALS['g_config']['pslevel'] == 3) {
|
||||
$image_encoder = new \PSL3ImageEncoderStream();
|
||||
} else {
|
||||
$image_encoder = new \PSL2ImageEncoderStream();
|
||||
}
|
||||
switch ($GLOBALS['g_config']['method']) {
|
||||
case 'fastps':
|
||||
if ($GLOBALS['g_config']['pslevel'] == 3) {
|
||||
$pipeline->output_driver = new \OutputDriverFastPS($image_encoder);
|
||||
} else {
|
||||
$pipeline->output_driver = new \OutputDriverFastPSLevel2($image_encoder);
|
||||
}
|
||||
break;
|
||||
case 'pdflib':
|
||||
$pipeline->output_driver = new \OutputDriverPDFLIB16($GLOBALS['g_config']['pdfversion']);
|
||||
break;
|
||||
case 'fpdf':
|
||||
$pipeline->output_driver = new \OutputDriverFPDF();
|
||||
break;
|
||||
case 'png':
|
||||
$pipeline->output_driver = new \OutputDriverPNG();
|
||||
break;
|
||||
case 'pcl':
|
||||
$pipeline->output_driver = new \OutputDriverPCL();
|
||||
break;
|
||||
default:
|
||||
die('Unknown output method');
|
||||
}
|
||||
if (isset($GLOBALS['g_config']['watermarkhtml'])) {
|
||||
$watermark_text = $GLOBALS['g_config']['watermarkhtml'];
|
||||
} else {
|
||||
$watermark_text = '';
|
||||
}
|
||||
$pipeline->output_driver->set_watermark($watermark_text);
|
||||
if ($watermark_text != '') {
|
||||
$dispatcher = & $pipeline->getDispatcher();
|
||||
}
|
||||
if ($GLOBALS['g_config']['debugbox']) {
|
||||
$pipeline->output_driver->set_debug_boxes(true);
|
||||
}
|
||||
if ($GLOBALS['g_config']['draw_page_border']) {
|
||||
$pipeline->output_driver->set_show_page_border(true);
|
||||
}
|
||||
if ($GLOBALS['g_config']['ps2pdf']) {
|
||||
$pipeline->output_filters[] = new \OutputFilterPS2PDF($GLOBALS['g_config']['pdfversion']);
|
||||
}
|
||||
if ($GLOBALS['g_config']['compress'] && $GLOBALS['g_config']['method'] == 'fastps') {
|
||||
$pipeline->output_filters[] = new \OutputFilterGZip();
|
||||
}
|
||||
if (!isset($GLOBALS['g_config']['process_mode'])) {
|
||||
$GLOBALS['g_config']['process_mode'] = '';
|
||||
}
|
||||
if ($GLOBALS['g_config']['process_mode'] == 'batch') {
|
||||
$filename = 'batch';
|
||||
} else {
|
||||
$filename = $sFilename;
|
||||
}
|
||||
switch ($GLOBALS['g_config']['output']) {
|
||||
case 0:
|
||||
$pipeline->destination = new \DestinationBrowser($filename);
|
||||
break;
|
||||
case 1:
|
||||
$pipeline->destination = new \DestinationDownload($filename);
|
||||
break;
|
||||
case 2:
|
||||
$pipeline->destination = new \DestinationFile($filename);
|
||||
break;
|
||||
}
|
||||
copy($sPath . $sFilename . '.html', PATH_OUTPUT_FILE_DIRECTORY . $sFilename . '.html');
|
||||
try {
|
||||
$status = $pipeline->process(((isset($_SERVER['HTTPS'])) && ($_SERVER['HTTPS'] == 'on') ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . '/files/' . $sApplication . '/outdocs/' . $sFilename . '.html', $g_media);
|
||||
copy(PATH_OUTPUT_FILE_DIRECTORY . $sFilename . '.pdf', $sPath . $sFilename . '.pdf');
|
||||
unlink(PATH_OUTPUT_FILE_DIRECTORY . $sFilename . '.pdf');
|
||||
unlink(PATH_OUTPUT_FILE_DIRECTORY . $sFilename . '.html');
|
||||
} catch (\Exception $e) {
|
||||
if ($e->getMessage() == 'ID_OUTPUT_NOT_GENERATE') {
|
||||
include_once 'classes/model/AppDocument.php';
|
||||
$dataDocument = explode('_', $sFilename);
|
||||
if (!isset($dataDocument[1])) {
|
||||
$dataDocument[1] = 1;
|
||||
}
|
||||
$oAppDocument = new \AppDocument();
|
||||
$oAppDocument->remove($dataDocument[0], $dataDocument[1]);
|
||||
\G::SendTemporalMessage(\G::LoadTranslation('ID_OUTPUT_NOT_GENERATE'), 'Error');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,377 @@
|
||||
<?php
|
||||
namespace ProcessMaker\BusinessModel;
|
||||
|
||||
use \G;
|
||||
use \DbSource;
|
||||
use \dbConnections;
|
||||
|
||||
class DataBaseConnection
|
||||
{
|
||||
/**
|
||||
* List of DataBaseConnections in process
|
||||
* @var string $pro_uid. Uid for Process
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDataBaseConnections($pro_uid)
|
||||
{
|
||||
$pro_uid = $this->validateProUid($pro_uid);
|
||||
|
||||
$oDBSource = new DbSource();
|
||||
$oCriteria = $oDBSource->getCriteriaDBSList($pro_uid);
|
||||
|
||||
$rs = \DbSourcePeer::doSelectRS($oCriteria);
|
||||
$rs->setFetchmode( \ResultSet::FETCHMODE_ASSOC );
|
||||
$rs->next();
|
||||
|
||||
$dbConnecions = array();
|
||||
while ($row = $rs->getRow()) {
|
||||
$row = array_change_key_case($row, CASE_LOWER);
|
||||
$dataDb = $this->getDataBaseConnection($pro_uid, $row['dbs_uid'], false);
|
||||
$dbConnecions[] = array_change_key_case($dataDb, CASE_LOWER);
|
||||
$rs->next();
|
||||
}
|
||||
return $dbConnecions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data for DataBaseConnection
|
||||
* @var string $pro_uid. Uid for Process
|
||||
* @var string $dbs_uid. Uid for Data Base Connection
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* return object
|
||||
*/
|
||||
public function getDataBaseConnection($pro_uid, $dbs_uid, $validate = true)
|
||||
{
|
||||
try {
|
||||
if ($validate) {
|
||||
$pro_uid = $this->validateProUid($pro_uid);
|
||||
$dbs_uid = $this->validateDbsUid($dbs_uid, $pro_uid);
|
||||
}
|
||||
|
||||
G::LoadClass( 'dbConnections' );
|
||||
$dbs = new dbConnections($pro_uid);
|
||||
$oDBConnection = new DbSource();
|
||||
$aFields = $oDBConnection->load($dbs_uid, $pro_uid);
|
||||
if ($aFields['DBS_PORT'] == '0') {
|
||||
$aFields['DBS_PORT'] = '';
|
||||
}
|
||||
$aFields['DBS_PASSWORD'] = $dbs->getPassWithoutEncrypt($aFields);
|
||||
|
||||
$response = array_change_key_case($aFields, CASE_LOWER);
|
||||
return $response;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save Data for DataBaseConnection
|
||||
* @var string $pro_uid. Uid for Process
|
||||
* @var string $dataDataBaseConnection. Data for DataBaseConnection
|
||||
* @var string $create. Create o Update DataBaseConnection
|
||||
* @var string $sDataBaseConnectionUid. Uid for DataBaseConnection
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function saveDataBaseConnection($pro_uid = '', $dataDBConnection = array(), $create = false)
|
||||
{
|
||||
$pro_uid = $this->validateProUid($pro_uid);
|
||||
if (!$create) {
|
||||
$dbs_uid = $dataDBConnection['dbs_uid'];
|
||||
$dbs_uid = $this->validateDbsUid($dbs_uid, $pro_uid);
|
||||
}
|
||||
|
||||
G::LoadClass('dbConnections');
|
||||
$oDBSource = new DbSource();
|
||||
$oContent = new \Content();
|
||||
$dataDBConnection = array_change_key_case($dataDBConnection, CASE_UPPER);
|
||||
|
||||
$dataDBConnection['PRO_UID'] = $pro_uid;
|
||||
|
||||
if (isset($dataDBConnection['DBS_TYPE'])) {
|
||||
$typesExists = array();
|
||||
$dbServices = $this->getDbEngines();
|
||||
foreach ($dbServices as $value) {
|
||||
$typesExists[] = $value['id'];
|
||||
}
|
||||
if (!in_array($dataDBConnection['DBS_TYPE'], $typesExists)) {
|
||||
throw (new \Exception("The dababase connection with dbs_type: '" . $dataDBConnection['DBS_TYPE'] . " is invalid"));
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($dataDBConnection['DBS_SERVER']) && $dataDBConnection['DBS_SERVER'] == '') {
|
||||
throw (new \Exception("The dababase connection with dbs_server: '" . $dataDBConnection['DBS_SERVER'] . "', is invalid"));
|
||||
}
|
||||
|
||||
if (isset($dataDBConnection['DBS_DATABASE_NAME']) && $dataDBConnection['DBS_DATABASE_NAME'] == '') {
|
||||
throw (new \Exception("The dababase connection with dbs_database_name: '" . $dataDBConnection['DBS_DATABASE_NAME'] . "', is invalid"));
|
||||
}
|
||||
|
||||
if (isset($dataDBConnection['DBS_PORT']) &&
|
||||
($dataDBConnection['DBS_PORT'] == ''|| $dataDBConnection['DBS_PORT'] == 0)) {
|
||||
throw (new \Exception("The dababase connection with dbs_port: '" . $dataDBConnection['DBS_PORT'] . "', is invalid"));
|
||||
}
|
||||
|
||||
if (isset($dataDBConnection['DBS_ENCODE'])) {
|
||||
$encodesExists = array();
|
||||
$dbs = new dbConnections();
|
||||
$dbEncodes = $dbs->getEncondeList($dataDBConnection['DBS_TYPE']);
|
||||
foreach ($dbEncodes as $value) {
|
||||
$encodesExists[] = $value['0'];
|
||||
}
|
||||
if (!in_array($dataDBConnection['DBS_ENCODE'], $encodesExists)) {
|
||||
throw (new \Exception( "The dababase connection with dbs_encode: '" . $dataDBConnection['DBS_ENCODE'] . "', is invalid" ));
|
||||
}
|
||||
}
|
||||
|
||||
$passOrigin = '';
|
||||
if (isset($dataDBConnection['DBS_PASSWORD'])) {
|
||||
$passOrigin = $dataDBConnection['DBS_PASSWORD'];
|
||||
if ($dataDBConnection['DBS_PASSWORD'] == 'none') {
|
||||
$dataDBConnection['DBS_PASSWORD'] = '';
|
||||
} else {
|
||||
$pass = G::encrypt( $dataDBConnection['DBS_PASSWORD'], $dataDBConnection['DBS_DATABASE_NAME']) . "_2NnV3ujj3w";
|
||||
$dataDBConnection['DBS_PASSWORD'] = $pass;
|
||||
}
|
||||
}
|
||||
|
||||
if ($create) {
|
||||
unset($dataDBConnection['DBS_UID']);
|
||||
// TEST CONNECTION
|
||||
$dataTest = array_merge($dataDBConnection, array('DBS_PASSWORD' => $passOrigin));
|
||||
$resTest = $this->testConnection($dataTest);
|
||||
if (!$resTest['resp']) {
|
||||
throw (new \Exception($resTest['message']));
|
||||
}
|
||||
$newDBConnectionUid = $oDBSource->create($dataDBConnection);
|
||||
$oContent->addContent('DBS_DESCRIPTION', '', $newDBConnectionUid,
|
||||
SYS_LANG, $dataDBConnection['DBS_DESCRIPTION'] );
|
||||
$newDataDBConnection = $this->getDataBaseConnection($pro_uid, $newDBConnectionUid);
|
||||
$newDataDBConnection = array_change_key_case($newDataDBConnection, CASE_LOWER);
|
||||
return $newDataDBConnection;
|
||||
} else {
|
||||
// TEST CONNECTION
|
||||
$allData = $this->getDataBaseConnection($pro_uid, $dataDBConnection['DBS_UID']);
|
||||
$dataTest = array_merge($allData, $dataDBConnection, array('DBS_PASSWORD' => $passOrigin));
|
||||
$resTest = $this->testConnection($dataTest);
|
||||
if (!$resTest['resp']) {
|
||||
throw (new \Exception($resTest['message']));
|
||||
}
|
||||
$oDBSource->update($dataDBConnection);
|
||||
if (isset($dataDBConnection['DBS_DESCRIPTION'])) {
|
||||
$oContent->addContent('DBS_DESCRIPTION', '', $dataDBConnection['DBS_UID'],
|
||||
SYS_LANG, $dataDBConnection['DBS_DESCRIPTION'] );
|
||||
}
|
||||
}
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete DataBaseConnection
|
||||
* @var string $pro_uid. Uid for Process
|
||||
* @var string $dbs_uid. Uid for DataBase Connection
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteDataBaseConnection($pro_uid, $dbs_uid)
|
||||
{
|
||||
$pro_uid = $this->validateProUid($pro_uid);
|
||||
$dbs_uid = $this->validateDbsUid($dbs_uid, $pro_uid);
|
||||
|
||||
$oDBSource = new DbSource();
|
||||
$oContent = new \Content();
|
||||
|
||||
$oDBSource->remove($dbs_uid, $pro_uid);
|
||||
$oContent->removeContent( 'DBS_DESCRIPTION', "", $dbs_uid );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test DataBase Connection
|
||||
* @var string $dataCon. Data for DataBase Connection
|
||||
* @var string $returnArray. Flag for url
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testConnection($dataCon, $returnArray = false)
|
||||
{
|
||||
$resp = array();
|
||||
$respTest = array();
|
||||
$resp['resp'] = false;
|
||||
|
||||
$dataCon = array_change_key_case($dataCon, CASE_UPPER);
|
||||
|
||||
G::LoadClass( 'net' );
|
||||
$Server = new \NET($dataCon['DBS_SERVER']);
|
||||
|
||||
// STEP 1 : Resolving Host Name
|
||||
$respTest['0'] = array();
|
||||
$respTest['0']['test'] = 'Resolving Host Name ' . $dataCon['DBS_SERVER'];
|
||||
if ($Server->getErrno() != 0) {
|
||||
if ($returnArray) {
|
||||
$respTest['0']['error'] = "Error Testing Connection: Resolving Host Name FAILED : " . $Server->error;
|
||||
} else {
|
||||
$resp['message'] = "Error Testing Connection: Resolving Host Name FAILED : " . $Server->error;
|
||||
return $resp;
|
||||
}
|
||||
}
|
||||
|
||||
// STEP 2 : Checking port
|
||||
$respTest['1'] = array();
|
||||
$respTest['1']['test'] = 'Checking port ' . $dataCon['DBS_PORT'];
|
||||
$Server->scannPort($dataCon['DBS_PORT']);
|
||||
if ($Server->getErrno() != 0) {
|
||||
if ($returnArray) {
|
||||
$respTest['1']['error'] = "Error Testing Connection: Checking port FAILED : " . $Server->error;
|
||||
} else {
|
||||
$resp['message'] = "Error Testing Connection: Checking port FAILED : " . $Server->error;
|
||||
return $resp;
|
||||
}
|
||||
}
|
||||
|
||||
// STEP 3 : Trying to connect to host
|
||||
$respTest['2'] = array();
|
||||
$respTest['2']['test'] = 'Trying to connect to host ' . $dataCon['DBS_SERVER'] . (($dataCon['DBS_PORT'] != '') ? ':'.$dataCon['DBS_PORT'] : '');
|
||||
$Server->loginDbServer($dataCon['DBS_USERNAME'], $dataCon['DBS_PASSWORD']);
|
||||
$Server->setDataBase($dataCon['DBS_DATABASE_NAME'], $dataCon['DBS_PORT']);
|
||||
if ($Server->errno == 0) {
|
||||
$response = $Server->tryConnectServer($dataCon['DBS_TYPE']);
|
||||
if ($response->status != 'SUCCESS') {
|
||||
if ($returnArray) {
|
||||
$respTest['2']['error'] = "Error Testing Connection: Trying to connect to host FAILED : " . $Server->error;
|
||||
} else {
|
||||
$resp['message'] = "Error Testing Connection: Trying to connect to host FAILED : " . $Server->error;
|
||||
return $resp;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ($returnArray) {
|
||||
$respTest['2']['error'] = "Error Testing Connection: Trying to connect to host FAILED : " . $Server->error;
|
||||
} else {
|
||||
$resp['message'] = "Error Testing Connection: Trying to connect to host FAILED : " . $Server->error;
|
||||
return $resp;
|
||||
}
|
||||
}
|
||||
|
||||
// STEP 4 : Trying to open database
|
||||
$respTest['3'] = array();
|
||||
$respTest['3']['test'] = 'Trying to open database [' . $dataCon['DBS_DATABASE_NAME'] . ']';
|
||||
$Server->loginDbServer($dataCon['DBS_USERNAME'], $dataCon['DBS_PASSWORD']);
|
||||
$Server->setDataBase($dataCon['DBS_DATABASE_NAME'], $dataCon['DBS_PORT']);
|
||||
if ($Server->errno == 0) {
|
||||
$response = $Server->tryConnectServer($dataCon['DBS_TYPE']);
|
||||
if ($response->status == 'SUCCESS') {
|
||||
$response = $Server->tryOpenDataBase($dataCon['DBS_TYPE']);
|
||||
if ($response->status != 'SUCCESS') {
|
||||
if ($returnArray) {
|
||||
$respTest['3']['error'] = "Error Testing Connection: Trying to open database FAILED : " . $Server->error;
|
||||
} else {
|
||||
$resp['message'] = "Error Testing Connection: Trying to open database FAILED : " . $Server->error;
|
||||
return $resp;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ($returnArray) {
|
||||
$respTest['3']['error'] = "Error Testing Connection: Trying to open database FAILED : " . $Server->error;
|
||||
} else {
|
||||
$resp['message'] = "Error Testing Connection: Trying to open database FAILED : " . $Server->error;
|
||||
return $resp;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ($returnArray) {
|
||||
$respTest['3']['error'] = "Error Testing Connection: Trying to open database FAILED : " . $Server->error;
|
||||
} else {
|
||||
$resp['message'] = "Error Testing Connection: Trying to open database FAILED : " . $Server->error;
|
||||
return $resp;
|
||||
}
|
||||
}
|
||||
|
||||
if ($returnArray) {
|
||||
return $respTest;
|
||||
} else {
|
||||
// CORRECT CONNECTION
|
||||
$resp['resp'] = true;
|
||||
return $resp;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Data Base Engines
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDbEngines ()
|
||||
{
|
||||
if (!class_exists('dbConnections')) {
|
||||
G::LoadClass('dbConnections');
|
||||
}
|
||||
$dbs = new dbConnections();
|
||||
$dbServices = $dbs->getDbServicesAvailables();
|
||||
return $dbServices;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate Process Uid
|
||||
* @var string $pro_uid. Uid for process
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function validateProUid ($pro_uid)
|
||||
{
|
||||
$pro_uid = trim($pro_uid);
|
||||
if ($pro_uid == '') {
|
||||
throw (new \Exception("The project with prj_uid: '', does not exist."));
|
||||
}
|
||||
$oProcess = new \Process();
|
||||
if (!($oProcess->processExists($pro_uid))) {
|
||||
throw (new \Exception("The project with prj_uid: '$pro_uid', does not exist."));
|
||||
}
|
||||
return $pro_uid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate DataBase Connection Uid
|
||||
* @var string $pro_uid. Uid for process
|
||||
* @var string $dbs_uid. Uid for process
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function validateDbsUid ($dbs_uid, $pro_uid)
|
||||
{
|
||||
$dbs_uid = trim($dbs_uid);
|
||||
if ($dbs_uid == '') {
|
||||
throw (new \Exception("The database connection with dbs_uid: '', does not exist."));
|
||||
}
|
||||
$oDBSource = new DbSource();
|
||||
if (!($oDBSource->Exists($dbs_uid, $pro_uid))) {
|
||||
throw (new \Exception("The database connection with dbs_uid: '$dbs_uid', does not exist."));
|
||||
}
|
||||
return $dbs_uid;
|
||||
}
|
||||
}
|
||||
|
||||
185
workflow/engine/src/ProcessMaker/BusinessModel/Department.php
Normal file
185
workflow/engine/src/ProcessMaker/BusinessModel/Department.php
Normal file
@@ -0,0 +1,185 @@
|
||||
<?php
|
||||
namespace ProcessMaker\BusinessModel;
|
||||
|
||||
use \G;
|
||||
use \UsersPeer;
|
||||
use \DepartmentPeer;
|
||||
|
||||
/**
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*/
|
||||
class Department
|
||||
{
|
||||
/**
|
||||
* Get list for Departments
|
||||
*
|
||||
* @access public
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDepartments()
|
||||
{
|
||||
$oDepartment = new \Department();
|
||||
$aDepts = $oDepartment->getDepartments('');
|
||||
foreach ($aDepts as &$depData) {
|
||||
$depData['DEP_CHILDREN'] = $this->getChildren($depData);
|
||||
$depData = array_change_key_case($depData, CASE_LOWER);
|
||||
}
|
||||
return $aDepts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list for Departments
|
||||
* @var string $dep_uid. Uid for Department
|
||||
*
|
||||
* @access public
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDepartment($dep_uid)
|
||||
{
|
||||
$dep_uid = Validator::depUid($dep_uid);
|
||||
$criteria = new \Criteria( 'workflow' );
|
||||
$criteria->add( DepartmentPeer::DEP_UID, $dep_uid, \Criteria::EQUAL );
|
||||
$con = \Propel::getConnection( DepartmentPeer::DATABASE_NAME );
|
||||
$objects = DepartmentPeer::doSelect( $criteria, $con );
|
||||
$oUsers = new \Users();
|
||||
|
||||
$node = array ();
|
||||
foreach ($objects as $oDepartment) {
|
||||
$node['DEP_UID'] = $oDepartment->getDepUid();
|
||||
$node['DEP_PARENT'] = $oDepartment->getDepParent();
|
||||
$node['DEP_TITLE'] = $oDepartment->getDepTitle();
|
||||
$node['DEP_STATUS'] = $oDepartment->getDepStatus();
|
||||
$node['DEP_MANAGER'] = $oDepartment->getDepManager();
|
||||
$node['DEP_LDAP_DN'] = $oDepartment->getDepLdapDn();
|
||||
$node['DEP_LAST'] = 0;
|
||||
|
||||
$manager = $oDepartment->getDepManager();
|
||||
if ($manager != '') {
|
||||
$UserUID = $oUsers->load($manager);
|
||||
$node['DEP_MANAGER_USERNAME'] = isset( $UserUID['USR_USERNAME'] ) ? $UserUID['USR_USERNAME'] : '';
|
||||
$node['DEP_MANAGER_FIRSTNAME'] = isset( $UserUID['USR_FIRSTNAME'] ) ? $UserUID['USR_FIRSTNAME'] : '';
|
||||
$node['DEP_MANAGER_LASTNAME'] = isset( $UserUID['USR_LASTNAME'] ) ? $UserUID['USR_LASTNAME'] : '';
|
||||
} else {
|
||||
$node['DEP_MANAGER_USERNAME'] = '';
|
||||
$node['DEP_MANAGER_FIRSTNAME'] = '';
|
||||
$node['DEP_MANAGER_LASTNAME'] = '';
|
||||
}
|
||||
|
||||
$criteriaCount = new \Criteria( 'workflow' );
|
||||
$criteriaCount->clearSelectColumns();
|
||||
$criteriaCount->addSelectColumn( 'COUNT(*)' );
|
||||
$criteriaCount->add( DepartmentPeer::DEP_PARENT, $oDepartment->getDepUid(), \Criteria::EQUAL );
|
||||
$rs = DepartmentPeer::doSelectRS( $criteriaCount );
|
||||
$rs->next();
|
||||
$row = $rs->getRow();
|
||||
$node['HAS_CHILDREN'] = $row[0];
|
||||
}
|
||||
$node = array_change_key_case($node, CASE_LOWER);
|
||||
return $node;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save Department
|
||||
* @var string $dep_data. Data for Process
|
||||
* @var string $create. Flag for create or update
|
||||
*
|
||||
* @access public
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function saveDepartment($dep_data, $create = true)
|
||||
{
|
||||
Validator::isArray($dep_data, '$dep_data');
|
||||
Validator::isNotEmpty($dep_data, '$dep_data');
|
||||
Validator::isBoolean($create, '$create');
|
||||
|
||||
$dep_data = array_change_key_case($dep_data, CASE_UPPER);
|
||||
$oDepartment = new \Department();
|
||||
if (isset($dep_data['DEP_UID']) && $dep_data['DEP_UID'] != '') {
|
||||
Validator::depUid($dep_data['DEP_UID']);
|
||||
}
|
||||
if (isset($dep_data['DEP_PARENT']) && $dep_data['DEP_PARENT'] != '') {
|
||||
Validator::depUid($dep_data['DEP_PARENT'], 'dep_parent');
|
||||
}
|
||||
if (isset($dep_data['DEP_MANAGER']) && $dep_data['DEP_MANAGER'] != '') {
|
||||
Validator::usrUid($dep_data['DEP_MANAGER'], 'dep_manager');
|
||||
}
|
||||
if (isset($dep_data['DEP_STATUS'])) {
|
||||
Validator::depStatus($dep_data['DEP_STATUS']);
|
||||
}
|
||||
|
||||
if (!$create) {
|
||||
$dep_data['DEPO_TITLE'] = $dep_data['DEP_TITLE'];
|
||||
if (isset($dep_data['DEP_TITLE'])) {
|
||||
Validator::depTitle($dep_data['DEP_TITLE'], $dep_data['DEP_UID']);
|
||||
}
|
||||
$oDepartment->update($dep_data);
|
||||
$oDepartment->updateDepartmentManager($dep_data['DEP_UID']);
|
||||
} else {
|
||||
if (isset($dep_data['DEP_TITLE'])) {
|
||||
Validator::depTitle($dep_data['DEP_TITLE']);
|
||||
} else {
|
||||
throw (new \Exception("The field dep_title is required."));
|
||||
}
|
||||
$dep_uid = $oDepartment->create($dep_data);
|
||||
$response = $this->getDepartment($dep_uid);
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete department
|
||||
* @var string $dep_uid. Uid for department
|
||||
*
|
||||
* @access public
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function deleteDepartment($dep_uid)
|
||||
{
|
||||
$dep_uid = Validator::depUid($dep_uid);
|
||||
$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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Look for Children for department
|
||||
* @var array $dataDep. Data for child department
|
||||
*
|
||||
* @access public
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getChildren ($dataDep)
|
||||
{
|
||||
$children = array();
|
||||
if ((int)$dataDep['HAS_CHILDREN'] > 0) {
|
||||
$oDepartment = new \Department();
|
||||
$aDepts = $oDepartment->getDepartments($dataDep['DEP_UID']);
|
||||
foreach ($aDepts as &$depData) {
|
||||
$depData['DEP_CHILDREN'] = $this->getChildren($depData);
|
||||
$depData = array_change_key_case($depData, CASE_LOWER);
|
||||
$children[] = $depData;
|
||||
}
|
||||
}
|
||||
return $children;
|
||||
}
|
||||
}
|
||||
|
||||
1000
workflow/engine/src/ProcessMaker/BusinessModel/DynaForm.php
Normal file
1000
workflow/engine/src/ProcessMaker/BusinessModel/DynaForm.php
Normal file
File diff suppressed because it is too large
Load Diff
258
workflow/engine/src/ProcessMaker/BusinessModel/Event.php
Normal file
258
workflow/engine/src/ProcessMaker/BusinessModel/Event.php
Normal file
@@ -0,0 +1,258 @@
|
||||
<?php
|
||||
namespace ProcessMaker\BusinessModel;
|
||||
|
||||
/**
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*/
|
||||
class Event
|
||||
{
|
||||
/**
|
||||
* Get list for Events
|
||||
* @var string $pro_uid. Uid for Process
|
||||
* @var string $filter.
|
||||
* @var string $evn_uid. Uid for Process
|
||||
*
|
||||
* @access public
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getEvents($pro_uid, $filter = '', $evn_uid = '')
|
||||
{
|
||||
$pro_uid = $this->validateProUid($pro_uid);
|
||||
if ($evn_uid != '') {
|
||||
$evn_uid = $this->validateEvnUid($evn_uid);
|
||||
}
|
||||
|
||||
$oProcess = new \Process();
|
||||
if (!($oProcess->processExists($pro_uid))) {
|
||||
throw (new \Exception( 'This process does not exist!' ));
|
||||
}
|
||||
|
||||
$sDelimiter = \DBAdapter::getStringDelimiter();
|
||||
$oCriteria = new \Criteria('workflow');
|
||||
$oCriteria->addSelectColumn(\EventPeer::EVN_UID);
|
||||
$oCriteria->addSelectColumn(\EventPeer::EVN_ACTION);
|
||||
$oCriteria->addSelectColumn(\EventPeer::EVN_STATUS);
|
||||
$oCriteria->addSelectColumn(\EventPeer::EVN_WHEN_OCCURS);
|
||||
$oCriteria->addSelectColumn(\EventPeer::EVN_RELATED_TO);
|
||||
|
||||
$oCriteria->addAsColumn('EVN_DESCRIPTION', \ContentPeer::CON_VALUE);
|
||||
$aConditions = array();
|
||||
$aConditions[] = array(\EventPeer::EVN_UID, \ContentPeer::CON_ID );
|
||||
$aConditions[] = array(\ContentPeer::CON_CATEGORY, $sDelimiter . 'EVN_DESCRIPTION' . $sDelimiter );
|
||||
$aConditions[] = array(\ContentPeer::CON_LANG, $sDelimiter . SYS_LANG . $sDelimiter );
|
||||
$oCriteria->addJoinMC($aConditions, \Criteria::LEFT_JOIN);
|
||||
$oCriteria->add(\EventPeer::PRO_UID, $pro_uid);
|
||||
if ($evn_uid != '') {
|
||||
$oCriteria->add(\EventPeer::EVN_UID, $evn_uid);
|
||||
}
|
||||
|
||||
switch ($filter) {
|
||||
case 'message':
|
||||
$oCriteria->add(\EventPeer::EVN_ACTION, "SEND_MESSAGE");
|
||||
break;
|
||||
case 'conditional':
|
||||
$oCriteria->add(\EventPeer::EVN_ACTION, "EXECUTE_CONDITIONAL_TRIGGER");
|
||||
break;
|
||||
case 'multiple':
|
||||
$oCriteria->add(\EventPeer::EVN_ACTION, "EXECUTE_TRIGGER");
|
||||
break;
|
||||
}
|
||||
$eventsArray = array();
|
||||
|
||||
$oDataset = \EventPeer::doSelectRS($oCriteria);
|
||||
$oDataset->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
$oDataset->next();
|
||||
while ($aRow = $oDataset->getRow()) {
|
||||
$oEvent = new \Event();
|
||||
$aFields = $oEvent->load( $aRow['EVN_UID'] );
|
||||
$aRow = array_merge($aRow, $aFields);
|
||||
$eventsArray[] = array_change_key_case($aRow, CASE_LOWER);
|
||||
$oDataset->next();
|
||||
}
|
||||
|
||||
if ($evn_uid != '' && empty($eventsArray)) {
|
||||
throw (new \Exception( 'This row does not exist!' ));
|
||||
} elseif ($evn_uid != '' && !empty($eventsArray)) {
|
||||
return current($eventsArray);
|
||||
}
|
||||
return $eventsArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save Event Post Put
|
||||
*
|
||||
* @param string $evn_uid
|
||||
*
|
||||
* @access public
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function saveEvents($pro_uid, $dataEvent, $create = false)
|
||||
{
|
||||
$pro_uid = $this->validateProUid($pro_uid);
|
||||
if (!$create) {
|
||||
$dataEvent['evn_uid'] = $this->validateEvnUid($dataEvent['evn_uid']);
|
||||
}
|
||||
|
||||
if ( ($pro_uid == '') || (count($dataEvent) == 0) ) {
|
||||
return false;
|
||||
}
|
||||
$dataEvent = array_change_key_case($dataEvent, CASE_UPPER);
|
||||
if ($dataEvent['EVN_RELATED_TO'] == 'SINGLE') {
|
||||
if (empty($dataEvent['TAS_UID'])) {
|
||||
throw (new \Exception('The field "tas_uid" is required!'));
|
||||
}
|
||||
$this->validateTasUid($dataEvent['TAS_UID']);
|
||||
} else {
|
||||
if (empty($dataEvent['EVN_TAS_UID_FROM'])) {
|
||||
throw (new \Exception('The field "evn_tas_uid_from" is required!'));
|
||||
}
|
||||
$this->validateTasUid($dataEvent['EVN_TAS_UID_FROM']);
|
||||
$dataEvent['TAS_UID'] = $dataEvent['EVN_TAS_UID_FROM'];
|
||||
|
||||
if (empty($dataEvent['EVN_TAS_UID_TO'])) {
|
||||
throw (new \Exception('The field "evn_tas_uid_to" is required!'));
|
||||
}
|
||||
$this->validateTasUid($dataEvent['EVN_TAS_UID_TO']);
|
||||
}
|
||||
|
||||
$this->validateTriUid($dataEvent['TRI_UID']);
|
||||
if ( $create && (isset($dataEvent['EVN_UID'])) ) {
|
||||
unset($dataEvent['EVN_UID']);
|
||||
}
|
||||
|
||||
$dataEvent['PRO_UID'] = $pro_uid;
|
||||
$oEvent = new \Event();
|
||||
|
||||
if ($create) {
|
||||
$uidNewEvent = $oEvent->create( $dataEvent );
|
||||
$dataEvent = $this->getEvents($pro_uid, '', $uidNewEvent);
|
||||
$dataEvent = array_change_key_case($dataEvent, CASE_LOWER);
|
||||
return $dataEvent;
|
||||
} else {
|
||||
$oEvent->update( $dataEvent );
|
||||
$uidNewEvent = $dataEvent['EVN_UID'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete Event
|
||||
*
|
||||
* @param string $evn_uid
|
||||
*
|
||||
* @access public
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteEvent($pro_uid, $evn_uid)
|
||||
{
|
||||
$pro_uid = $this->validateProUid($pro_uid);
|
||||
$evn_uid = $this->validateEvnUid($evn_uid);
|
||||
|
||||
try {
|
||||
$oEvent = new \Event();
|
||||
$oEvent->remove( $evn_uid );
|
||||
} catch (Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate Process Uid
|
||||
* @var string $pro_uid. Uid for process
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function validateProUid ($pro_uid)
|
||||
{
|
||||
$pro_uid = trim($pro_uid);
|
||||
if ($pro_uid == '') {
|
||||
throw (new \Exception("The project with prj_uid: '', does not exist."));
|
||||
}
|
||||
$oProcess = new \Process();
|
||||
if (!($oProcess->processExists($pro_uid))) {
|
||||
throw (new \Exception("The project with prj_uid: '$pro_uid', does not exist."));
|
||||
}
|
||||
return $pro_uid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate Event Uid
|
||||
* @var string $evn_uid. Uid for event
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function validateEvnUid ($evn_uid)
|
||||
{
|
||||
$evn_uid = trim($evn_uid);
|
||||
if ($evn_uid == '') {
|
||||
throw (new \Exception("The event with evn_uid: '', does not exist."));
|
||||
}
|
||||
$oEvent = new \Event();
|
||||
if (!($oEvent->Exists($evn_uid))) {
|
||||
throw (new \Exception("The event with evn_uid: '$evn_uid', does not exist."));
|
||||
}
|
||||
return $evn_uid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate Task Uid
|
||||
* @var string $tas_uid. Uid for task
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function validateTasUid($tas_uid)
|
||||
{
|
||||
$tas_uid = trim($tas_uid);
|
||||
if ($tas_uid == '') {
|
||||
throw (new \Exception("The task with tas_uid: '', does not exist."));
|
||||
}
|
||||
$oTask = new \Task();
|
||||
if (!($oTask->taskExists($tas_uid))) {
|
||||
throw (new \Exception("The task with tas_uid: '$tas_uid', does not exist."));
|
||||
}
|
||||
return $tas_uid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate Trigger Uid
|
||||
* @var string $tri_uid. Uid for trigger
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function validateTriUid($tri_uid)
|
||||
{
|
||||
$tri_uid = trim($tri_uid);
|
||||
if ($tri_uid == '') {
|
||||
throw (new \Exception("The trigger with tri_uid: '', does not exist."));
|
||||
}
|
||||
|
||||
$oTriggers = new \Triggers();
|
||||
if (!($oTriggers->TriggerExists($tri_uid))) {
|
||||
throw (new \Exception("The trigger with tri_uid: '', does not exist."));
|
||||
}
|
||||
|
||||
return $tri_uid;
|
||||
}
|
||||
}
|
||||
|
||||
546
workflow/engine/src/ProcessMaker/BusinessModel/FilesManager.php
Normal file
546
workflow/engine/src/ProcessMaker/BusinessModel/FilesManager.php
Normal file
@@ -0,0 +1,546 @@
|
||||
<?php
|
||||
namespace ProcessMaker\BusinessModel;
|
||||
|
||||
use \G;
|
||||
|
||||
class FilesManager
|
||||
{
|
||||
/**
|
||||
* Return the Process Files Manager
|
||||
*
|
||||
* @param string $sProcessUID {@min 32} {@max 32}
|
||||
*
|
||||
* return array
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function getProcessFilesManager($sProcessUID)
|
||||
{
|
||||
try {
|
||||
$aDirectories[] = array('name' => "templates",
|
||||
'type' => "folder",
|
||||
'path' => "/",
|
||||
'editable' => false);
|
||||
$aDirectories[] = array('name' => "public",
|
||||
'type' => "folder",
|
||||
'path' => "/",
|
||||
'editable' => false);
|
||||
return $aDirectories;
|
||||
} catch (Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the Process Files Manager Path
|
||||
*
|
||||
* @param string $sProcessUID {@min 32} {@max 32}
|
||||
* @param string $path
|
||||
*
|
||||
* return array
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function getProcessFilesManagerPath($sProcessUID, $path)
|
||||
{
|
||||
try {
|
||||
$checkPath = substr($path, -1);
|
||||
if ($checkPath == '/') {
|
||||
$path = substr($path, 0, -1);
|
||||
}
|
||||
$sMainDirectory = current(explode("/", $path));
|
||||
if (strstr($path,'/')) {
|
||||
$sSubDirectory = substr($path, strpos($path, "/")+1). PATH_SEP ;
|
||||
} else {
|
||||
$sSubDirectory = '';
|
||||
}
|
||||
switch ($sMainDirectory) {
|
||||
case 'templates':
|
||||
$sDirectory = PATH_DATA_MAILTEMPLATES . $sProcessUID . PATH_SEP . $sSubDirectory;
|
||||
break;
|
||||
case 'public':
|
||||
$sDirectory = PATH_DATA_PUBLIC . $sProcessUID . PATH_SEP . $sSubDirectory;
|
||||
break;
|
||||
default:
|
||||
throw (new \Exception( 'Invalid value specified for `path`. Expecting `templates` or `public`'));
|
||||
break;
|
||||
}
|
||||
\G::verifyPath($sDirectory, true);
|
||||
$aTheFiles = array();
|
||||
$aFiles = array();
|
||||
$oDirectory = dir($sDirectory);
|
||||
while ($sObject = $oDirectory->read()) {
|
||||
if (($sObject !== '.') && ($sObject !== '..')) {
|
||||
$sPath = $sDirectory . $sObject;
|
||||
if (is_dir($sPath)) {
|
||||
$aTheFiles[] = array('prf_name' => $sObject,
|
||||
'prf_type' => "folder",
|
||||
'prf_path' => $sMainDirectory);
|
||||
} else {
|
||||
$aAux = pathinfo($sPath);
|
||||
$aAux['extension'] = (isset($aAux['extension'])?$aAux['extension']:'');
|
||||
$aFiles[] = array('FILE' => $sObject, 'EXT' => $aAux['extension'] );
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($aFiles as $aFile) {
|
||||
$arrayFileUid = $this->getFileManagerUid($sDirectory.$aFile['FILE']);
|
||||
$fcontent = file_get_contents($sDirectory.$aFile['FILE']);
|
||||
$fileUid = $arrayFileUid["PRF_UID"];
|
||||
if ($fileUid != null) {
|
||||
$oProcessFiles = \ProcessFilesPeer::retrieveByPK($fileUid);
|
||||
$editable = $oProcessFiles->getPrfEditable();
|
||||
if ($editable == '1') {
|
||||
$editable = 'true';
|
||||
} else {
|
||||
$editable = 'false';
|
||||
}
|
||||
$aTheFiles[] = array( 'prf_uid' => $oProcessFiles->getPrfUid(),
|
||||
'prf_filename' => $aFile['FILE'],
|
||||
'usr_uid' => $oProcessFiles->getUsrUid(),
|
||||
'prf_update_usr_uid' => $oProcessFiles->getPrfUpdateUsrUid(),
|
||||
'prf_path' => $sMainDirectory. PATH_SEP .$sSubDirectory,
|
||||
'prf_type' => $oProcessFiles->getPrfType(),
|
||||
'prf_editable' => $editable,
|
||||
'prf_create_date' => $oProcessFiles->getPrfCreateDate(),
|
||||
'prf_update_date' => $oProcessFiles->getPrfUpdateDate(),
|
||||
'prf_content' => $fcontent);
|
||||
} else {
|
||||
$extention = end(explode(".", $aFile['FILE']));
|
||||
if ($extention == 'docx' || $extention == 'doc' || $extention == 'html' || $extention == 'php' || $extention == 'jsp'
|
||||
|| $extention == 'xlsx' || $extention == 'xls' || $extention == 'js' || $extention == 'css' || $extention == 'txt') {
|
||||
$editable = 'true';
|
||||
} else {
|
||||
$editable = 'false';
|
||||
}
|
||||
$aTheFiles[] = array('prf_uid' => '',
|
||||
'prf_filename' => $aFile['FILE'],
|
||||
'usr_uid' => '',
|
||||
'prf_update_usr_uid' => '',
|
||||
'prf_path' => $sMainDirectory. PATH_SEP .$sSubDirectory,
|
||||
'prf_type' => 'file',
|
||||
'prf_editable' => $editable,
|
||||
'prf_create_date' => '',
|
||||
'prf_update_date' => '',
|
||||
'prf_content' => $fcontent);
|
||||
}
|
||||
}
|
||||
return $aTheFiles;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the Process File Manager
|
||||
*
|
||||
* @param string $sProcessUID {@min 32} {@max 32}
|
||||
* @param string $userUID {@min 32} {@max 32}
|
||||
* @param array $aData
|
||||
*
|
||||
* return array
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function addProcessFilesManager($sProcessUID, $userUID, $aData)
|
||||
{
|
||||
try {
|
||||
$aData['prf_path'] = rtrim($aData['prf_path'], '/') . '/';
|
||||
if (!$aData['prf_filename']) {
|
||||
throw (new \Exception( 'Invalid value specified for `prf_filename`.'));
|
||||
}
|
||||
$extention = strstr($aData['prf_filename'], '.');
|
||||
if (!$extention) {
|
||||
$extention = '.html';
|
||||
$aData['prf_filename'] = $aData['prf_filename'].$extention;
|
||||
}
|
||||
if ($extention == '.docx' || $extention == '.doc' || $extention == '.html' || $extention == '.php' || $extention == '.jsp' ||
|
||||
$extention == '.xlsx' || $extention == '.xls' || $extention == '.js' || $extention == '.css' || $extention == '.txt') {
|
||||
$sEditable = true;
|
||||
} else {
|
||||
$sEditable = false;
|
||||
}
|
||||
$sMainDirectory = current(explode("/", $aData['prf_path']));
|
||||
if ($sMainDirectory != 'public' && $sMainDirectory != 'templates') {
|
||||
throw (new \Exception( 'Invalid value specified for `prf_path`. Expecting `templates/` or `public/`'));
|
||||
}
|
||||
if (strstr($aData['prf_path'],'/')) {
|
||||
$sSubDirectory = substr($aData['prf_path'], strpos($aData['prf_path'], "/")+1) ;
|
||||
} else {
|
||||
$sSubDirectory = '';
|
||||
}
|
||||
switch ($sMainDirectory) {
|
||||
case 'templates':
|
||||
$sDirectory = PATH_DATA_MAILTEMPLATES . $sProcessUID . PATH_SEP . $sSubDirectory . $aData['prf_filename'];
|
||||
$sCheckDirectory = PATH_DATA_MAILTEMPLATES . $sProcessUID . PATH_SEP . $sSubDirectory;
|
||||
break;
|
||||
case 'public':
|
||||
$sDirectory = PATH_DATA_PUBLIC . $sProcessUID . PATH_SEP . $sSubDirectory . $aData['prf_filename'];
|
||||
$sCheckDirectory = PATH_DATA_PUBLIC . $sProcessUID . PATH_SEP . $sSubDirectory;
|
||||
$sEditable = false;
|
||||
break;
|
||||
default:
|
||||
$sDirectory = PATH_DATA_MAILTEMPLATES . $sProcessUID . PATH_SEP . $sSubDirectory . $aData['prf_filename'];
|
||||
break;
|
||||
}
|
||||
$content = $aData['prf_content'];
|
||||
if (is_string($content)) {
|
||||
if (file_exists(PATH_SEP.$sDirectory)) {
|
||||
throw (new \Exception( 'The file: '.$sMainDirectory. PATH_SEP . $sSubDirectory . $aData['prf_filename'] . ' already exists.'));
|
||||
}
|
||||
}
|
||||
if (!file_exists($sCheckDirectory)) {
|
||||
$sPkProcessFiles = \G::generateUniqueID();
|
||||
$oProcessFiles = new \ProcessFiles();
|
||||
$sDate = date('Y-m-d H:i:s');
|
||||
$oProcessFiles->setPrfUid($sPkProcessFiles);
|
||||
$oProcessFiles->setProUid($sProcessUID);
|
||||
$oProcessFiles->setUsrUid($userUID);
|
||||
$oProcessFiles->setPrfUpdateUsrUid('');
|
||||
$oProcessFiles->setPrfPath($sCheckDirectory);
|
||||
$oProcessFiles->setPrfType('folder');
|
||||
$oProcessFiles->setPrfEditable('');
|
||||
$oProcessFiles->setPrfCreateDate($sDate);
|
||||
$oProcessFiles->save();
|
||||
}
|
||||
\G::verifyPath($sCheckDirectory, true);
|
||||
$sPkProcessFiles = \G::generateUniqueID();
|
||||
$oProcessFiles = new \ProcessFiles();
|
||||
$sDate = date('Y-m-d H:i:s');
|
||||
$oProcessFiles->setPrfUid($sPkProcessFiles);
|
||||
$oProcessFiles->setProUid($sProcessUID);
|
||||
$oProcessFiles->setUsrUid($userUID);
|
||||
$oProcessFiles->setPrfUpdateUsrUid('');
|
||||
$oProcessFiles->setPrfPath($sDirectory);
|
||||
$oProcessFiles->setPrfType('file');
|
||||
$oProcessFiles->setPrfEditable($sEditable);
|
||||
$oProcessFiles->setPrfCreateDate($sDate);
|
||||
$oProcessFiles->save();
|
||||
$fp = fopen($sDirectory, 'w');
|
||||
$content = $aData['prf_content'];
|
||||
fwrite($fp, $content);
|
||||
fclose($fp);
|
||||
$oProcessFile = array('prf_uid' => $oProcessFiles->getPrfUid(),
|
||||
'prf_filename' => $aData['prf_filename'],
|
||||
'usr_uid' => $oProcessFiles->getUsrUid(),
|
||||
'prf_update_usr_uid' => $oProcessFiles->getPrfUpdateUsrUid(),
|
||||
'prf_path' => $sMainDirectory. PATH_SEP . $sSubDirectory,
|
||||
'prf_type' => $oProcessFiles->getPrfType(),
|
||||
'prf_editable' => $oProcessFiles->getPrfEditable(),
|
||||
'prf_create_date' => $oProcessFiles->getPrfCreateDate(),
|
||||
'prf_update_date' => $oProcessFiles->getPrfUpdateDate(),
|
||||
'prf_content' => $content);
|
||||
return $oProcessFile;
|
||||
} catch (Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the Process Files Manager
|
||||
*
|
||||
* @param string $prjUid {@min 32} {@max 32}
|
||||
* @param string $prfUid {@min 32} {@max 32}
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function uploadProcessFilesManager($prjUid, $prfUid)
|
||||
{
|
||||
try {
|
||||
$path = '';
|
||||
$criteria = new \Criteria("workflow");
|
||||
$criteria->addSelectColumn(\ProcessFilesPeer::PRF_PATH);
|
||||
$criteria->add(\ProcessFilesPeer::PRF_UID, $prfUid, \Criteria::EQUAL);
|
||||
$rsCriteria = \ProcessFilesPeer::doSelectRS($criteria);
|
||||
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
$rsCriteria->next();
|
||||
while ($aRow = $rsCriteria->getRow()) {
|
||||
$path = $aRow['PRF_PATH'];
|
||||
$rsCriteria->next();
|
||||
}
|
||||
if ($path == '') {
|
||||
throw new \Exception(\G::LoadTranslation('ID_PMTABLE_UPLOADING_FILE_PROBLEM'));
|
||||
}
|
||||
$file = end(explode("/",$path));
|
||||
$path = str_replace($file,'',$path);
|
||||
if ($file == $_FILES['prf_file']['name']) {
|
||||
if ($_FILES['prf_file']['error'] != 1) {
|
||||
if ($_FILES['prf_file']['tmp_name'] != '') {
|
||||
\G::uploadFile($_FILES['prf_file']['tmp_name'], $path, $_FILES['prf_file']['name']);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new \Exception(\G::LoadTranslation('ID_PMTABLE_UPLOADING_FILE_PROBLEM'));
|
||||
}
|
||||
$oProcessFile = array('prf_uid' => $prfUid);
|
||||
return $oProcessFile;
|
||||
} catch (Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data of unique ids of a file
|
||||
*
|
||||
* @param string $path
|
||||
*
|
||||
* return array
|
||||
*/
|
||||
public function getFileManagerUid($path)
|
||||
{
|
||||
try {
|
||||
$criteria = new \Criteria("workflow");
|
||||
$criteria->addSelectColumn(\ProcessFilesPeer::PRF_UID);
|
||||
$criteria->add(\ProcessFilesPeer::PRF_PATH, $path, \Criteria::EQUAL);
|
||||
$rsCriteria = \ProcessFilesPeer::doSelectRS($criteria);
|
||||
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
$rsCriteria->next();
|
||||
return $rsCriteria->getRow();
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the Process Files Manager
|
||||
*
|
||||
* @param string $sProcessUID {@min 32} {@max 32}
|
||||
* @param string $userUID {@min 32} {@max 32}
|
||||
* @param array $aData
|
||||
* @param string $prfUid {@min 32} {@max 32}
|
||||
*
|
||||
* return array
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function updateProcessFilesManager($sProcessUID, $userUID, $aData, $prfUid)
|
||||
{
|
||||
try {
|
||||
$path = '';
|
||||
$criteria = new \Criteria("workflow");
|
||||
$criteria->addSelectColumn(\ProcessFilesPeer::PRF_PATH);
|
||||
$criteria->add(\ProcessFilesPeer::PRF_UID, $prfUid, \Criteria::EQUAL);
|
||||
$rsCriteria = \ProcessFilesPeer::doSelectRS($criteria);
|
||||
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
$rsCriteria->next();
|
||||
while ($aRow = $rsCriteria->getRow()) {
|
||||
$path = $aRow['PRF_PATH'];
|
||||
$rsCriteria->next();
|
||||
}
|
||||
if ($path == '') {
|
||||
throw new \Exception('Invalid value specified for `prf_uid`.');
|
||||
}
|
||||
$sFile = end(explode("/",$path));
|
||||
$sPath = str_replace($sFile,'',$path);
|
||||
$sSubDirectory = substr(str_replace($sProcessUID,'',substr($sPath,(strpos($sPath, $sProcessUID)))),0,-1);
|
||||
$sMainDirectory = str_replace(substr($sPath, strpos($sPath, $sProcessUID)),'', $sPath);
|
||||
if ($sMainDirectory == PATH_DATA_MAILTEMPLATES) {
|
||||
$sMainDirectory = 'mailTemplates';
|
||||
} else {
|
||||
$sMainDirectory = 'public';
|
||||
}
|
||||
$extention = end(explode(".", $sFile));
|
||||
if ($extention == 'docx' || $extention == 'doc' || $extention == 'html' || $extention == 'php' || $extention == 'jsp' ||
|
||||
$extention == 'xlsx' || $extention == 'xls' || $extention == 'js' || $extention == 'css' || $extention == 'txt') {
|
||||
$sEditable = true;
|
||||
} else {
|
||||
$sEditable = false;
|
||||
}
|
||||
if ($sEditable == false) {
|
||||
throw (new \Exception( 'Unable to edit. Make sure your file has an editable extension.'));
|
||||
}
|
||||
$oProcessFiles = \ProcessFilesPeer::retrieveByPK($prfUid);
|
||||
$sDate = date('Y-m-d H:i:s');
|
||||
$oProcessFiles->setPrfUpdateUsrUid($userUID);
|
||||
$oProcessFiles->setPrfUpdateDate($sDate);
|
||||
$oProcessFiles->save();
|
||||
$fp = fopen($path, 'w');
|
||||
$content = $aData['prf_content'];
|
||||
fwrite($fp, $content);
|
||||
fclose($fp);
|
||||
$oProcessFile = array('prf_uid' => $oProcessFiles->getPrfUid(),
|
||||
'prf_filename' => $sFile,
|
||||
'usr_uid' => $oProcessFiles->getUsrUid(),
|
||||
'prf_update_usr_uid' => $oProcessFiles->getPrfUpdateUsrUid(),
|
||||
'prf_path' => $sMainDirectory.$sSubDirectory,
|
||||
'prf_type' => $oProcessFiles->getPrfType(),
|
||||
'prf_editable' => $sEditable,
|
||||
'prf_create_date' => $oProcessFiles->getPrfCreateDate(),
|
||||
'prf_update_date' => $oProcessFiles->getPrfUpdateDate(),
|
||||
'prf_content' => $content);
|
||||
return $oProcessFile;
|
||||
} catch (Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $sProcessUID {@min 32} {@max 32}
|
||||
* @param string $prfUid {@min 32} {@max 32}
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function deleteProcessFilesManager($sProcessUID, $prfUid)
|
||||
{
|
||||
try {
|
||||
$path = '';
|
||||
$criteria = new \Criteria("workflow");
|
||||
$criteria->addSelectColumn(\ProcessFilesPeer::PRF_PATH);
|
||||
$criteria->add(\ProcessFilesPeer::PRF_UID, $prfUid, \Criteria::EQUAL);
|
||||
$rsCriteria = \ProcessFilesPeer::doSelectRS($criteria);
|
||||
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
$rsCriteria->next();
|
||||
while ($aRow = $rsCriteria->getRow()) {
|
||||
$path = $aRow['PRF_PATH'];
|
||||
$rsCriteria->next();
|
||||
}
|
||||
if ($path == '') {
|
||||
throw new \Exception('Invalid value specified for `prf_uid`.');
|
||||
}
|
||||
$sFile = end(explode("/",$path));
|
||||
$sPath = str_replace($sFile,'',$path);
|
||||
$sSubDirectory = substr(str_replace($sProcessUID,'',substr($sPath,(strpos($sPath, $sProcessUID)))),0,-1);
|
||||
$sMainDirectory = str_replace(substr($sPath, strpos($sPath, $sProcessUID)),'', $sPath);
|
||||
if ($sMainDirectory == PATH_DATA_MAILTEMPLATES) {
|
||||
$sMainDirectory = 'mailTemplates';
|
||||
} else {
|
||||
$sMainDirectory = 'public';
|
||||
}
|
||||
$oProcessMap = new \processMap(new \DBConnection());
|
||||
$oProcessMap->deleteFile($sProcessUID, $sMainDirectory, $sSubDirectory, $sFile);
|
||||
$rs = \ProcessFilesPeer::doDelete($criteria);
|
||||
} catch (Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $sProcessUID {@min 32} {@max 32}
|
||||
* @param string $prfUid {@min 32} {@max 32}
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function downloadProcessFilesManager($sProcessUID, $prfUid)
|
||||
{
|
||||
try {
|
||||
$path = '';
|
||||
$criteria = new \Criteria("workflow");
|
||||
$criteria->addSelectColumn(\ProcessFilesPeer::PRF_PATH);
|
||||
$criteria->add(\ProcessFilesPeer::PRF_UID, $prfUid, \Criteria::EQUAL);
|
||||
$rsCriteria = \ProcessFilesPeer::doSelectRS($criteria);
|
||||
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
$rsCriteria->next();
|
||||
while ($aRow = $rsCriteria->getRow()) {
|
||||
$path = $aRow['PRF_PATH'];
|
||||
$rsCriteria->next();
|
||||
}
|
||||
if ($path == '') {
|
||||
throw new \Exception('Invalid value specified for `prf_uid`.');
|
||||
}
|
||||
$sFile = end(explode("/",$path));
|
||||
$sPath = str_replace($sFile,'',$path);
|
||||
$sSubDirectory = substr(str_replace($sProcessUID,'',substr($sPath,(strpos($sPath, $sProcessUID)))),0,-1);
|
||||
$sMainDirectory = str_replace(substr($sPath, strpos($sPath, $sProcessUID)),'', $sPath);
|
||||
if ($sMainDirectory == PATH_DATA_MAILTEMPLATES) {
|
||||
$sMainDirectory = 'mailTemplates';
|
||||
} else {
|
||||
$sMainDirectory = 'public';
|
||||
}
|
||||
if (file_exists($path)) {
|
||||
$oProcessMap = new \processMap(new \DBConnection());
|
||||
$oProcessMap->downloadFile($sProcessUID,$sMainDirectory,$sSubDirectory,$sFile);
|
||||
die();
|
||||
} else {
|
||||
throw (new \Exception( 'Invalid value specified for `path`.'));
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $sProcessUID {@min 32} {@max 32}
|
||||
* @param array $path
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function deleteFolderProcessFilesManager($sProcessUID, $path)
|
||||
{
|
||||
try {
|
||||
$sDirToDelete = end(explode("/",$path));
|
||||
$sPath = str_replace($sDirToDelete,'',$path);
|
||||
$sSubDirectory = substr(str_replace($sProcessUID,'',substr($sPath,(strpos($sPath, $sProcessUID)))),0,-1);
|
||||
$sMainDirectory = current(explode("/", $path));
|
||||
$sSubDirectory = substr(str_replace($sMainDirectory,'',$sSubDirectory),1);
|
||||
switch ($sMainDirectory) {
|
||||
case 'templates':
|
||||
$sDirectory = PATH_DATA_MAILTEMPLATES . $sProcessUID . PATH_SEP . ($sSubDirectory != '' ? $sSubDirectory . PATH_SEP : '');
|
||||
break;
|
||||
case 'public':
|
||||
$sDirectory = PATH_DATA_PUBLIC . $sProcessUID . PATH_SEP . ($sSubDirectory != '' ? $sSubDirectory . PATH_SEP : '');
|
||||
break;
|
||||
default:
|
||||
die();
|
||||
break;
|
||||
}
|
||||
if (file_exists($sDirectory.$sDirToDelete)) {
|
||||
\G::rm_dir($sDirectory.$sDirToDelete);
|
||||
} else {
|
||||
throw (new \Exception( 'Invalid value specified for `path`.'));
|
||||
}
|
||||
$criteria = new \Criteria("workflow");
|
||||
$criteria->addSelectColumn(\ProcessFilesPeer::PRF_PATH);
|
||||
$criteria->add( \ProcessFilesPeer::PRF_PATH, '%' . $sDirectory.$sDirToDelete. PATH_SEP . '%', \Criteria::LIKE );
|
||||
$rs = \ProcessFilesPeer::doDelete($criteria);
|
||||
return $sDirectory.$sDirToDelete;
|
||||
} catch (Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $sProcessUID {@min 32} {@max 32}
|
||||
* @param string $prfUid {@min 32} {@max 32}
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function getProcessFileManager($sProcessUID, $prfUid)
|
||||
{
|
||||
try {
|
||||
$oProcessFiles = \ProcessFilesPeer::retrieveByPK($prfUid);
|
||||
$fcontent = file_get_contents($oProcessFiles->getPrfPath());
|
||||
$sFile = end(explode("/",$oProcessFiles->getPrfPath()));
|
||||
$path = $oProcessFiles->getPrfPath();
|
||||
$sPath = str_replace($sFile,'',$path);
|
||||
$sSubDirectory = substr(str_replace($sProcessUID,'',substr($sPath,(strpos($sPath, $sProcessUID)))),0,-1);
|
||||
$sMainDirectory = str_replace(substr($sPath, strpos($sPath, $sProcessUID)),'', $sPath);
|
||||
if ($sMainDirectory == PATH_DATA_MAILTEMPLATES) {
|
||||
$sMainDirectory = 'templates';
|
||||
} else {
|
||||
$sMainDirectory = 'public';
|
||||
}
|
||||
$oProcessFile = array('prf_uid' => $oProcessFiles->getPrfUid(),
|
||||
'prf_filename' => $sFile,
|
||||
'usr_uid' => $oProcessFiles->getUsrUid(),
|
||||
'prf_update_usr_uid' => $oProcessFiles->getPrfUpdateUsrUid(),
|
||||
'prf_path' => $sMainDirectory.$sSubDirectory,
|
||||
'prf_type' => $oProcessFiles->getPrfType(),
|
||||
'prf_editable' => $oProcessFiles->getPrfEditable(),
|
||||
'prf_create_date' => $oProcessFiles->getPrfCreateDate(),
|
||||
'prf_update_date' => $oProcessFiles->getPrfUpdateDate(),
|
||||
'prf_content' => $fcontent);
|
||||
return $oProcessFile;
|
||||
} catch (Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
776
workflow/engine/src/ProcessMaker/BusinessModel/Group.php
Normal file
776
workflow/engine/src/ProcessMaker/BusinessModel/Group.php
Normal file
@@ -0,0 +1,776 @@
|
||||
<?php
|
||||
namespace ProcessMaker\BusinessModel;
|
||||
|
||||
class Group
|
||||
{
|
||||
private $arrayFieldDefinition = array(
|
||||
"GRP_UID" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "groupUid"),
|
||||
|
||||
"GRP_TITLE" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "groupTitle"),
|
||||
"GRP_STATUS" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array("ACTIVE", "INACTIVE"), "fieldNameAux" => "groupStatus")
|
||||
);
|
||||
|
||||
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($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 title of a Group
|
||||
*
|
||||
* @param string $groupTitle Title
|
||||
* @param string $groupUidExclude Unique id of Group to exclude
|
||||
*
|
||||
* return bool Return true if exists the title of a Group, false otherwise
|
||||
*/
|
||||
public function existsTitle($groupTitle, $groupUidExclude = "")
|
||||
{
|
||||
try {
|
||||
$delimiter = \DBAdapter::getStringDelimiter();
|
||||
|
||||
$criteria = new \Criteria("workflow");
|
||||
|
||||
$criteria->addSelectColumn(\GroupwfPeer::GRP_UID);
|
||||
|
||||
$criteria->addAlias("CT", \ContentPeer::TABLE_NAME);
|
||||
|
||||
$arrayCondition = array();
|
||||
$arrayCondition[] = array(\GroupwfPeer::GRP_UID, "CT.CON_ID", \Criteria::EQUAL);
|
||||
$arrayCondition[] = array("CT.CON_CATEGORY", $delimiter . "GRP_TITLE" . $delimiter, \Criteria::EQUAL);
|
||||
$arrayCondition[] = array("CT.CON_LANG", $delimiter . SYS_LANG . $delimiter, \Criteria::EQUAL);
|
||||
$criteria->addJoinMC($arrayCondition, \Criteria::LEFT_JOIN);
|
||||
|
||||
if ($groupUidExclude != "") {
|
||||
$criteria->add(\GroupwfPeer::GRP_UID, $groupUidExclude, \Criteria::NOT_EQUAL);
|
||||
}
|
||||
|
||||
$criteria->add("CT.CON_VALUE", $groupTitle, \Criteria::EQUAL);
|
||||
|
||||
$rsCriteria = \GroupwfPeer::doSelectRS($criteria);
|
||||
|
||||
if ($rsCriteria->next()) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify if doesn't exists the Group in table GROUP
|
||||
*
|
||||
* @param string $groupUid Unique id of Group
|
||||
* @param string $fieldNameForException Field name for the exception
|
||||
*
|
||||
* return void Throw exception if doesn't exists the Group in table GROUP
|
||||
*/
|
||||
public function throwExceptionIfNotExistsGroup($groupUid, $fieldNameForException)
|
||||
{
|
||||
try {
|
||||
$group = new \Groupwf();
|
||||
|
||||
if (!$group->GroupwfExists($groupUid)) {
|
||||
$msg = str_replace(array("{0}", "{1}"), array($fieldNameForException, $groupUid), "The group with {0}: {1} does not exist");
|
||||
|
||||
throw (new \Exception($msg));
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify if exists the title of a Group
|
||||
*
|
||||
* @param string $groupTitle Title
|
||||
* @param string $fieldNameForException Field name for the exception
|
||||
* @param string $groupUidExclude Unique id of Group to exclude
|
||||
*
|
||||
* return void Throw exception if exists the title of a Group
|
||||
*/
|
||||
public function throwExceptionIfExistsTitle($groupTitle, $fieldNameForException, $groupUidExclude = "")
|
||||
{
|
||||
try {
|
||||
if ($this->existsTitle($groupTitle, $groupUidExclude)) {
|
||||
$msg = str_replace(array("{0}", "{1}"), array($fieldNameForException, $groupTitle), "The group title with {0}: \"{1}\" already exists");
|
||||
|
||||
throw (new \Exception($msg));
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Group
|
||||
*
|
||||
* @param array $arrayData Data
|
||||
*
|
||||
* return array Return data of the new Group created
|
||||
*/
|
||||
public function create($arrayData)
|
||||
{
|
||||
try {
|
||||
$arrayData = array_change_key_case($arrayData, CASE_UPPER);
|
||||
|
||||
unset($arrayData["GRP_UID"]);
|
||||
|
||||
//Verify data
|
||||
$process = new \ProcessMaker\BusinessModel\Process();
|
||||
|
||||
$process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $this->arrayFieldDefinition, $this->arrayFieldNameForException, true);
|
||||
|
||||
$this->throwExceptionIfExistsTitle($arrayData["GRP_TITLE"], $this->arrayFieldNameForException["groupTitle"]);
|
||||
|
||||
//Create
|
||||
$group = new \Groupwf();
|
||||
|
||||
$groupUid = $group->create($arrayData);
|
||||
|
||||
//Return
|
||||
$arrayData = array_merge(array("GRP_UID" => $groupUid), $arrayData);
|
||||
|
||||
if (!$this->formatFieldNameInUppercase) {
|
||||
$arrayData = array_change_key_case($arrayData, CASE_LOWER);
|
||||
}
|
||||
|
||||
return $arrayData;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update Group
|
||||
*
|
||||
* @param string $groupUid Unique id of Group
|
||||
* @param array $arrayData Data
|
||||
*
|
||||
* return array Return data of the Group updated
|
||||
*/
|
||||
public function update($groupUid, $arrayData)
|
||||
{
|
||||
try {
|
||||
$arrayData = array_change_key_case($arrayData, CASE_UPPER);
|
||||
|
||||
//Verify data
|
||||
$process = new \ProcessMaker\BusinessModel\Process();
|
||||
|
||||
$this->throwExceptionIfNotExistsGroup($groupUid, $this->arrayFieldNameForException["groupUid"]);
|
||||
|
||||
$process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $this->arrayFieldDefinition, $this->arrayFieldNameForException, false);
|
||||
|
||||
if (isset($arrayData["GRP_TITLE"])) {
|
||||
$this->throwExceptionIfExistsTitle($arrayData["GRP_TITLE"], $this->arrayFieldNameForException["groupTitle"], $groupUid);
|
||||
}
|
||||
|
||||
//Update
|
||||
$group = new \Groupwf();
|
||||
|
||||
$arrayData["GRP_UID"] = $groupUid;
|
||||
|
||||
$result = $group->update($arrayData);
|
||||
|
||||
//Return
|
||||
unset($arrayData["GRP_UID"]);
|
||||
|
||||
if (!$this->formatFieldNameInUppercase) {
|
||||
$arrayData = array_change_key_case($arrayData, CASE_LOWER);
|
||||
}
|
||||
|
||||
return $arrayData;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete Group
|
||||
*
|
||||
* @param string $groupUid Unique id of Group
|
||||
*
|
||||
* return void
|
||||
*/
|
||||
public function delete($groupUid)
|
||||
{
|
||||
try {
|
||||
//Verify data
|
||||
$this->throwExceptionIfNotExistsGroup($groupUid, $this->arrayFieldNameForException["groupUid"]);
|
||||
|
||||
//Delete
|
||||
$group = new \Groupwf();
|
||||
|
||||
$result = $group->remove($groupUid);
|
||||
|
||||
//Delete assignments of tasks
|
||||
$criteria = new \Criteria("workflow");
|
||||
|
||||
$criteria->add(\TaskUserPeer::USR_UID, $groupUid);
|
||||
|
||||
\TaskUserPeer::doDelete($criteria);
|
||||
|
||||
//Delete permissions
|
||||
$criteria = new \Criteria("workflow");
|
||||
|
||||
$criteria->add(\ObjectPermissionPeer::USR_UID, $groupUid);
|
||||
|
||||
\ObjectPermissionPeer::doDelete($criteria);
|
||||
|
||||
//Delete assignments of supervisors
|
||||
$criteria = new \Criteria("workflow");
|
||||
|
||||
$criteria->add(\ProcessUserPeer::USR_UID, $groupUid);
|
||||
$criteria->add(\ProcessUserPeer::PU_TYPE, "GROUP_SUPERVISOR");
|
||||
|
||||
\ProcessUserPeer::doDelete($criteria);
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get criteria for Group
|
||||
*
|
||||
* return object
|
||||
*/
|
||||
public function getGroupCriteria()
|
||||
{
|
||||
try {
|
||||
$criteria = new \Criteria("workflow");
|
||||
|
||||
$criteria->addSelectColumn(\GroupwfPeer::GRP_UID);
|
||||
$criteria->addSelectColumn(\GroupwfPeer::GRP_STATUS);
|
||||
$criteria->addSelectColumn(\GroupwfPeer::GRP_LDAP_DN);
|
||||
$criteria->addSelectColumn(\GroupwfPeer::GRP_UX);
|
||||
$criteria->addAsColumn("GRP_TITLE", \ContentPeer::CON_VALUE);
|
||||
$criteria->addJoin(\GroupwfPeer::GRP_UID, \ContentPeer::CON_ID, \Criteria::LEFT_JOIN);
|
||||
$criteria->add(\ContentPeer::CON_CATEGORY, "GRP_TITLE", \Criteria::EQUAL);
|
||||
$criteria->add(\ContentPeer::CON_LANG, SYS_LANG, \Criteria::EQUAL);
|
||||
|
||||
return $criteria;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data of total Users by Group
|
||||
*
|
||||
* @param string $groupUid Unique id of Group
|
||||
*
|
||||
* return array Return an array with data of total Users by Group
|
||||
*/
|
||||
public function getTotalUsersByGroup($groupUid = "")
|
||||
{
|
||||
try {
|
||||
$arrayData = array();
|
||||
|
||||
//Verif data
|
||||
if ($groupUid != "") {
|
||||
$this->throwExceptionIfNotExistsGroup($groupUid, $this->arrayFieldNameForException["groupUid"]);
|
||||
}
|
||||
|
||||
//Get data
|
||||
$criteria = new \Criteria("workflow");
|
||||
|
||||
$criteria->addSelectColumn(\GroupUserPeer::GRP_UID);
|
||||
$criteria->addSelectColumn("COUNT(" . \GroupUserPeer::GRP_UID . ") AS NUM_REC");
|
||||
$criteria->addJoin(\GroupUserPeer::USR_UID, \UsersPeer::USR_UID, \Criteria::INNER_JOIN);
|
||||
|
||||
if ($groupUid != "") {
|
||||
$criteria->add(\GroupUserPeer::GRP_UID, $groupUid, \Criteria::EQUAL);
|
||||
}
|
||||
|
||||
$criteria->add(\UsersPeer::USR_STATUS, "CLOSED", \Criteria::NOT_EQUAL);
|
||||
$criteria->addGroupByColumn(\GroupUserPeer::GRP_UID);
|
||||
|
||||
$rsCriteria = \GroupUserPeer::doSelectRS($criteria);
|
||||
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
|
||||
while ($rsCriteria->next()) {
|
||||
$row = $rsCriteria->getRow();
|
||||
|
||||
$arrayData[$row["GRP_UID"]] = $row["NUM_REC"];
|
||||
}
|
||||
|
||||
//Return
|
||||
return $arrayData;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data of total Tasks by Group
|
||||
*
|
||||
* @param string $groupUid Unique id of Group
|
||||
*
|
||||
* return array Return an array with data of total Tasks by Group
|
||||
*/
|
||||
public function getTotalTasksByGroup($groupUid = "")
|
||||
{
|
||||
try {
|
||||
$arrayData = array();
|
||||
|
||||
//Verif data
|
||||
if ($groupUid != "") {
|
||||
$this->throwExceptionIfNotExistsGroup($groupUid, $this->arrayFieldNameForException["groupUid"]);
|
||||
}
|
||||
|
||||
//Get data
|
||||
$criteria = new \Criteria("workflow");
|
||||
|
||||
$criteria->addAsColumn("GRP_UID", \TaskUserPeer::USR_UID);
|
||||
$criteria->addSelectColumn("COUNT(" . \TaskUserPeer::USR_UID . ") AS NUM_REC");
|
||||
|
||||
if ($groupUid != "") {
|
||||
$criteria->add(\TaskUserPeer::USR_UID, $groupUid, \Criteria::EQUAL);
|
||||
}
|
||||
|
||||
$criteria->add(\TaskUserPeer::TU_TYPE, 1, \Criteria::EQUAL);
|
||||
$criteria->add(\TaskUserPeer::TU_RELATION, 2, \Criteria::EQUAL);
|
||||
$criteria->addGroupByColumn(\TaskUserPeer::USR_UID);
|
||||
|
||||
$rsCriteria = \TaskUserPeer::doSelectRS($criteria);
|
||||
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC );
|
||||
|
||||
while ($rsCriteria->next()) {
|
||||
$row = $rsCriteria->getRow();
|
||||
|
||||
$arrayData[$row["GRP_UID"]] = $row["NUM_REC"];
|
||||
}
|
||||
|
||||
//Return
|
||||
return $arrayData;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data of a Group from a record
|
||||
*
|
||||
* @param array $record Record
|
||||
*
|
||||
* return array Return an array with data Group
|
||||
*/
|
||||
public function getGroupDataFromRecord($record)
|
||||
{
|
||||
try {
|
||||
return array(
|
||||
$this->getFieldNameByFormatFieldName("GRP_UID") => $record["GRP_UID"],
|
||||
$this->getFieldNameByFormatFieldName("GRP_TITLE") => $record["GRP_TITLE"],
|
||||
$this->getFieldNameByFormatFieldName("GRP_STATUS") => $record["GRP_STATUS"],
|
||||
$this->getFieldNameByFormatFieldName("GRP_USERS") => (int)($record["GRP_USERS"]),
|
||||
$this->getFieldNameByFormatFieldName("GRP_TASKS") => (int)($record["GRP_TASKS"])
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all Groups
|
||||
*
|
||||
* @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 Groups
|
||||
*/
|
||||
public function getGroups($arrayFilterData = null, $sortField = null, $sortDir = null, $start = null, $limit = null)
|
||||
{
|
||||
try {
|
||||
$arrayGroup = 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 $arrayGroup;
|
||||
}
|
||||
|
||||
$arrayTotalUsersByGroup = $this->getTotalUsersByGroup();
|
||||
$arrayTotalTasksByGroup = $this->getTotalTasksByGroup();
|
||||
|
||||
//SQL
|
||||
$criteria = $this->getGroupCriteria();
|
||||
|
||||
if (!is_null($arrayFilterData) && is_array($arrayFilterData) && isset($arrayFilterData["filter"]) && trim($arrayFilterData["filter"]) != "") {
|
||||
$criteria->add(\ContentPeer::CON_VALUE, "%" . $arrayFilterData["filter"] . "%", \Criteria::LIKE);
|
||||
}
|
||||
|
||||
//Number records total
|
||||
$criteriaCount = clone $criteria;
|
||||
|
||||
$criteriaCount->clearSelectColumns();
|
||||
$criteriaCount->addSelectColumn("COUNT(" . \GroupwfPeer::GRP_UID . ") AS NUM_REC");
|
||||
|
||||
$rsCriteriaCount = \GroupwfPeer::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);
|
||||
|
||||
switch ($sortField) {
|
||||
case "GRP_UID":
|
||||
case "GRP_STATUS":
|
||||
case "GRP_LDAP_DN":
|
||||
case "GRP_UX":
|
||||
$sortField = \GroupwfPeer::TABLE_NAME . "." . $sortField;
|
||||
break;
|
||||
default:
|
||||
$sortField = "GRP_TITLE";
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
$sortField = "GRP_TITLE";
|
||||
}
|
||||
|
||||
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 = \GroupwfPeer::doSelectRS($criteria);
|
||||
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
|
||||
while ($rsCriteria->next()) {
|
||||
$row = $rsCriteria->getRow();
|
||||
|
||||
$row["GRP_USERS"] = (isset($arrayTotalUsersByGroup[$row["GRP_UID"]]))? $arrayTotalUsersByGroup[$row["GRP_UID"]] : 0;
|
||||
$row["GRP_TASKS"] = (isset($arrayTotalTasksByGroup[$row["GRP_UID"]]))? $arrayTotalTasksByGroup[$row["GRP_UID"]] : 0;
|
||||
|
||||
$arrayGroup[] = $this->getGroupDataFromRecord($row);
|
||||
}
|
||||
|
||||
//Return
|
||||
return $arrayGroup;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data of a Group
|
||||
*
|
||||
* @param string $groupUid Unique id of Group
|
||||
*
|
||||
* return array Return an array with data of a Group
|
||||
*/
|
||||
public function getGroup($groupUid)
|
||||
{
|
||||
try {
|
||||
//Verify data
|
||||
$this->throwExceptionIfNotExistsGroup($groupUid, $this->arrayFieldNameForException["groupUid"]);
|
||||
|
||||
//Get data
|
||||
$arrayTotalUsersByGroup = $this->getTotalUsersByGroup($groupUid);
|
||||
$arrayTotalTasksByGroup = $this->getTotalTasksByGroup($groupUid);
|
||||
|
||||
//SQL
|
||||
$criteria = $this->getGroupCriteria();
|
||||
|
||||
$criteria->add(\GroupwfPeer::GRP_UID, $groupUid, \Criteria::EQUAL);
|
||||
|
||||
$rsCriteria = \GroupwfPeer::doSelectRS($criteria);
|
||||
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
|
||||
$rsCriteria->next();
|
||||
|
||||
$row = $rsCriteria->getRow();
|
||||
|
||||
$row["GRP_USERS"] = (isset($arrayTotalUsersByGroup[$groupUid]))? $arrayTotalUsersByGroup[$groupUid] : 0;
|
||||
$row["GRP_TASKS"] = (isset($arrayTotalTasksByGroup[$groupUid]))? $arrayTotalTasksByGroup[$groupUid] : 0;
|
||||
|
||||
//Return
|
||||
return $this->getGroupDataFromRecord($row);
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get criteria for User
|
||||
*
|
||||
* @param string $groupUid Unique id of Group
|
||||
* @param array $arrayFilterData Data of the filters
|
||||
* @param array $arrayUserUidExclude Unique id of Users to exclude
|
||||
*
|
||||
* return object
|
||||
*/
|
||||
public function getUserCriteria($groupUid, $arrayFilterData = null, $arrayUserUidExclude = null)
|
||||
{
|
||||
try {
|
||||
$criteria = new \Criteria("workflow");
|
||||
|
||||
$criteria->addSelectColumn(\UsersPeer::USR_UID);
|
||||
$criteria->addSelectColumn(\UsersPeer::USR_USERNAME);
|
||||
$criteria->addSelectColumn(\UsersPeer::USR_FIRSTNAME);
|
||||
$criteria->addSelectColumn(\UsersPeer::USR_LASTNAME);
|
||||
$criteria->addSelectColumn(\UsersPeer::USR_EMAIL);
|
||||
$criteria->addSelectColumn(\UsersPeer::USR_STATUS);
|
||||
|
||||
if ($groupUid != "") {
|
||||
$criteria->addJoin(\GroupUserPeer::USR_UID, \UsersPeer::USR_UID, \Criteria::LEFT_JOIN);
|
||||
$criteria->add(\GroupUserPeer::GRP_UID, $groupUid, \Criteria::EQUAL);
|
||||
}
|
||||
|
||||
$criteria->add(\UsersPeer::USR_STATUS, "CLOSED", \Criteria::NOT_EQUAL);
|
||||
|
||||
if (!is_null($arrayUserUidExclude) && is_array($arrayUserUidExclude)) {
|
||||
$criteria->add(\UsersPeer::USR_UID, $arrayUserUidExclude, \Criteria::NOT_IN);
|
||||
}
|
||||
|
||||
if (!is_null($arrayFilterData) && is_array($arrayFilterData) && isset($arrayFilterData["filter"]) && trim($arrayFilterData["filter"]) != "") {
|
||||
$criteria->add(
|
||||
$criteria->getNewCriterion(\UsersPeer::USR_USERNAME, "%" . $arrayFilterData["filter"] . "%", \Criteria::LIKE)->addOr(
|
||||
$criteria->getNewCriterion(\UsersPeer::USR_FIRSTNAME, "%" . $arrayFilterData["filter"] . "%", \Criteria::LIKE)->addOr(
|
||||
$criteria->getNewCriterion(\UsersPeer::USR_LASTNAME, "%" . $arrayFilterData["filter"] . "%", \Criteria::LIKE)))
|
||||
);
|
||||
}
|
||||
|
||||
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($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_EMAIL") => $record["USR_EMAIL"] . "",
|
||||
$this->getFieldNameByFormatFieldName("USR_STATUS") => $record["USR_STATUS"]
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all Users of a Group
|
||||
*
|
||||
* @param string $option Option (USERS, AVAILABLE-USERS)
|
||||
* @param string $groupUid Unique id of Group
|
||||
* @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 Group
|
||||
*/
|
||||
public function getUsers($option, $groupUid, $arrayFilterData = null, $sortField = null, $sortDir = null, $start = null, $limit = null)
|
||||
{
|
||||
try {
|
||||
$arrayUser = array();
|
||||
|
||||
//Verify data
|
||||
$process = new \ProcessMaker\BusinessModel\Process();
|
||||
|
||||
$this->throwExceptionIfNotExistsGroup($groupUid, $this->arrayFieldNameForException["groupUid"]);
|
||||
|
||||
$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($groupUid, $arrayFilterData);
|
||||
break;
|
||||
case "AVAILABLE-USERS":
|
||||
//Get Uids
|
||||
$arrayUid = array();
|
||||
|
||||
$criteria = $this->getUserCriteria($groupUid);
|
||||
|
||||
$rsCriteria = \UsersPeer::doSelectRS($criteria);
|
||||
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
|
||||
while ($rsCriteria->next()) {
|
||||
$row = $rsCriteria->getRow();
|
||||
|
||||
$arrayUid[] = $row["USR_UID"];
|
||||
}
|
||||
|
||||
//Criteria
|
||||
$criteria = $this->getUserCriteria("", $arrayFilterData, $arrayUid);
|
||||
break;
|
||||
}
|
||||
|
||||
//Number records total
|
||||
$criteriaCount = clone $criteria;
|
||||
|
||||
$criteriaCount->clearSelectColumns();
|
||||
$criteriaCount->addSelectColumn("COUNT(" . \UsersPeer::USR_UID . ") AS NUM_REC");
|
||||
|
||||
$rsCriteriaCount = \UsersPeer::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);
|
||||
|
||||
switch ($sortField) {
|
||||
case "USR_UID":
|
||||
case "USR_USERNAME":
|
||||
case "USR_FIRSTNAME":
|
||||
case "USR_LASTNAME":
|
||||
case "USR_EMAIL":
|
||||
case "USR_STATUS":
|
||||
$sortField = \UsersPeer::TABLE_NAME . "." . $sortField;
|
||||
break;
|
||||
default:
|
||||
$sortField = \UsersPeer::USR_USERNAME;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
$sortField = \UsersPeer::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 = \UsersPeer::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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
206
workflow/engine/src/ProcessMaker/BusinessModel/Group/User.php
Normal file
206
workflow/engine/src/ProcessMaker/BusinessModel/Group/User.php
Normal file
@@ -0,0 +1,206 @@
|
||||
<?php
|
||||
namespace ProcessMaker\BusinessModel\Group;
|
||||
|
||||
class User
|
||||
{
|
||||
private $arrayFieldDefinition = array(
|
||||
"GRP_UID" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "groupUid"),
|
||||
"USR_UID" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "userUid")
|
||||
);
|
||||
|
||||
private $formatFieldNameInUppercase = true;
|
||||
|
||||
private $arrayFieldNameForException = array();
|
||||
|
||||
/**
|
||||
* 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($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 doesn't exist the User in Group
|
||||
*
|
||||
* @param string $groupUid Unique id of Group
|
||||
* @param string $userUid Unique id of User
|
||||
* @param string $fieldNameForException Field name for the exception
|
||||
*
|
||||
* return void Throw exception if doesn't exist the User in Group
|
||||
*/
|
||||
public function throwExceptionIfNotExistsGroupUser($groupUid, $userUid, $fieldNameForException)
|
||||
{
|
||||
try {
|
||||
$obj = \GroupUserPeer::retrieveByPK($groupUid, $userUid);
|
||||
|
||||
if (!(is_object($obj) && get_class($obj) == "GroupUser")) {
|
||||
$msg = str_replace(array("{0}", "{1}"), array($fieldNameForException, $userUid), "The user with {0}: {1} is not assigned to the group");
|
||||
|
||||
throw (new \Exception($msg));
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify if exists the User in Group
|
||||
*
|
||||
* @param string $groupUid Unique id of Group
|
||||
* @param string $userUid Unique id of User
|
||||
* @param string $fieldNameForException Field name for the exception
|
||||
*
|
||||
* return void Throw exception if exists the User in Group
|
||||
*/
|
||||
public function throwExceptionIfExistsGroupUser($groupUid, $userUid, $fieldNameForException)
|
||||
{
|
||||
try {
|
||||
$obj = \GroupUserPeer::retrieveByPK($groupUid, $userUid);
|
||||
|
||||
if (is_object($obj) && get_class($obj) == "GroupUser") {
|
||||
$msg = str_replace(array("{0}", "{1}"), array($fieldNameForException, $userUid), "The user with {0}: {1} is already assigned to the group");
|
||||
|
||||
throw (new \Exception($msg));
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign User to Group
|
||||
*
|
||||
* @param string $groupUid Unique id of Group
|
||||
* @param array $arrayData Data
|
||||
*
|
||||
* return array Return data of the User assigned to Group
|
||||
*/
|
||||
public function create($groupUid, $arrayData)
|
||||
{
|
||||
try {
|
||||
$arrayData = array_change_key_case($arrayData, CASE_UPPER);
|
||||
|
||||
unset($arrayData["GRP_UID"]);
|
||||
|
||||
//Verify data
|
||||
$process = new \ProcessMaker\BusinessModel\Process();
|
||||
$group = new \ProcessMaker\BusinessModel\Group();
|
||||
|
||||
$group->throwExceptionIfNotExistsGroup($groupUid, $this->arrayFieldNameForException["groupUid"]);
|
||||
|
||||
$process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $this->arrayFieldDefinition, $this->arrayFieldNameForException, true);
|
||||
|
||||
$process->throwExceptionIfNotExistsUser($arrayData["USR_UID"], $this->arrayFieldNameForException["userUid"]);
|
||||
|
||||
$this->throwExceptionIfExistsGroupUser($groupUid, $arrayData["USR_UID"], $this->arrayFieldNameForException["userUid"]);
|
||||
|
||||
//Create
|
||||
$group = new \Groups();
|
||||
|
||||
$group->addUserToGroup($groupUid, $arrayData["USR_UID"]);
|
||||
|
||||
//Return
|
||||
$arrayData = array_merge(array("GRP_UID" => $groupUid), $arrayData);
|
||||
|
||||
if (!$this->formatFieldNameInUppercase) {
|
||||
$arrayData = array_change_key_case($arrayData, CASE_LOWER);
|
||||
}
|
||||
|
||||
return $arrayData;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unassign User of the Group
|
||||
*
|
||||
* @param string $groupUid Unique id of Group
|
||||
* @param string $userUid Unique id of User
|
||||
*
|
||||
* return void
|
||||
*/
|
||||
public function delete($groupUid, $userUid)
|
||||
{
|
||||
try {
|
||||
//Verify data
|
||||
$process = new \ProcessMaker\BusinessModel\Process();
|
||||
$group = new \ProcessMaker\BusinessModel\Group();
|
||||
|
||||
$group->throwExceptionIfNotExistsGroup($groupUid, $this->arrayFieldNameForException["groupUid"]);
|
||||
|
||||
$process->throwExceptionIfNotExistsUser($userUid, $this->arrayFieldNameForException["userUid"]);
|
||||
|
||||
$this->throwExceptionIfNotExistsGroupUser($groupUid, $userUid, $this->arrayFieldNameForException["userUid"]);
|
||||
|
||||
//Delete
|
||||
$group = new \Groups();
|
||||
|
||||
$group->removeUserOfGroup($groupUid, $userUid);
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
466
workflow/engine/src/ProcessMaker/BusinessModel/InputDocument.php
Normal file
466
workflow/engine/src/ProcessMaker/BusinessModel/InputDocument.php
Normal file
@@ -0,0 +1,466 @@
|
||||
<?php
|
||||
namespace ProcessMaker\BusinessModel;
|
||||
|
||||
class InputDocument
|
||||
{
|
||||
private $arrayFieldDefinition = array(
|
||||
"INP_DOC_UID" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "inputDocumentUid"),
|
||||
|
||||
"INP_DOC_TITLE" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "inputDocumentTitle"),
|
||||
"INP_DOC_DESCRIPTION" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "inputDocumentDescription"),
|
||||
"INP_DOC_FORM_NEEDED" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array("VIRTUAL", "REAL", "VREAL"), "fieldNameAux" => "inputDocumentFormNeeded"),
|
||||
"INP_DOC_ORIGINAL" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array("ORIGINAL", "COPY", "COPYLEGAL"), "fieldNameAux" => "inputDocumentOriginal"),
|
||||
"INP_DOC_PUBLISHED" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array("PRIVATE"), "fieldNameAux" => "inputDocumentPublished"),
|
||||
"INP_DOC_VERSIONING" => array("type" => "int", "required" => false, "empty" => false, "defaultValues" => array(0, 1), "fieldNameAux" => "inputDocumentVersioning"),
|
||||
"INP_DOC_DESTINATION_PATH" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "inputDocumentDestinationPath"),
|
||||
"INP_DOC_TAGS" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "inputDocumentTags")
|
||||
);
|
||||
|
||||
private $formatFieldNameInUppercase = true;
|
||||
|
||||
private $arrayFieldNameForException = array(
|
||||
"processUid" => "PRO_UID"
|
||||
);
|
||||
|
||||
/**
|
||||
* 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($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 title of a InputDocument
|
||||
*
|
||||
* @param string $processUid Unique id of Process
|
||||
* @param string $inputDocumentTitle Title
|
||||
* @param string $inputDocumentUidExclude Unique id of InputDocument to exclude
|
||||
*
|
||||
* return bool Return true if exists the title of a InputDocument, false otherwise
|
||||
*/
|
||||
public function existsTitle($processUid, $inputDocumentTitle, $inputDocumentUidExclude = "")
|
||||
{
|
||||
try {
|
||||
$delimiter = \DBAdapter::getStringDelimiter();
|
||||
|
||||
$criteria = new \Criteria("workflow");
|
||||
|
||||
$criteria->addSelectColumn(\InputDocumentPeer::INP_DOC_UID);
|
||||
|
||||
$criteria->addAlias("CT", \ContentPeer::TABLE_NAME);
|
||||
|
||||
$arrayCondition = array();
|
||||
$arrayCondition[] = array(\InputDocumentPeer::INP_DOC_UID, "CT.CON_ID", \Criteria::EQUAL);
|
||||
$arrayCondition[] = array("CT.CON_CATEGORY", $delimiter . "INP_DOC_TITLE" . $delimiter, \Criteria::EQUAL);
|
||||
$arrayCondition[] = array("CT.CON_LANG", $delimiter . SYS_LANG . $delimiter, \Criteria::EQUAL);
|
||||
$criteria->addJoinMC($arrayCondition, \Criteria::LEFT_JOIN);
|
||||
|
||||
$criteria->add(\InputDocumentPeer::PRO_UID, $processUid, \Criteria::EQUAL);
|
||||
|
||||
if ($inputDocumentUidExclude != "") {
|
||||
$criteria->add(\InputDocumentPeer::INP_DOC_UID, $inputDocumentUidExclude, \Criteria::NOT_EQUAL);
|
||||
}
|
||||
|
||||
$criteria->add("CT.CON_VALUE", $inputDocumentTitle, \Criteria::EQUAL);
|
||||
|
||||
$rsCriteria = \InputDocumentPeer::doSelectRS($criteria);
|
||||
|
||||
if ($rsCriteria->next()) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify if doesn't exists the InputDocument in table INPUT_DOCUMENT
|
||||
*
|
||||
* @param string $inputDocumentUid Unique id of InputDocument
|
||||
* @param string $processUid Unique id of Process
|
||||
* @param string $fieldNameForException Field name for the exception
|
||||
*
|
||||
* return void Throw exception if doesn't exists the InputDocument in table INPUT_DOCUMENT
|
||||
*/
|
||||
public function throwExceptionIfNotExistsInputDocument($inputDocumentUid, $processUid, $fieldNameForException)
|
||||
{
|
||||
try {
|
||||
$criteria = new \Criteria("workflow");
|
||||
|
||||
$criteria->addSelectColumn(\InputDocumentPeer::INP_DOC_UID);
|
||||
|
||||
if ($processUid != "") {
|
||||
$criteria->add(\InputDocumentPeer::PRO_UID, $processUid, \Criteria::EQUAL);
|
||||
}
|
||||
|
||||
$criteria->add(\InputDocumentPeer::INP_DOC_UID, $inputDocumentUid, \Criteria::EQUAL);
|
||||
|
||||
$rsCriteria = \InputDocumentPeer::doSelectRS($criteria);
|
||||
|
||||
if (!$rsCriteria->next()) {
|
||||
$msg = str_replace(array("{0}", "{1}"), array($fieldNameForException, $inputDocumentUid), "The Input Document with {0}: {1} does not exist");
|
||||
|
||||
throw (new \Exception($msg));
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify if exists the title of a InputDocument
|
||||
*
|
||||
* @param string $processUid Unique id of Process
|
||||
* @param string $inputDocumentTitle Title
|
||||
* @param string $fieldNameForException Field name for the exception
|
||||
* @param string $inputDocumentUidExclude Unique id of InputDocument to exclude
|
||||
*
|
||||
* return void Throw exception if exists the title of a InputDocument
|
||||
*/
|
||||
public function throwExceptionIfExistsTitle($processUid, $inputDocumentTitle, $fieldNameForException, $inputDocumentUidExclude = "")
|
||||
{
|
||||
try {
|
||||
if ($this->existsTitle($processUid, $inputDocumentTitle, $inputDocumentUidExclude)) {
|
||||
$msg = str_replace(array("{0}", "{1}"), array($fieldNameForException, $inputDocumentTitle), "The Input Document title with {0}: \"{1}\" already exists");
|
||||
|
||||
throw (new \Exception($msg));
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create InputDocument for a Process
|
||||
*
|
||||
* @param string $processUid Unique id of Process
|
||||
* @param array $arrayData Data
|
||||
*
|
||||
* return array Return data of the new InputDocument created
|
||||
*/
|
||||
public function create($processUid, $arrayData)
|
||||
{
|
||||
try {
|
||||
$arrayData = array_change_key_case($arrayData, CASE_UPPER);
|
||||
|
||||
unset($arrayData["INP_DOC_UID"]);
|
||||
|
||||
//Verify data
|
||||
$process = new \ProcessMaker\BusinessModel\Process();
|
||||
|
||||
$process->throwExceptionIfNotExistsProcess($processUid, $this->arrayFieldNameForException["processUid"]);
|
||||
|
||||
$process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $this->arrayFieldDefinition, $this->arrayFieldNameForException, true);
|
||||
|
||||
$this->throwExceptionIfExistsTitle($processUid, $arrayData["INP_DOC_TITLE"], $this->arrayFieldNameForException["inputDocumentTitle"]);
|
||||
|
||||
//Flags
|
||||
$flagDataDestinationPath = (isset($arrayData["INP_DOC_DESTINATION_PATH"]))? 1 : 0;
|
||||
$flagDataTags = (isset($arrayData["INP_DOC_TAGS"]))? 1 : 0;
|
||||
|
||||
//Create
|
||||
$inputDocument = new \InputDocument();
|
||||
|
||||
$arrayData["PRO_UID"] = $processUid;
|
||||
|
||||
$arrayData["INP_DOC_DESTINATION_PATH"] = ($flagDataDestinationPath == 1)? $arrayData["INP_DOC_DESTINATION_PATH"] : "";
|
||||
$arrayData["INP_DOC_TAGS"] = ($flagDataTags == 1)? $arrayData["INP_DOC_TAGS"] : "";
|
||||
|
||||
$inputDocumentUid = $inputDocument->create($arrayData);
|
||||
|
||||
//Return
|
||||
unset($arrayData["PRO_UID"]);
|
||||
|
||||
if ($flagDataDestinationPath == 0) {
|
||||
unset($arrayData["INP_DOC_DESTINATION_PATH"]);
|
||||
}
|
||||
|
||||
if ($flagDataTags == 0) {
|
||||
unset($arrayData["INP_DOC_TAGS"]);
|
||||
}
|
||||
|
||||
$arrayData = array_merge(array("INP_DOC_UID" => $inputDocumentUid), $arrayData);
|
||||
|
||||
if (!$this->formatFieldNameInUppercase) {
|
||||
$arrayData = array_change_key_case($arrayData, CASE_LOWER);
|
||||
}
|
||||
|
||||
return $arrayData;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update InputDocument
|
||||
*
|
||||
* @param string $inputDocumentUid Unique id of InputDocument
|
||||
* @param array $arrayData Data
|
||||
*
|
||||
* return array Return data of the InputDocument updated
|
||||
*/
|
||||
public function update($inputDocumentUid, $arrayData)
|
||||
{
|
||||
try {
|
||||
$arrayData = array_change_key_case($arrayData, CASE_UPPER);
|
||||
|
||||
//Verify data
|
||||
$this->throwExceptionIfNotExistsInputDocument($inputDocumentUid, "", $this->arrayFieldNameForException["inputDocumentUid"]);
|
||||
|
||||
//Load InputDocument
|
||||
$inputDocument = new \InputDocument();
|
||||
|
||||
$arrayInputDocumentData = $inputDocument->load($inputDocumentUid);
|
||||
|
||||
$processUid = $arrayInputDocumentData["PRO_UID"];
|
||||
|
||||
//Verify data
|
||||
$process = new \ProcessMaker\BusinessModel\Process();
|
||||
|
||||
$process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $this->arrayFieldDefinition, $this->arrayFieldNameForException, false);
|
||||
|
||||
if (isset($arrayData["INP_DOC_TITLE"])) {
|
||||
$this->throwExceptionIfExistsTitle($processUid, $arrayData["INP_DOC_TITLE"], $this->arrayFieldNameForException["inputDocumentTitle"], $inputDocumentUid);
|
||||
}
|
||||
|
||||
//Update
|
||||
$arrayData["INP_DOC_UID"] = $inputDocumentUid;
|
||||
|
||||
$result = $inputDocument->update($arrayData);
|
||||
|
||||
//Return
|
||||
unset($arrayData["INP_DOC_UID"]);
|
||||
|
||||
if (!$this->formatFieldNameInUppercase) {
|
||||
$arrayData = array_change_key_case($arrayData, CASE_LOWER);
|
||||
}
|
||||
|
||||
return $arrayData;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete InputDocument
|
||||
*
|
||||
* @param string $inputDocumentUid Unique id of InputDocument
|
||||
*
|
||||
* return void
|
||||
*/
|
||||
public function delete($inputDocumentUid)
|
||||
{
|
||||
try {
|
||||
//Verify data
|
||||
$this->throwExceptionIfNotExistsInputDocument($inputDocumentUid, "", $this->arrayFieldNameForException["inputDocumentUid"]);
|
||||
|
||||
//Delete
|
||||
//StepSupervisor
|
||||
$stepSupervisor = new \StepSupervisor();
|
||||
|
||||
$arrayData = $stepSupervisor->loadInfo($inputDocumentUid);
|
||||
$result = $stepSupervisor->remove($arrayData["STEP_UID"]);
|
||||
|
||||
//ObjectPermission
|
||||
$objectPermission = new \ObjectPermission();
|
||||
|
||||
$arrayData = $objectPermission->loadInfo($inputDocumentUid);
|
||||
|
||||
if (is_array($arrayData)) {
|
||||
$result = $objectPermission->remove($arrayData["OP_UID"]);
|
||||
}
|
||||
|
||||
//InputDocument
|
||||
$inputDocument = new \InputDocument();
|
||||
|
||||
$result = $inputDocument->remove($inputDocumentUid);
|
||||
|
||||
//Step
|
||||
$step = new \Step();
|
||||
|
||||
$step->removeStep("INPUT_DOCUMENT", $inputDocumentUid);
|
||||
|
||||
//ObjectPermission
|
||||
$objectPermission = new \ObjectPermission();
|
||||
|
||||
$objectPermission->removeByObject("INPUT", $inputDocumentUid);
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get criteria for InputDocument
|
||||
*
|
||||
* return object
|
||||
*/
|
||||
public function getInputDocumentCriteria()
|
||||
{
|
||||
try {
|
||||
$delimiter = \DBAdapter::getStringDelimiter();
|
||||
|
||||
$criteria = new \Criteria("workflow");
|
||||
|
||||
$criteria->addSelectColumn(\InputDocumentPeer::INP_DOC_UID);
|
||||
$criteria->addAsColumn("INP_DOC_TITLE", "CT.CON_VALUE");
|
||||
$criteria->addAsColumn("INP_DOC_DESCRIPTION", "CD.CON_VALUE");
|
||||
$criteria->addSelectColumn(\InputDocumentPeer::INP_DOC_FORM_NEEDED);
|
||||
$criteria->addSelectColumn(\InputDocumentPeer::INP_DOC_ORIGINAL);
|
||||
$criteria->addSelectColumn(\InputDocumentPeer::INP_DOC_PUBLISHED);
|
||||
$criteria->addSelectColumn(\InputDocumentPeer::INP_DOC_VERSIONING);
|
||||
$criteria->addSelectColumn(\InputDocumentPeer::INP_DOC_DESTINATION_PATH);
|
||||
$criteria->addSelectColumn(\InputDocumentPeer::INP_DOC_TAGS);
|
||||
|
||||
$criteria->addAlias("CT", \ContentPeer::TABLE_NAME);
|
||||
$criteria->addAlias("CD", \ContentPeer::TABLE_NAME);
|
||||
|
||||
$arrayCondition = array();
|
||||
$arrayCondition[] = array(\InputDocumentPeer::INP_DOC_UID, "CT.CON_ID", \Criteria::EQUAL);
|
||||
$arrayCondition[] = array("CT.CON_CATEGORY", $delimiter . "INP_DOC_TITLE" . $delimiter, \Criteria::EQUAL);
|
||||
$arrayCondition[] = array("CT.CON_LANG", $delimiter . SYS_LANG . $delimiter, \Criteria::EQUAL);
|
||||
$criteria->addJoinMC($arrayCondition, \Criteria::LEFT_JOIN);
|
||||
|
||||
$arrayCondition = array();
|
||||
$arrayCondition[] = array(\InputDocumentPeer::INP_DOC_UID, "CD.CON_ID", \Criteria::EQUAL);
|
||||
$arrayCondition[] = array("CD.CON_CATEGORY", $delimiter . "INP_DOC_DESCRIPTION" . $delimiter, \Criteria::EQUAL);
|
||||
$arrayCondition[] = array("CD.CON_LANG", $delimiter . SYS_LANG . $delimiter, \Criteria::EQUAL);
|
||||
$criteria->addJoinMC($arrayCondition, \Criteria::LEFT_JOIN);
|
||||
|
||||
return $criteria;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data of an InputDocument from a record
|
||||
*
|
||||
* @param array $record Record
|
||||
*
|
||||
* return array Return an array with data InputDocument
|
||||
*/
|
||||
public function getInputDocumentDataFromRecord($record)
|
||||
{
|
||||
try {
|
||||
if ($record["INP_DOC_TITLE"] . "" == "") {
|
||||
//Load InputDocument
|
||||
$inputDocument = new \InputDocument();
|
||||
|
||||
$arrayInputDocumentData = $inputDocument->load($record["INP_DOC_UID"]);
|
||||
|
||||
//There is no transaltion for this Document name, try to get/regenerate the label
|
||||
$record["INP_DOC_TITLE"] = $arrayInputDocumentData["INP_DOC_TITLE"];
|
||||
$record["INP_DOC_DESCRIPTION"] = $arrayInputDocumentData["INP_DOC_DESCRIPTION"];
|
||||
}
|
||||
|
||||
return array(
|
||||
$this->getFieldNameByFormatFieldName("INP_DOC_UID") => $record["INP_DOC_UID"],
|
||||
$this->getFieldNameByFormatFieldName("INP_DOC_TITLE") => $record["INP_DOC_TITLE"],
|
||||
$this->getFieldNameByFormatFieldName("INP_DOC_DESCRIPTION") => $record["INP_DOC_DESCRIPTION"] . "",
|
||||
$this->getFieldNameByFormatFieldName("INP_DOC_FORM_NEEDED") => $record["INP_DOC_FORM_NEEDED"] . "",
|
||||
$this->getFieldNameByFormatFieldName("INP_DOC_ORIGINAL") => $record["INP_DOC_ORIGINAL"] . "",
|
||||
$this->getFieldNameByFormatFieldName("INP_DOC_PUBLISHED") => $record["INP_DOC_PUBLISHED"] . "",
|
||||
$this->getFieldNameByFormatFieldName("INP_DOC_VERSIONING") => (int)($record["INP_DOC_VERSIONING"]),
|
||||
$this->getFieldNameByFormatFieldName("INP_DOC_DESTINATION_PATH") => $record["INP_DOC_DESTINATION_PATH"] . "",
|
||||
$this->getFieldNameByFormatFieldName("INP_DOC_TAGS") => $record["INP_DOC_TAGS"] . ""
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data of an InputDocument
|
||||
*
|
||||
* @param string $inputDocumentUid Unique id of InputDocument
|
||||
*
|
||||
* return array Return an array with data of an InputDocument
|
||||
*/
|
||||
public function getInputDocument($inputDocumentUid)
|
||||
{
|
||||
try {
|
||||
//Verify data
|
||||
$this->throwExceptionIfNotExistsInputDocument($inputDocumentUid, "", $this->arrayFieldNameForException["inputDocumentUid"]);
|
||||
|
||||
//Get data
|
||||
$criteria = $this->getInputDocumentCriteria();
|
||||
|
||||
$criteria->add(\InputDocumentPeer::INP_DOC_UID, $inputDocumentUid, \Criteria::EQUAL);
|
||||
|
||||
$rsCriteria = \InputDocumentPeer::doSelectRS($criteria);
|
||||
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
|
||||
$rsCriteria->next();
|
||||
|
||||
$row = $rsCriteria->getRow();
|
||||
|
||||
return $this->getInputDocumentDataFromRecord($row);
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,407 @@
|
||||
<?php
|
||||
namespace ProcessMaker\BusinessModel;
|
||||
|
||||
use \G;
|
||||
|
||||
class OutputDocument
|
||||
{
|
||||
/**
|
||||
* Return output documents of a project
|
||||
* @param string $sProcessUID
|
||||
* @return array
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function getOutputDocuments($sProcessUID = '')
|
||||
{
|
||||
try {
|
||||
$sDelimiter = \DBAdapter::getStringDelimiter();
|
||||
$oCriteria = new \Criteria('workflow');
|
||||
$oCriteria->addSelectColumn(\OutputDocumentPeer::OUT_DOC_UID);
|
||||
$oCriteria->addSelectColumn(\OutputDocumentPeer::OUT_DOC_TYPE);
|
||||
$oCriteria->addSelectColumn(\OutputDocumentPeer::PRO_UID);
|
||||
$oCriteria->addSelectColumn(\OutputDocumentPeer::OUT_DOC_REPORT_GENERATOR);
|
||||
$oCriteria->addSelectColumn(\OutputDocumentPeer::OUT_DOC_LANDSCAPE);
|
||||
$oCriteria->addSelectColumn(\OutputDocumentPeer::OUT_DOC_MEDIA);
|
||||
$oCriteria->addSelectColumn(\OutputDocumentPeer::OUT_DOC_LEFT_MARGIN);
|
||||
$oCriteria->addSelectColumn(\OutputDocumentPeer::OUT_DOC_RIGHT_MARGIN);
|
||||
$oCriteria->addSelectColumn(\OutputDocumentPeer::OUT_DOC_TOP_MARGIN);
|
||||
$oCriteria->addSelectColumn(\OutputDocumentPeer::OUT_DOC_BOTTOM_MARGIN);
|
||||
$oCriteria->addSelectColumn(\OutputDocumentPeer::OUT_DOC_GENERATE);
|
||||
$oCriteria->addSelectColumn(\OutputDocumentPeer::OUT_DOC_TYPE);
|
||||
$oCriteria->addSelectColumn(\OutputDocumentPeer::OUT_DOC_CURRENT_REVISION);
|
||||
$oCriteria->addSelectColumn(\OutputDocumentPeer::OUT_DOC_FIELD_MAPPING);
|
||||
$oCriteria->addSelectColumn(\OutputDocumentPeer::OUT_DOC_VERSIONING);
|
||||
$oCriteria->addSelectColumn(\OutputDocumentPeer::OUT_DOC_DESTINATION_PATH);
|
||||
$oCriteria->addSelectColumn(\OutputDocumentPeer::OUT_DOC_TAGS);
|
||||
$oCriteria->addSelectColumn(\OutputDocumentPeer::OUT_DOC_PDF_SECURITY_ENABLED);
|
||||
$oCriteria->addSelectColumn(\OutputDocumentPeer::OUT_DOC_PDF_SECURITY_OPEN_PASSWORD);
|
||||
$oCriteria->addSelectColumn(\OutputDocumentPeer::OUT_DOC_PDF_SECURITY_OWNER_PASSWORD);
|
||||
$oCriteria->addSelectColumn(\OutputDocumentPeer::OUT_DOC_PDF_SECURITY_PERMISSIONS);
|
||||
$oCriteria->addAsColumn('OUT_DOC_TITLE', 'C1.CON_VALUE');
|
||||
$oCriteria->addAsColumn('OUT_DOC_DESCRIPTION', 'C2.CON_VALUE');
|
||||
$oCriteria->addAsColumn('OUT_DOC_FILENAME', 'C3.CON_VALUE');
|
||||
$oCriteria->addAsColumn('OUT_DOC_TEMPLATE', 'C4.CON_VALUE');
|
||||
$oCriteria->addAlias('C1', 'CONTENT');
|
||||
$oCriteria->addAlias('C2', 'CONTENT');
|
||||
$oCriteria->addAlias('C3', 'CONTENT');
|
||||
$oCriteria->addAlias('C4', 'CONTENT');
|
||||
$aConditions = array();
|
||||
$aConditions[] = array(\OutputDocumentPeer::OUT_DOC_UID, 'C1.CON_ID' );
|
||||
$aConditions[] = array('C1.CON_CATEGORY', $sDelimiter . 'OUT_DOC_TITLE' . $sDelimiter );
|
||||
$aConditions[] = array('C1.CON_LANG', $sDelimiter . SYS_LANG . $sDelimiter );
|
||||
$oCriteria->addJoinMC($aConditions, \Criteria::LEFT_JOIN);
|
||||
$aConditions = array();
|
||||
$aConditions[] = array(\OutputDocumentPeer::OUT_DOC_UID, 'C2.CON_ID' );
|
||||
$aConditions[] = array('C2.CON_CATEGORY', $sDelimiter . 'OUT_DOC_DESCRIPTION' . $sDelimiter );
|
||||
$aConditions[] = array('C2.CON_LANG', $sDelimiter . SYS_LANG . $sDelimiter );
|
||||
$oCriteria->addJoinMC($aConditions, \Criteria::LEFT_JOIN);
|
||||
$aConditions = array();
|
||||
$aConditions[] = array(\OutputDocumentPeer::OUT_DOC_UID, 'C3.CON_ID' );
|
||||
$aConditions[] = array('C3.CON_CATEGORY', $sDelimiter . 'OUT_DOC_FILENAME' . $sDelimiter );
|
||||
$aConditions[] = array('C3.CON_LANG', $sDelimiter . SYS_LANG . $sDelimiter );
|
||||
$oCriteria->addJoinMC($aConditions, \Criteria::LEFT_JOIN);
|
||||
$aConditions = array();
|
||||
$aConditions[] = array(\OutputDocumentPeer::OUT_DOC_UID, 'C4.CON_ID' );
|
||||
$aConditions[] = array('C4.CON_CATEGORY', $sDelimiter . 'OUT_DOC_TEMPLATE' . $sDelimiter );
|
||||
$aConditions[] = array('C4.CON_LANG', $sDelimiter . SYS_LANG . $sDelimiter );
|
||||
$oCriteria->addJoinMC($aConditions, \Criteria::LEFT_JOIN);
|
||||
$oCriteria->add(\OutputDocumentPeer::PRO_UID, $sProcessUID);
|
||||
$oDataset = \OutputDocumentPeer::doSelectRS($oCriteria);
|
||||
$oDataset->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
$oDataset->next();
|
||||
$outputDocArray = array();
|
||||
while ($aRow = $oDataset->getRow()) {
|
||||
if (($aRow['OUT_DOC_TITLE'] == null) || ($aRow['OUT_DOC_TITLE'] == "")) {
|
||||
// There is no transaltion for this Document name, try to get/regenerate the label
|
||||
$outputDocument = new \OutputDocument();
|
||||
$outputDocumentObj = $outputDocument->load($aRow['OUT_DOC_UID']);
|
||||
$aRow['OUT_DOC_TITLE'] = $outputDocumentObj['OUT_DOC_TITLE'];
|
||||
$aRow['OUT_DOC_DESCRIPTION'] = $outputDocumentObj['OUT_DOC_DESCRIPTION'];
|
||||
} else {
|
||||
$outputDocArray[] = array('out_doc_uid' => $aRow['OUT_DOC_UID'],
|
||||
'out_doc_title' => $aRow['OUT_DOC_TITLE'],
|
||||
'out_doc_description' => $aRow['OUT_DOC_DESCRIPTION'],
|
||||
'out_doc_filename' => $aRow['OUT_DOC_FILENAME'],
|
||||
'out_doc_template' => $aRow['OUT_DOC_TEMPLATE'],
|
||||
'out_doc_report_generator' => $aRow['OUT_DOC_REPORT_GENERATOR'],
|
||||
'out_doc_landscape' => $aRow['OUT_DOC_LANDSCAPE'],
|
||||
'out_doc_media' => $aRow['OUT_DOC_MEDIA'],
|
||||
'out_doc_left_margin' => $aRow['OUT_DOC_LEFT_MARGIN'],
|
||||
'out_doc_right_margin' => $aRow['OUT_DOC_RIGHT_MARGIN'],
|
||||
'out_doc_top_margin' => $aRow['OUT_DOC_TOP_MARGIN'],
|
||||
'out_doc_bottom_margin' => $aRow['OUT_DOC_BOTTOM_MARGIN'],
|
||||
'out_doc_generate' => $aRow['OUT_DOC_GENERATE'],
|
||||
'out_doc_type' => $aRow['OUT_DOC_TYPE'],
|
||||
'out_doc_current_revision' => $aRow['OUT_DOC_CURRENT_REVISION'],
|
||||
'out_doc_field_mapping' => $aRow['OUT_DOC_FIELD_MAPPING'],
|
||||
'out_doc_versioning' => $aRow['OUT_DOC_VERSIONING'],
|
||||
'out_doc_destination_path' => $aRow['OUT_DOC_DESTINATION_PATH'],
|
||||
'out_doc_tags' => $aRow['OUT_DOC_TAGS'],
|
||||
'out_doc_pdf_security_enabled' => $aRow['OUT_DOC_PDF_SECURITY_ENABLED'],
|
||||
'out_doc_pdf_security_open_password' => $aRow['OUT_DOC_PDF_SECURITY_OPEN_PASSWORD'],
|
||||
'out_doc_pdf_security_owner_password' => $aRow['OUT_DOC_PDF_SECURITY_OWNER_PASSWORD'],
|
||||
'out_doc_pdf_security_permissions' => $aRow['OUT_DOC_PDF_SECURITY_PERMISSIONS']);
|
||||
}
|
||||
$oDataset->next();
|
||||
}
|
||||
return $outputDocArray;
|
||||
} catch (Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a single output document of a project
|
||||
* @param string $sProcessUID
|
||||
* @param string $sOutputDocumentUID
|
||||
* @return array
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function getOutputDocument($sProcessUID = '', $sOutputDocumentUID = '')
|
||||
{
|
||||
try {
|
||||
$sDelimiter = \DBAdapter::getStringDelimiter();
|
||||
$oCriteria = new \Criteria('workflow');
|
||||
$oCriteria->addSelectColumn(\OutputDocumentPeer::OUT_DOC_UID);
|
||||
$oCriteria->addSelectColumn(\OutputDocumentPeer::OUT_DOC_TYPE);
|
||||
$oCriteria->addSelectColumn(\OutputDocumentPeer::PRO_UID);
|
||||
$oCriteria->addSelectColumn(\OutputDocumentPeer::OUT_DOC_REPORT_GENERATOR);
|
||||
$oCriteria->addSelectColumn(\OutputDocumentPeer::OUT_DOC_LANDSCAPE);
|
||||
$oCriteria->addSelectColumn(\OutputDocumentPeer::OUT_DOC_MEDIA);
|
||||
$oCriteria->addSelectColumn(\OutputDocumentPeer::OUT_DOC_LEFT_MARGIN);
|
||||
$oCriteria->addSelectColumn(\OutputDocumentPeer::OUT_DOC_RIGHT_MARGIN);
|
||||
$oCriteria->addSelectColumn(\OutputDocumentPeer::OUT_DOC_TOP_MARGIN);
|
||||
$oCriteria->addSelectColumn(\OutputDocumentPeer::OUT_DOC_BOTTOM_MARGIN);
|
||||
$oCriteria->addSelectColumn(\OutputDocumentPeer::OUT_DOC_GENERATE);
|
||||
$oCriteria->addSelectColumn(\OutputDocumentPeer::OUT_DOC_TYPE);
|
||||
$oCriteria->addSelectColumn(\OutputDocumentPeer::OUT_DOC_CURRENT_REVISION);
|
||||
$oCriteria->addSelectColumn(\OutputDocumentPeer::OUT_DOC_FIELD_MAPPING);
|
||||
$oCriteria->addSelectColumn(\OutputDocumentPeer::OUT_DOC_VERSIONING);
|
||||
$oCriteria->addSelectColumn(\OutputDocumentPeer::OUT_DOC_DESTINATION_PATH);
|
||||
$oCriteria->addSelectColumn(\OutputDocumentPeer::OUT_DOC_TAGS);
|
||||
$oCriteria->addSelectColumn(\OutputDocumentPeer::OUT_DOC_PDF_SECURITY_ENABLED);
|
||||
$oCriteria->addSelectColumn(\OutputDocumentPeer::OUT_DOC_PDF_SECURITY_OPEN_PASSWORD);
|
||||
$oCriteria->addSelectColumn(\OutputDocumentPeer::OUT_DOC_PDF_SECURITY_OWNER_PASSWORD);
|
||||
$oCriteria->addSelectColumn(\OutputDocumentPeer::OUT_DOC_PDF_SECURITY_PERMISSIONS);
|
||||
$oCriteria->add(\OutputDocumentPeer::OUT_DOC_UID, $sOutputDocumentUID);
|
||||
$oCriteria->addAsColumn('OUT_DOC_TITLE', 'C1.CON_VALUE');
|
||||
$oCriteria->addAsColumn('OUT_DOC_DESCRIPTION', 'C2.CON_VALUE');
|
||||
$oCriteria->addAsColumn('OUT_DOC_FILENAME', 'C3.CON_VALUE');
|
||||
$oCriteria->addAsColumn('OUT_DOC_TEMPLATE', 'C4.CON_VALUE');
|
||||
$oCriteria->addAlias('C1', 'CONTENT');
|
||||
$oCriteria->addAlias('C2', 'CONTENT');
|
||||
$oCriteria->addAlias('C3', 'CONTENT');
|
||||
$oCriteria->addAlias('C4', 'CONTENT');
|
||||
$aConditions = array();
|
||||
$aConditions[] = array(\OutputDocumentPeer::OUT_DOC_UID, 'C1.CON_ID' );
|
||||
$aConditions[] = array('C1.CON_CATEGORY', $sDelimiter . 'OUT_DOC_TITLE' . $sDelimiter );
|
||||
$aConditions[] = array('C1.CON_LANG', $sDelimiter . SYS_LANG . $sDelimiter );
|
||||
$oCriteria->addJoinMC($aConditions, \Criteria::LEFT_JOIN);
|
||||
$aConditions = array();
|
||||
$aConditions[] = array(\OutputDocumentPeer::OUT_DOC_UID, 'C2.CON_ID' );
|
||||
$aConditions[] = array('C2.CON_CATEGORY', $sDelimiter . 'OUT_DOC_DESCRIPTION' . $sDelimiter );
|
||||
$aConditions[] = array('C2.CON_LANG', $sDelimiter . SYS_LANG . $sDelimiter );
|
||||
$oCriteria->addJoinMC($aConditions, \Criteria::LEFT_JOIN);
|
||||
$aConditions = array();
|
||||
$aConditions[] = array(\OutputDocumentPeer::OUT_DOC_UID, 'C3.CON_ID' );
|
||||
$aConditions[] = array('C3.CON_CATEGORY', $sDelimiter . 'OUT_DOC_FILENAME' . $sDelimiter );
|
||||
$aConditions[] = array('C3.CON_LANG', $sDelimiter . SYS_LANG . $sDelimiter );
|
||||
$oCriteria->addJoinMC($aConditions, \Criteria::LEFT_JOIN);
|
||||
$aConditions = array();
|
||||
$aConditions[] = array(\OutputDocumentPeer::OUT_DOC_UID, 'C4.CON_ID' );
|
||||
$aConditions[] = array('C4.CON_CATEGORY', $sDelimiter . 'OUT_DOC_TEMPLATE' . $sDelimiter );
|
||||
$aConditions[] = array('C4.CON_LANG', $sDelimiter . SYS_LANG . $sDelimiter );
|
||||
$oCriteria->addJoinMC($aConditions, \Criteria::LEFT_JOIN);
|
||||
$oCriteria->add(\OutputDocumentPeer::PRO_UID, $sProcessUID);
|
||||
$oDataset = \OutputDocumentPeer::doSelectRS($oCriteria);
|
||||
$oDataset->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
$oDataset->next();
|
||||
$outputDocArray = array();
|
||||
while ($aRow = $oDataset->getRow()) {
|
||||
if (($aRow['OUT_DOC_TITLE'] == null) || ($aRow['OUT_DOC_TITLE'] == "")) {
|
||||
// There is no transaltion for this Document name, try to get/regenerate the label
|
||||
$outputDocument = new \OutputDocument();
|
||||
$outputDocumentObj = $outputDocument->load($aRow['OUT_DOC_UID']);
|
||||
$aRow['OUT_DOC_TITLE'] = $outputDocumentObj['OUT_DOC_TITLE'];
|
||||
$aRow['OUT_DOC_DESCRIPTION'] = $outputDocumentObj['OUT_DOC_DESCRIPTION'];
|
||||
} else {
|
||||
$outputDocArray = array('out_doc_uid' => $aRow['OUT_DOC_UID'],
|
||||
'out_doc_title' => $aRow['OUT_DOC_TITLE'],
|
||||
'out_doc_description' => $aRow['OUT_DOC_DESCRIPTION'],
|
||||
'out_doc_filename' => $aRow['OUT_DOC_FILENAME'],
|
||||
'out_doc_template' => $aRow['OUT_DOC_TEMPLATE'],
|
||||
'out_doc_report_generator' => $aRow['OUT_DOC_REPORT_GENERATOR'],
|
||||
'out_doc_landscape' => $aRow['OUT_DOC_LANDSCAPE'],
|
||||
'out_doc_media' => $aRow['OUT_DOC_MEDIA'],
|
||||
'out_doc_left_margin' => $aRow['OUT_DOC_LEFT_MARGIN'],
|
||||
'out_doc_right_margin' => $aRow['OUT_DOC_RIGHT_MARGIN'],
|
||||
'out_doc_top_margin' => $aRow['OUT_DOC_TOP_MARGIN'],
|
||||
'out_doc_bottom_margin' => $aRow['OUT_DOC_BOTTOM_MARGIN'],
|
||||
'out_doc_generate' => $aRow['OUT_DOC_GENERATE'],
|
||||
'out_doc_type' => $aRow['OUT_DOC_TYPE'],
|
||||
'out_doc_current_revision' => $aRow['OUT_DOC_CURRENT_REVISION'],
|
||||
'out_doc_field_mapping' => $aRow['OUT_DOC_FIELD_MAPPING'],
|
||||
'out_doc_versioning' => $aRow['OUT_DOC_VERSIONING'],
|
||||
'out_doc_destination_path' => $aRow['OUT_DOC_DESTINATION_PATH'],
|
||||
'out_doc_tags' => $aRow['OUT_DOC_TAGS'],
|
||||
'out_doc_pdf_security_enabled' => $aRow['OUT_DOC_PDF_SECURITY_ENABLED'],
|
||||
'out_doc_pdf_security_open_password' => $aRow['OUT_DOC_PDF_SECURITY_OPEN_PASSWORD'],
|
||||
'out_doc_pdf_security_owner_password' => $aRow['OUT_DOC_PDF_SECURITY_OWNER_PASSWORD'],
|
||||
'out_doc_pdf_security_permissions' => $aRow['OUT_DOC_PDF_SECURITY_PERMISSIONS']);
|
||||
}
|
||||
$oDataset->next();
|
||||
}
|
||||
return $outputDocArray;
|
||||
} catch (Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new output document for a project
|
||||
* @param string $sProcessUID
|
||||
* @param array $aData
|
||||
* @return array
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function addOutputDocument($sProcessUID, $aData)
|
||||
{
|
||||
$pemission = $aData['out_doc_pdf_security_permissions'];
|
||||
$pemission = explode("|", $pemission);
|
||||
foreach ($pemission as $row) {
|
||||
if ($row == "print" || $row == "modify" || $row == "copy" || $row == "forms" || $row == "") {
|
||||
$aData['out_doc_pdf_security_permissions'] = $aData['out_doc_pdf_security_permissions'];
|
||||
} else {
|
||||
throw (new \Exception( 'Invalid value specified for `out_doc_pdf_security_permissions`'));
|
||||
}
|
||||
}
|
||||
try {
|
||||
require_once(PATH_TRUNK . "workflow" . PATH_SEP . "engine" . PATH_SEP . "classes" . PATH_SEP . "model" . PATH_SEP . "OutputDocument.php");
|
||||
$aData = array_change_key_case($aData, CASE_UPPER);
|
||||
$aData['PRO_UID'] = $sProcessUID;
|
||||
//Verify data
|
||||
$process = new \Process();
|
||||
if (!$process->exists($sProcessUID)) {
|
||||
throw (new \Exception(str_replace(array("{0}", "{1}"), array($sProcessUID, "PROCESS"), "The UID \"{0}\" doesn't exist in table {1}")));
|
||||
}
|
||||
if ($aData["OUT_DOC_TITLE"]=="") {
|
||||
throw (new \Exception( 'Invalid value specified for `out_doc_title`, can`t be null'));
|
||||
}
|
||||
if (isset($aData["OUT_DOC_TITLE"]) && $this->existsTitle($sProcessUID, $aData["OUT_DOC_TITLE"])) {
|
||||
throw (new \Exception(\G::LoadTranslation("ID_OUTPUT_NOT_SAVE")));
|
||||
}
|
||||
$oOutputDocument = new \OutputDocument();
|
||||
if (isset( $aData['OUT_DOC_TITLE'] ) && $aData['OUT_DOC_TITLE'] != '') {
|
||||
if (isset( $aData['OUT_DOC_PDF_SECURITY_ENABLED'] ) && $aData['OUT_DOC_PDF_SECURITY_ENABLED'] == "0") {
|
||||
$aData['OUT_DOC_PDF_SECURITY_OPEN_PASSWORD'] = "";
|
||||
$aData['OUT_DOC_PDF_SECURITY_OWNER_PASSWORD'] = "";
|
||||
$aData['OUT_DOC_PDF_SECURITY_PERMISSIONS'] = "";
|
||||
}
|
||||
}
|
||||
$outDocUid = $oOutputDocument->create($aData);
|
||||
$aData = array_change_key_case($aData, CASE_LOWER);
|
||||
if (isset( $aData['out_doc_pdf_security_open_password'] ) && $aData['out_doc_pdf_security_open_password'] != "") {
|
||||
$aData['out_doc_pdf_security_open_password'] = \G::encrypt( $aData['out_doc_pdf_security_open_password'], $outDocUid );
|
||||
$aData['out_doc_pdf_security_owner_password'] = \G::encrypt( $aData['out_doc_pdf_security_owner_password'], $outDocUid );
|
||||
}
|
||||
$this->updateOutputDocument($sProcessUID, $aData, $outDocUid, 1);
|
||||
//Return
|
||||
unset($aData["PRO_UID"]);
|
||||
$aData = array_change_key_case($aData, CASE_LOWER);
|
||||
$aData["out_doc_uid"] = $outDocUid;
|
||||
return $aData;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a output document for a project
|
||||
* @param string $sProcessUID
|
||||
* @param array $aData
|
||||
* @param string $sOutputDocumentUID
|
||||
* @param int $sFlag
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function updateOutputDocument($sProcessUID, $aData, $sOutputDocumentUID = '', $sFlag)
|
||||
{
|
||||
$oConnection = \Propel::getConnection(\OutputDocumentPeer::DATABASE_NAME);
|
||||
$pemission = $aData['out_doc_pdf_security_permissions'];
|
||||
$pemission = explode("|", $pemission);
|
||||
foreach ($pemission as $row) {
|
||||
if ($row == "print" || $row == "modify" || $row == "copy" || $row == "forms" || $row == "") {
|
||||
$aData['out_doc_pdf_security_permissions'] = $aData['out_doc_pdf_security_permissions'];
|
||||
} else {
|
||||
throw (new \Exception( 'Invalid value specified for `out_doc_pdf_security_permissions`'));
|
||||
}
|
||||
}
|
||||
try {
|
||||
$aData = array_change_key_case($aData, CASE_UPPER);
|
||||
$oOutputDocument = \OutputDocumentPeer::retrieveByPK($sOutputDocumentUID);
|
||||
if (!is_null($oOutputDocument)) {
|
||||
$oOutputDocument->fromArray($aData, \BasePeer::TYPE_FIELDNAME);
|
||||
if ($oOutputDocument->validate()) {
|
||||
$oConnection->begin();
|
||||
if (isset($aData['OUT_DOC_TITLE'])) {
|
||||
if ($this->existsTitle($sProcessUID, $aData["OUT_DOC_TITLE"]) && $sFlag == 0) {
|
||||
throw (new \Exception(\G::LoadTranslation("ID_OUTPUT_NOT_SAVE")));
|
||||
}
|
||||
$oOutputDocument->setOutDocTitle($aData['OUT_DOC_TITLE']);
|
||||
}
|
||||
if (isset($aData['OUT_DOC_DESCRIPTION'])) {
|
||||
$oOutputDocument->setOutDocDescription($aData['OUT_DOC_DESCRIPTION']);
|
||||
}
|
||||
if (isset($aData['OUT_DOC_FILENAME'])) {
|
||||
$oOutputDocument->setOutDocFilename($aData['OUT_DOC_FILENAME']);
|
||||
}
|
||||
if (isset($aData['OUT_DOC_TEMPLATE'])) {
|
||||
$oOutputDocument->setOutDocTemplate($aData['OUT_DOC_TEMPLATE']);
|
||||
}
|
||||
$iResult = $oOutputDocument->save();
|
||||
$oConnection->commit();
|
||||
} else {
|
||||
$sMessage = '';
|
||||
$aValidationFailures = $oOutputDocument->getValidationFailures();
|
||||
foreach ($aValidationFailures as $oValidationFailure) {
|
||||
$sMessage .= $oValidationFailure->getMessage();
|
||||
}
|
||||
throw (new \Exception('The registry cannot be updated!' . $sMessage));
|
||||
}
|
||||
} else {
|
||||
throw (new \Exception('This row does not exist!'));
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a output document of a project
|
||||
*
|
||||
* @param string $sProcessUID
|
||||
* @param string $sOutputDocumentUID
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function deleteOutputDocument($sProcessUID, $sOutputDocumentUID)
|
||||
{
|
||||
try {
|
||||
require_once(PATH_TRUNK . "workflow" . PATH_SEP . "engine" . PATH_SEP . "classes" . PATH_SEP . "model" . PATH_SEP . "OutputDocument.php");
|
||||
require_once (PATH_TRUNK . "workflow" . PATH_SEP . "engine" . PATH_SEP . "classes" . PATH_SEP . "model" . PATH_SEP . "ObjectPermission.php");
|
||||
require_once(PATH_TRUNK . "workflow" . PATH_SEP . "engine" . PATH_SEP . "classes" . PATH_SEP . "model" . PATH_SEP . "Step.php");
|
||||
\G::LoadClass( 'processMap' );
|
||||
$oOutputDocument = new \OutputDocument();
|
||||
$fields = $oOutputDocument->load( $sOutputDocumentUID );
|
||||
$oOutputDocument->remove( $sOutputDocumentUID );
|
||||
$oStep = new \Step();
|
||||
$oStep->removeStep( 'OUTPUT_DOCUMENT', $sOutputDocumentUID );
|
||||
$oOP = new \ObjectPermission();
|
||||
$oOP->removeByObject( 'OUTPUT', $sOutputDocumentUID );
|
||||
//refresh dbarray with the last change in outputDocument
|
||||
$oMap = new \processMap();
|
||||
$oCriteria = $oMap->getOutputDocumentsCriteria( $fields['PRO_UID'] );
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the title exists in the OutputDocuments of Process
|
||||
*
|
||||
* @param string $processUid Unique id of Process
|
||||
* @param string $title Title
|
||||
* @param string $outputDocumentUidExclude Unique id of InputDocument to exclude
|
||||
*
|
||||
* return bool Return true if the title exists in the OutputDocuments of Process, false otherwise
|
||||
*/
|
||||
public function existsTitle($processUid, $title)
|
||||
{
|
||||
try {
|
||||
$delimiter = \DBAdapter::getStringDelimiter();
|
||||
$criteria = new \Criteria("workflow");
|
||||
$criteria->addSelectColumn(\OutputDocumentPeer::OUT_DOC_UID);
|
||||
$criteria->addAlias("CT", "CONTENT");
|
||||
$arrayCondition = array();
|
||||
$arrayCondition[] = array(\OutputDocumentPeer::OUT_DOC_UID, "CT.CON_ID", \Criteria::EQUAL);
|
||||
$arrayCondition[] = array("CT.CON_CATEGORY", $delimiter . "OUT_DOC_TITLE" . $delimiter, \Criteria::EQUAL);
|
||||
$arrayCondition[] = array("CT.CON_LANG", $delimiter . SYS_LANG . $delimiter, \Criteria::EQUAL);
|
||||
$criteria->addJoinMC($arrayCondition, \Criteria::LEFT_JOIN);
|
||||
$criteria->add(\OutputDocumentPeer::PRO_UID, $processUid, \Criteria::EQUAL);
|
||||
$criteria->add(\ContentPeer::CON_VALUE, $title, \Criteria::EQUAL);
|
||||
$rsCriteria = \OutputDocumentPeer::doSelectRS($criteria);
|
||||
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
if ($rsCriteria->next()) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
1803
workflow/engine/src/ProcessMaker/BusinessModel/Process.php
Normal file
1803
workflow/engine/src/ProcessMaker/BusinessModel/Process.php
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,402 @@
|
||||
<?php
|
||||
namespace ProcessMaker\BusinessModel;
|
||||
|
||||
class ProcessCategory
|
||||
{
|
||||
private $arrayFieldDefinition = array(
|
||||
"CAT_UID" => array("fieldName" => "CATEGORY_UID", "type" => "string", "required" => false, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "processCategoryUid"),
|
||||
|
||||
"CAT_PARENT" => array("fieldName" => "CATEGORY_PARENT", "type" => "string", "required" => false, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "processCategoryParent"),
|
||||
"CAT_NAME" => array("fieldName" => "CATEGORY_NAME", "type" => "string", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "processCategoryName"),
|
||||
"CAT_ICON" => array("fieldName" => "CATEGORY_ICON", "type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "processCategoryIcon")
|
||||
);
|
||||
|
||||
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($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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get criteria for Process Category
|
||||
*
|
||||
* return object
|
||||
*/
|
||||
public function getProcessCategoryCriteria()
|
||||
{
|
||||
try {
|
||||
$criteria = new \Criteria("workflow");
|
||||
$criteria->addSelectColumn(\ProcessCategoryPeer::CATEGORY_UID);
|
||||
$criteria->addSelectColumn(\ProcessCategoryPeer::CATEGORY_PARENT);
|
||||
$criteria->addSelectColumn(\ProcessCategoryPeer::CATEGORY_NAME);
|
||||
$criteria->addSelectColumn(\ProcessCategoryPeer::CATEGORY_ICON);
|
||||
$criteria->add(\ProcessCategoryPeer::CATEGORY_UID, "", \Criteria::NOT_EQUAL);
|
||||
|
||||
return $criteria;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data of a Process Category from a record
|
||||
*
|
||||
* @param array $record Record
|
||||
*
|
||||
* return array Return an array with data Process Category
|
||||
*/
|
||||
public function getProcessCategoryDataFromRecord($record)
|
||||
{
|
||||
try {
|
||||
return array(
|
||||
$this->getFieldNameByFormatFieldName("CAT_UID") => $record["CATEGORY_UID"],
|
||||
$this->getFieldNameByFormatFieldName("CAT_NAME") => $record["CATEGORY_NAME"],
|
||||
$this->getFieldNameByFormatFieldName("CAT_TOTAL_PROCESSES") => (int)($record["CATEGORY_TOTAL_PROCESSES"])
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all Process Categories
|
||||
*
|
||||
* @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 Process Categories
|
||||
*/
|
||||
public function getCategories($arrayFilterData = null, $sortField = null, $sortDir = null, $start = null, $limit = null)
|
||||
{
|
||||
try {
|
||||
$arrayProcessCategory = 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 $arrayProcessCategory;
|
||||
}
|
||||
|
||||
//Set variables
|
||||
$process = new \Process();
|
||||
|
||||
$arrayTotalProcessesByCategory = $process->getAllProcessesByCategory();
|
||||
|
||||
//SQL
|
||||
$criteria = $this->getProcessCategoryCriteria();
|
||||
|
||||
if (!is_null($arrayFilterData) && is_array($arrayFilterData) && isset($arrayFilterData["filter"]) && trim($arrayFilterData["filter"]) != "") {
|
||||
$criteria->add(\ProcessCategoryPeer::CATEGORY_NAME, "%" . $arrayFilterData["filter"] . "%", \Criteria::LIKE);
|
||||
}
|
||||
|
||||
//Number records total
|
||||
$criteriaCount = clone $criteria;
|
||||
|
||||
$criteriaCount->clearSelectColumns();
|
||||
$criteriaCount->addSelectColumn("COUNT(" . \ProcessCategoryPeer::CATEGORY_UID . ") AS NUM_REC");
|
||||
|
||||
$rsCriteriaCount = \ProcessCategoryPeer::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);
|
||||
$sortField = (isset($this->arrayFieldDefinition[$sortField]["fieldName"]))? $this->arrayFieldDefinition[$sortField]["fieldName"] : $sortField;
|
||||
|
||||
switch ($sortField) {
|
||||
case "CATEGORY_UID":
|
||||
case "CATEGORY_PARENT":
|
||||
case "CATEGORY_NAME":
|
||||
case "CATEGORY_ICON":
|
||||
$sortField = \ProcessCategoryPeer::TABLE_NAME . "." . $sortField;
|
||||
break;
|
||||
default:
|
||||
$sortField = \ProcessCategoryPeer::CATEGORY_NAME;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
$sortField = \ProcessCategoryPeer::CATEGORY_NAME;
|
||||
}
|
||||
|
||||
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 = \ProcessCategoryPeer::doSelectRS($criteria);
|
||||
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
|
||||
while ($rsCriteria->next()) {
|
||||
$row = $rsCriteria->getRow();
|
||||
|
||||
$row["CATEGORY_TOTAL_PROCESSES"] = (isset($arrayTotalProcessesByCategory[$row["CATEGORY_UID"]]))? $arrayTotalProcessesByCategory[$row["CATEGORY_UID"]] : 0;
|
||||
|
||||
$arrayProcessCategory[] = $this->getProcessCategoryDataFromRecord($row);
|
||||
}
|
||||
|
||||
//Return
|
||||
return $arrayProcessCategory;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a Process Category
|
||||
*
|
||||
* @param string $cat_uid Category Id
|
||||
*
|
||||
* return array Return an object with the Process Category
|
||||
*/
|
||||
public function getCategory($cat_uid)
|
||||
{
|
||||
try {
|
||||
$oProcessCategory = '';
|
||||
$process = new \Process();
|
||||
$oTotalProcessesByCategory = $process->getAllProcessesByCategory();
|
||||
$criteria = $this->getAProcessCategoryCriteria($cat_uid);
|
||||
$criteriaCount = clone $criteria;
|
||||
$criteriaCount->clearSelectColumns();
|
||||
$criteriaCount->addSelectColumn("COUNT(" . \ProcessCategoryPeer::CATEGORY_UID . ") AS NUM_REC");
|
||||
$rsCriteriaCount = \ProcessCategoryPeer::doSelectRS($criteriaCount);
|
||||
$rsCriteriaCount->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
$rsCriteriaCount->next();
|
||||
$rsCriteria = \ProcessCategoryPeer::doSelectRS($criteria);
|
||||
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
while ($rsCriteria->next()) {
|
||||
$row = $rsCriteria->getRow();
|
||||
$row["CATEGORY_TOTAL_PROCESSES"] = (isset($oTotalProcessesByCategory[$row["CATEGORY_UID"]]))? $oTotalProcessesByCategory[$row["CATEGORY_UID"]] : 0;
|
||||
$oProcessCategory = $this->getProcessCategoryDataFromRecord($row);
|
||||
}
|
||||
//Return
|
||||
if ($oProcessCategory != '') {
|
||||
return $oProcessCategory;
|
||||
} else {
|
||||
throw (new \Exception( 'The Category with cat_uid: '.$cat_uid.' doesn\'t exist!'));
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Post Process Category
|
||||
*
|
||||
* @param string $cat_name Name of Category
|
||||
*
|
||||
* return array
|
||||
*/
|
||||
public function addCategory($cat_name)
|
||||
{
|
||||
try {
|
||||
require_once 'classes/model/ProcessCategory.php';
|
||||
$catName = trim( $cat_name );
|
||||
if ($this->existsName( $cat_name )) {
|
||||
throw (new \Exception( 'cat_name. Duplicate Process Category name'));
|
||||
}
|
||||
$catUid = \G::GenerateUniqueID();
|
||||
$pcat = new \ProcessCategory();
|
||||
$pcat->setNew( true );
|
||||
$pcat->setCategoryUid( $catUid );
|
||||
$pcat->setCategoryName( $catName );
|
||||
$pcat->save();
|
||||
$oProcessCategory = array_change_key_case($this->getCategory( $catUid ), CASE_LOWER);
|
||||
//Return
|
||||
return $oProcessCategory;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Put Process Category
|
||||
*
|
||||
* @param string $cat_uid Category id
|
||||
* @param string $cat_name Category Name
|
||||
*
|
||||
* return array
|
||||
*/
|
||||
public function updateCategory($cat_uid, $cat_name)
|
||||
{
|
||||
try {
|
||||
require_once 'classes/model/ProcessCategory.php';
|
||||
$catUID = $cat_uid;
|
||||
$catName = trim( $cat_name );
|
||||
if ($this->existsName( $cat_name )) {
|
||||
throw (new \Exception( 'cat_name. Duplicate Process Category name'));
|
||||
}
|
||||
$pcat = new \ProcessCategory();
|
||||
$pcat->setNew( false );
|
||||
$pcat->setCategoryUid( $catUID );
|
||||
$pcat->setCategoryName( $catName );
|
||||
$pcat->save();
|
||||
$oProcessCategory = array_change_key_case($this->getCategory( $cat_uid ), CASE_LOWER);
|
||||
//Return
|
||||
return $oProcessCategory;
|
||||
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete Process Category
|
||||
*
|
||||
* @param string $cat_uid Category id
|
||||
*
|
||||
* return array
|
||||
*/
|
||||
public function deleteCategory($cat_uid)
|
||||
{
|
||||
try {
|
||||
require_once 'classes/model/ProcessCategory.php';
|
||||
$criteria = $this->getAProcessCategoryCriteria($cat_uid);
|
||||
$rsCriteria = \ProcessCategoryPeer::doSelectRS($criteria);
|
||||
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
$rsCriteria->next();
|
||||
$row = $rsCriteria->getRow();
|
||||
if ($row) {
|
||||
$cat = new \ProcessCategory();
|
||||
$cat->setCategoryUid( $cat_uid );
|
||||
$cat->delete();
|
||||
} else {
|
||||
throw (new \Exception( 'The Category with cat_uid: '.$cat_uid.' doesn\'t exist!'));
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get criteria for Process Category
|
||||
*
|
||||
* return object
|
||||
*/
|
||||
public function getAProcessCategoryCriteria($cat_uid)
|
||||
{
|
||||
try {
|
||||
$criteria = new \Criteria("workflow");
|
||||
$criteria->addSelectColumn(\ProcessCategoryPeer::CATEGORY_UID);
|
||||
$criteria->addSelectColumn(\ProcessCategoryPeer::CATEGORY_PARENT);
|
||||
$criteria->addSelectColumn(\ProcessCategoryPeer::CATEGORY_NAME);
|
||||
$criteria->addSelectColumn(\ProcessCategoryPeer::CATEGORY_ICON);
|
||||
$criteria->add(\ProcessCategoryPeer::CATEGORY_UID, $cat_uid);
|
||||
return $criteria;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the name exists
|
||||
*
|
||||
* @param string $name Name
|
||||
*
|
||||
* return bool Return true if the name exists, false otherwise
|
||||
*/
|
||||
public function existsName($name)
|
||||
{
|
||||
try {
|
||||
$criteria = new \Criteria("workflow");
|
||||
$criteria->add(\ProcessCategoryPeer::CATEGORY_NAME, $name, \Criteria::EQUAL);
|
||||
$rsCriteria = \ProcessCategoryPeer::doSelectRS($criteria);
|
||||
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
$rsCriteria->next();
|
||||
return $rsCriteria->getRow();
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,480 @@
|
||||
<?php
|
||||
namespace ProcessMaker\BusinessModel;
|
||||
|
||||
use \G;
|
||||
use \Cases;
|
||||
use \Criteria;
|
||||
use \ObjectPermissionPeer;
|
||||
|
||||
/**
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*/
|
||||
class ProcessPermissions
|
||||
{
|
||||
/**
|
||||
* Get list for Process Permissions
|
||||
*
|
||||
* @var string $pro_uid. Uid for Process
|
||||
* @var string $op_uid. Uid for Process Permission
|
||||
*
|
||||
* @access public
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getProcessPermissions($pro_uid, $op_uid = '')
|
||||
{
|
||||
$pro_uid = $this->validateProUid($pro_uid);
|
||||
if ($op_uid != '') {
|
||||
$op_uid = $this->validateOpUid($op_uid);
|
||||
}
|
||||
|
||||
G::LoadClass('case');
|
||||
Cases::verifyTable();
|
||||
$aObjectsPermissions = array();
|
||||
$oCriteria = new \Criteria('workflow');
|
||||
$oCriteria->add(ObjectPermissionPeer::PRO_UID, $pro_uid);
|
||||
if ($op_uid != '') {
|
||||
$oCriteria->add(ObjectPermissionPeer::OP_UID, $op_uid);
|
||||
}
|
||||
$oDataset = ObjectPermissionPeer::doSelectRS($oCriteria);
|
||||
$oDataset->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
$oDataset->next();
|
||||
while ($aRow = $oDataset->getRow()) {
|
||||
//Obtain task target
|
||||
if (($aRow['TAS_UID'] != '') && ($aRow['TAS_UID'] != '0')) {
|
||||
try {
|
||||
$oTask = new \Task();
|
||||
$aFields = $oTask->load($aRow['TAS_UID']);
|
||||
$sTaskTarget = $aFields['TAS_TITLE'];
|
||||
} catch (\Exception $oError) {
|
||||
$sTaskTarget = 'All Tasks';
|
||||
}
|
||||
} else {
|
||||
$sTaskTarget = G::LoadTranslation('ID_ANY_TASK');
|
||||
}
|
||||
//Obtain user or group
|
||||
if ($aRow['OP_USER_RELATION'] == 1) {
|
||||
$oUser = new \Users();
|
||||
$aFields = $oUser->load($aRow['USR_UID']);
|
||||
$sUserGroup = $aFields['USR_FIRSTNAME'] . ' ' . $aFields['USR_LASTNAME'] . ' (' . $aFields['USR_USERNAME'] . ')';
|
||||
} else {
|
||||
$oGroup = new \Groupwf();
|
||||
if ($aRow['USR_UID'] != '') {
|
||||
try {
|
||||
$aFields = $oGroup->load($aRow['USR_UID']);
|
||||
$sUserGroup = $aFields['GRP_TITLE'];
|
||||
} catch (\Exception $oError) {
|
||||
$sUserGroup = '(GROUP DELETED)';
|
||||
}
|
||||
} else {
|
||||
$sUserGroup = G::LoadTranslation('ID_ANY');
|
||||
}
|
||||
}
|
||||
//Obtain task source
|
||||
if (($aRow['OP_TASK_SOURCE'] != '') && ($aRow['OP_TASK_SOURCE'] != '0')) {
|
||||
try {
|
||||
$oTask = new \Task();
|
||||
$aFields = $oTask->load($aRow['OP_TASK_SOURCE']);
|
||||
$sTaskSource = $aFields['TAS_TITLE'];
|
||||
} catch (\Exception $oError) {
|
||||
$sTaskSource = 'All Tasks';
|
||||
}
|
||||
} else {
|
||||
$sTaskSource = G::LoadTranslation('ID_ANY_TASK');
|
||||
}
|
||||
//Obtain object and type
|
||||
switch ($aRow['OP_OBJ_TYPE']) {
|
||||
case 'ALL':
|
||||
$sObjectType = G::LoadTranslation('ID_ALL');
|
||||
$sObject = G::LoadTranslation('ID_ALL');
|
||||
break;
|
||||
case 'ANY': //For backward compatibility (some process with ANY instead of ALL
|
||||
$sObjectType = G::LoadTranslation('ID_ALL');
|
||||
$sObject = G::LoadTranslation('ID_ALL');
|
||||
break;
|
||||
/* case 'ANY_DYNAFORM':
|
||||
$sObjectType = G::LoadTranslation('ID_ANY_DYNAFORM');
|
||||
$sObject = G::LoadTranslation('ID_ALL');
|
||||
break;
|
||||
case 'ANY_INPUT':
|
||||
$sObjectType = G::LoadTranslation('ID_ANY_INPUT');
|
||||
$sObject = G::LoadTranslation('ID_ALL');
|
||||
break;
|
||||
case 'ANY_OUTPUT':
|
||||
$sObjectType = G::LoadTranslation('ID_ANY_OUTPUT');
|
||||
$sObject = G::LoadTranslation('ID_ALL');
|
||||
break; */
|
||||
case 'DYNAFORM':
|
||||
$sObjectType = G::LoadTranslation('ID_DYNAFORM');
|
||||
if (($aRow['OP_OBJ_UID'] != '') && ($aRow['OP_OBJ_UID'] != '0')) {
|
||||
$oDynaform = new \Dynaform();
|
||||
$aFields = $oDynaform->load($aRow['OP_OBJ_UID']);
|
||||
$sObject = $aFields['DYN_TITLE'];
|
||||
} else {
|
||||
$sObject = G::LoadTranslation('ID_ALL');
|
||||
}
|
||||
break;
|
||||
case 'INPUT':
|
||||
$sObjectType = G::LoadTranslation('ID_INPUT_DOCUMENT');
|
||||
if (($aRow['OP_OBJ_UID'] != '') && ($aRow['OP_OBJ_UID'] != '0')) {
|
||||
$oInputDocument = new \InputDocument();
|
||||
$aFields = $oInputDocument->load($aRow['OP_OBJ_UID']);
|
||||
$sObject = $aFields['INP_DOC_TITLE'];
|
||||
} else {
|
||||
$sObject = G::LoadTranslation('ID_ALL');
|
||||
}
|
||||
break;
|
||||
case 'OUTPUT':
|
||||
$sObjectType = G::LoadTranslation('ID_OUTPUT_DOCUMENT');
|
||||
if (($aRow['OP_OBJ_UID'] != '') && ($aRow['OP_OBJ_UID'] != '0')) {
|
||||
$oOutputDocument = new \OutputDocument();
|
||||
$aFields = $oOutputDocument->load($aRow['OP_OBJ_UID']);
|
||||
$sObject = $aFields['OUT_DOC_TITLE'];
|
||||
} else {
|
||||
$sObject = G::LoadTranslation('ID_ALL');
|
||||
}
|
||||
break;
|
||||
case 'CASES_NOTES':
|
||||
$sObjectType = G::LoadTranslation('ID_CASES_NOTES');
|
||||
$sObject = 'N/A';
|
||||
break;
|
||||
case 'MSGS_HISTORY':
|
||||
$sObjectType = G::LoadTranslation('MSGS_HISTORY');
|
||||
$sObject = G::LoadTranslation('ID_ALL');
|
||||
break;
|
||||
default:
|
||||
$sObjectType = G::LoadTranslation('ID_ALL');
|
||||
$sObject = G::LoadTranslation('ID_ALL');
|
||||
break;
|
||||
}
|
||||
//Participated
|
||||
if ($aRow['OP_PARTICIPATE'] == 0) {
|
||||
$sParticipated = G::LoadTranslation('ID_NO');
|
||||
} else {
|
||||
$sParticipated = G::LoadTranslation('ID_YES');
|
||||
}
|
||||
//Obtain action (permission)
|
||||
$sAction = G::LoadTranslation('ID_' . $aRow['OP_ACTION']);
|
||||
//Add to array
|
||||
$arrayTemp = array();
|
||||
$arrayTemp = array_merge($aRow, array(
|
||||
'OP_UID' => $aRow['OP_UID'],
|
||||
'TASK_TARGET' => $sTaskTarget,
|
||||
'GROUP_USER' => $sUserGroup,
|
||||
'TASK_SOURCE' => $sTaskSource,
|
||||
'OBJECT_TYPE' => $sObjectType,
|
||||
'OBJECT' => $sObject,
|
||||
'PARTICIPATED' => $sParticipated,
|
||||
'ACTION' => $sAction,
|
||||
'OP_CASE_STATUS' => $aRow['OP_CASE_STATUS'])
|
||||
);
|
||||
$aObjectsPermissions[] = array_change_key_case($arrayTemp, CASE_LOWER);
|
||||
$oDataset->next();
|
||||
}
|
||||
|
||||
if ($op_uid != '' && empty($aObjectsPermissions)) {
|
||||
throw (new \Exception( 'This row does not exist!!' ));
|
||||
} elseif ($op_uid != '' && !empty($aObjectsPermissions)) {
|
||||
$aObjectsPermissions = array_change_key_case($aObjectsPermissions, CASE_LOWER);
|
||||
return current($aObjectsPermissions);
|
||||
}
|
||||
$aObjectsPermissions = array_change_key_case($aObjectsPermissions, CASE_LOWER);
|
||||
return $aObjectsPermissions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save Process Permission
|
||||
*
|
||||
* @var array $data. Data for Process Permission
|
||||
* @var string $op_uid. Uid for Process Permission
|
||||
*
|
||||
* @access public
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
||||
public function saveProcessPermission($data, $op_uid = '')
|
||||
{
|
||||
try {
|
||||
$data = array_change_key_case($data, CASE_UPPER);
|
||||
|
||||
$this->validateProUid($data['PRO_UID']);
|
||||
if ($op_uid != '') {
|
||||
$op_uid = $this->validateOpUid($op_uid);
|
||||
}
|
||||
if ($data['OP_USER_RELATION'] == "1") {
|
||||
$this->validateUsrUid($data['USR_UID']);
|
||||
} else {
|
||||
$this->validateGrpUid($data['USR_UID']);
|
||||
}
|
||||
if (isset($data['TAS_UID']) && ($data['TAS_UID'] != '')) {
|
||||
$this->validateTasUid($data['TAS_UID']);
|
||||
} else {
|
||||
$data['TAS_UID'] = '';
|
||||
}
|
||||
if (isset($data['OP_TASK_SOURCE']) && ($data['OP_TASK_SOURCE'] != '')) {
|
||||
$this->validateTasUid($data['OP_TASK_SOURCE']);
|
||||
} else {
|
||||
$data['OP_TASK_SOURCE'] = '';
|
||||
}
|
||||
|
||||
$sObjectUID = '';
|
||||
switch ($data['OP_OBJ_TYPE']) {
|
||||
case 'ANY':
|
||||
//case 'ANY_DYNAFORM':CASES_NOTES
|
||||
//case 'ANY_INPUT':
|
||||
//case 'ANY_OUTPUT':
|
||||
$sObjectUID = '';
|
||||
break;
|
||||
case 'DYNAFORM':
|
||||
if ($data['DYNAFORMS'] != '') {
|
||||
$this->validateDynUid($data['DYNAFORMS']);
|
||||
}
|
||||
$sObjectUID = $data['DYNAFORMS'];
|
||||
break;
|
||||
case 'INPUT':
|
||||
if ($data['INPUTS'] != '') {
|
||||
$this->validateInpUid($data['INPUTS']);
|
||||
}
|
||||
$sObjectUID = $data['INPUTS'];
|
||||
break;
|
||||
case 'OUTPUT':
|
||||
if ($data['OUTPUTS'] != '') {
|
||||
$this->validateOutUid($data['OUTPUTS']);
|
||||
}
|
||||
$sObjectUID = $data['OUTPUTS'];
|
||||
break;
|
||||
}
|
||||
$oOP = new \ObjectPermission();
|
||||
$permissionUid = ($op_uid != '') ? $op_uid : G::generateUniqueID();
|
||||
$data['OP_UID'] = $permissionUid;
|
||||
$data['OP_OBJ_UID'] = $sObjectUID;
|
||||
|
||||
if ($op_uid == '') {
|
||||
$oOP->fromArray( $data, \BasePeer::TYPE_FIELDNAME );
|
||||
$oOP->save();
|
||||
$daraRes = $oOP->load($permissionUid);
|
||||
$daraRes = array_change_key_case($daraRes, CASE_LOWER);
|
||||
return $daraRes;
|
||||
} else {
|
||||
$data['TAS_UID'] = $data['TAS_UID'] != '' ? $data['TAS_UID'] : '0';
|
||||
$data['OP_TASK_SOURCE'] = $data['OP_TASK_SOURCE'] != '' ? $data['OP_TASK_SOURCE'] : '0';
|
||||
$data['OP_PARTICIPATE'] = $data['OP_PARTICIPATE'] != '' ? $data['OP_PARTICIPATE'] : 0;
|
||||
$data['OP_OBJ_TYPE'] = $data['OP_OBJ_TYPE'] != '' ? $data['OP_OBJ_TYPE'] : '0';
|
||||
$data['OP_OBJ_UID'] = $data['OP_OBJ_UID'] != '' ? $data['OP_OBJ_UID'] : '0';
|
||||
$data['OP_ACTION'] = $data['OP_ACTION'] != '' ? $data['OP_ACTION'] : '0';
|
||||
$data['OP_CASE_STATUS'] = $data['OP_CASE_STATUS'] != '' ? $data['OP_CASE_STATUS'] : '0';
|
||||
$oOP->update($data);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete Process Permission
|
||||
*
|
||||
* @var string $op_uid. Uid for Process Permission
|
||||
*
|
||||
* @access public
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteProcessPermission($op_uid, $pro_uid)
|
||||
{
|
||||
try {
|
||||
$pro_uid = $this->validateProUid($pro_uid);
|
||||
$op_uid = $this->validateOpUid($op_uid);
|
||||
|
||||
$oOP = new \ObjectPermission();
|
||||
$oOP = ObjectPermissionPeer::retrieveByPK( $op_uid );
|
||||
$oOP->delete();
|
||||
} catch (Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate Process Uid
|
||||
* @var string $pro_uid. Uid for process
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function validateProUid ($pro_uid)
|
||||
{
|
||||
$pro_uid = trim($pro_uid);
|
||||
if ($pro_uid == '') {
|
||||
throw (new \Exception("The project with prj_uid: '' does not exist."));
|
||||
}
|
||||
$oProcess = new \Process();
|
||||
if (!($oProcess->processExists($pro_uid))) {
|
||||
throw (new \Exception("The project with prj_uid: '$pro_uid' does not exist."));
|
||||
}
|
||||
return $pro_uid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate Process Permission Uid
|
||||
* @var string $op_uid. Uid for process permission
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function validateOpUid ($op_uid)
|
||||
{
|
||||
$op_uid = trim($op_uid);
|
||||
if ($op_uid == '') {
|
||||
throw (new \Exception("The process permission with op_uid: '' does not exist."));
|
||||
}
|
||||
$oObjectPermission = new \ObjectPermission();
|
||||
if (!($oObjectPermission->Exists($op_uid))) {
|
||||
throw (new \Exception("The process permission with op_uid: '$op_uid' does not exist."));
|
||||
}
|
||||
return $op_uid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate User Uid
|
||||
* @var string $usr_uid. Uid for user
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function validateUsrUid($usr_uid)
|
||||
{
|
||||
$usr_uid = trim($usr_uid);
|
||||
if ($usr_uid == '') {
|
||||
throw (new \Exception("The user with usr_uid: '' does not exist."));
|
||||
}
|
||||
$oUsers = new \Users();
|
||||
if (!($oUsers->userExists($usr_uid))) {
|
||||
throw (new \Exception("The user with usr_uid: '$usr_uid' does not exist."));
|
||||
}
|
||||
return $usr_uid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate Group Uid
|
||||
* @var string $grp_uid. Uid for group
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function validateGrpUid($grp_uid)
|
||||
{
|
||||
$grp_uid = trim($grp_uid);
|
||||
if ($grp_uid == '') {
|
||||
throw (new \Exception("The group with usr_uid: '' does not exist."));
|
||||
}
|
||||
$oGroup = new \Groupwf();
|
||||
if (!($oGroup->GroupwfExists($grp_uid))) {
|
||||
throw (new \Exception("The group with usr_uid: '$grp_uid' does not exist."));
|
||||
}
|
||||
return $grp_uid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate Task Uid
|
||||
* @var string $tas_uid. Uid for task
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function validateTasUid($tas_uid)
|
||||
{
|
||||
$tas_uid = trim($tas_uid);
|
||||
if ($tas_uid == '') {
|
||||
throw (new \Exception("The task with tas_uid: '' does not exist."));
|
||||
}
|
||||
$oTask = new \Task();
|
||||
if (!($oTask->taskExists($tas_uid))) {
|
||||
throw (new \Exception("The task with tas_uid: '$tas_uid' does not exist."));
|
||||
}
|
||||
return $tas_uid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate Dynaform Uid
|
||||
* @var string $dyn_uid. Uid for dynaform
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function validateDynUid($dyn_uid)
|
||||
{
|
||||
$dyn_uid = trim($dyn_uid);
|
||||
if ($dyn_uid == '') {
|
||||
throw (new \Exception("The dynaform with dynaforms: '' does not exist."));
|
||||
}
|
||||
$oDynaform = new \Dynaform();
|
||||
if (!($oDynaform->dynaformExists($dyn_uid))) {
|
||||
throw (new \Exception("The dynaform with dynaforms: '$dyn_uid' does not exist."));
|
||||
}
|
||||
return $dyn_uid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate Input Uid
|
||||
* @var string $inp_uid. Uid for dynaform
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function validateInpUid($inp_uid)
|
||||
{
|
||||
$inp_uid = trim($inp_uid);
|
||||
if ($inp_uid == '') {
|
||||
throw (new \Exception("The input with inputs: '' does not exist."));
|
||||
}
|
||||
$oInputDocument = new \InputDocument();
|
||||
if (!($oInputDocument->InputExists($inp_uid))) {
|
||||
throw (new \Exception("The input with inputs: '$inp_uid' does not exist."));
|
||||
}
|
||||
return $inp_uid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate Output Uid
|
||||
* @var string $out_uid. Uid for output
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function validateOutUid($out_uid)
|
||||
{
|
||||
$out_uid = trim($out_uid);
|
||||
if ($out_uid == '') {
|
||||
throw (new \Exception("The output with outputs: '' does not exist."));
|
||||
}
|
||||
$oOutputDocument = new \OutputDocument();
|
||||
if (!($oOutputDocument->OutputExists($out_uid))) {
|
||||
throw (new \Exception("The output with outputs: '$out_uid' does not exist."));
|
||||
}
|
||||
return $out_uid;
|
||||
}
|
||||
}
|
||||
|
||||
1033
workflow/engine/src/ProcessMaker/BusinessModel/ProcessSupervisor.php
Normal file
1033
workflow/engine/src/ProcessMaker/BusinessModel/ProcessSupervisor.php
Normal file
File diff suppressed because it is too large
Load Diff
392
workflow/engine/src/ProcessMaker/BusinessModel/ProjectUser.php
Normal file
392
workflow/engine/src/ProcessMaker/BusinessModel/ProjectUser.php
Normal file
@@ -0,0 +1,392 @@
|
||||
<?php
|
||||
namespace ProcessMaker\BusinessModel;
|
||||
|
||||
use \G;
|
||||
|
||||
class ProjectUser
|
||||
{
|
||||
/**
|
||||
* Return the users to assigned to a process
|
||||
*
|
||||
* @param string $sProcessUID {@min 32} {@max 32}
|
||||
*
|
||||
* return array
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function getProjectUsers($sProcessUID)
|
||||
{
|
||||
try {
|
||||
$oProcess = \ProcessPeer::retrieveByPK( $sProcessUID );
|
||||
if (is_null($oProcess)) {
|
||||
throw (new \Exception( 'This id for `prj_uid`: '. $sProcessUID .' does not correspond to a registered process'));
|
||||
}
|
||||
$aUsers = array();
|
||||
$sDelimiter = \DBAdapter::getStringDelimiter();
|
||||
$oCriteria = new \Criteria('workflow');
|
||||
$oCriteria->setDistinct();
|
||||
$oCriteria->addSelectColumn(\UsersPeer::USR_FIRSTNAME);
|
||||
$oCriteria->addSelectColumn(\UsersPeer::USR_LASTNAME);
|
||||
$oCriteria->addSelectColumn(\UsersPeer::USR_USERNAME);
|
||||
$oCriteria->addSelectColumn(\UsersPeer::USR_EMAIL);
|
||||
$oCriteria->addSelectColumn(\TaskUserPeer::TAS_UID);
|
||||
$oCriteria->addSelectColumn(\TaskUserPeer::USR_UID);
|
||||
$oCriteria->addSelectColumn(\TaskUserPeer::TU_TYPE);
|
||||
$oCriteria->addSelectColumn(\TaskUserPeer::TU_RELATION);
|
||||
$oCriteria->addJoin(\TaskUserPeer::USR_UID, \UsersPeer::USR_UID, \Criteria::LEFT_JOIN);
|
||||
$oCriteria->addJoin(\TaskUserPeer::TAS_UID, \TaskPeer::TAS_UID, \Criteria::LEFT_JOIN);
|
||||
$oCriteria->add(\TaskPeer::PRO_UID, $sProcessUID);
|
||||
$oCriteria->add(\TaskUserPeer::TU_TYPE, 1);
|
||||
$oCriteria->addGroupByColumn(\TaskUserPeer::USR_UID);
|
||||
$oDataset = \TaskUserPeer::doSelectRS($oCriteria);
|
||||
$oDataset->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
$oDataset->next();
|
||||
while ($aRow = $oDataset->getRow()) {
|
||||
if ($aRow['TU_RELATION'] == 1) {
|
||||
$aUsers[] = array('usr_uid' => $aRow['USR_UID'],
|
||||
'usr_username' => $aRow['USR_USERNAME'],
|
||||
'usr_firstname' => $aRow['USR_FIRSTNAME'],
|
||||
'usr_lastname' => $aRow['USR_LASTNAME']);
|
||||
} else {
|
||||
$criteria = new \Criteria("workflow");
|
||||
$criteria->addSelectColumn(\UsersPeer::USR_UID);
|
||||
$criteria->addJoin(\GroupUserPeer::USR_UID, \UsersPeer::USR_UID, \Criteria::INNER_JOIN);
|
||||
$criteria->add(\GroupUserPeer::GRP_UID, $aRow['USR_UID'], \Criteria::EQUAL);
|
||||
$criteria->add(\UsersPeer::USR_STATUS, "CLOSED", \Criteria::NOT_EQUAL);
|
||||
$rsCriteria = \GroupUserPeer::doSelectRS($criteria);
|
||||
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
while ($rsCriteria->next()) {
|
||||
$row = $rsCriteria->getRow();
|
||||
$oCriteriaU = new \Criteria('workflow');
|
||||
$oCriteriaU->setDistinct();
|
||||
$oCriteriaU->addSelectColumn(\UsersPeer::USR_FIRSTNAME);
|
||||
$oCriteriaU->addSelectColumn(\UsersPeer::USR_LASTNAME);
|
||||
$oCriteriaU->addSelectColumn(\UsersPeer::USR_USERNAME);
|
||||
$oCriteriaU->addSelectColumn(\UsersPeer::USR_EMAIL);
|
||||
$oCriteriaU->add(\UsersPeer::USR_UID, $row['USR_UID']);
|
||||
$oDatasetU = \UsersPeer::doSelectRS($oCriteriaU);
|
||||
$oDatasetU->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
while ($oDatasetU->next()) {
|
||||
$aRowU = $oDatasetU->getRow();
|
||||
$aUsers[] = array('usr_uid' => $row['USR_UID'],
|
||||
'usr_username' => $aRowU['USR_USERNAME'],
|
||||
'usr_firstname' => $aRowU['USR_FIRSTNAME'],
|
||||
'usr_lastname' => $aRowU['USR_LASTNAME']);
|
||||
}
|
||||
}
|
||||
}
|
||||
$oDataset->next();
|
||||
}
|
||||
$aUsersGroups = array();
|
||||
$exclude = array("");
|
||||
for ($i = 0; $i<=count($aUsers)-1; $i++) {
|
||||
if (!in_array(trim($aUsers[$i]["usr_uid"]) ,$exclude)) {
|
||||
$aUsersGroups[] = $aUsers[$i];
|
||||
$exclude[] = trim($aUsers[$i]["usr_uid"]);
|
||||
}
|
||||
}
|
||||
return $aUsersGroups;
|
||||
} catch (Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return starting task
|
||||
*
|
||||
* @param string $sProcessUID {@min 32} {@max 32}
|
||||
*
|
||||
* return array
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function getProjectStartingTasks($sProcessUID)
|
||||
{
|
||||
try {
|
||||
$oProcess = \ProcessPeer::retrieveByPK( $sProcessUID );
|
||||
if (is_null($oProcess)) {
|
||||
throw (new \Exception( 'This id for `prj_uid`: '. $sProcessUID .' does not correspond to a registered process'));
|
||||
}
|
||||
$aUsers = array();
|
||||
$sDelimiter = \DBAdapter::getStringDelimiter();
|
||||
$oCriteria = new \Criteria('workflow');
|
||||
$oCriteria->setDistinct();
|
||||
$oCriteria->addSelectColumn(\UsersPeer::USR_UID);
|
||||
$oCriteria->addSelectColumn(\UsersPeer::USR_FIRSTNAME);
|
||||
$oCriteria->addSelectColumn(\UsersPeer::USR_LASTNAME);
|
||||
$oCriteria->addSelectColumn(\UsersPeer::USR_USERNAME);
|
||||
$oCriteria->addJoin(\TaskUserPeer::USR_UID, \UsersPeer::USR_UID, \Criteria::LEFT_JOIN);
|
||||
$oCriteria->addJoin(\TaskUserPeer::TAS_UID, \TaskPeer::TAS_UID, \Criteria::LEFT_JOIN);
|
||||
$oCriteria->add(\TaskPeer::PRO_UID, $sProcessUID);
|
||||
$oCriteria->add(\TaskUserPeer::TU_TYPE, 1);
|
||||
$oCriteria->add(\TaskUserPeer::TU_RELATION, 1);
|
||||
$oCriteria->addGroupByColumn(\TaskUserPeer::USR_UID);
|
||||
$oDataset = \TaskUserPeer::doSelectRS($oCriteria);
|
||||
$oDataset->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
$oDataset->next();
|
||||
while ($aRow = $oDataset->getRow()) {
|
||||
\G::LoadClass( 'case' );
|
||||
$oCase = new \Cases();
|
||||
$startTasks = $oCase->getStartCases( $aRow['USR_UID'] );
|
||||
foreach ($startTasks as $task) {
|
||||
if ((isset( $task['pro_uid'] )) && ($task['pro_uid'] == $sProcessUID) ) {
|
||||
$taskValue = explode( '(', $task['value'] );
|
||||
$tasksLastIndex = count( $taskValue ) - 1;
|
||||
$taskValue = explode( ')', $taskValue[$tasksLastIndex] );
|
||||
$aUsers[] = array('act_name' => $taskValue[0],
|
||||
'act_uid' => $task['uid']);
|
||||
}
|
||||
}
|
||||
$oDataset->next();
|
||||
}
|
||||
$new = array();
|
||||
$exclude = array("");
|
||||
for ($i = 0; $i<=count($aUsers)-1; $i++) {
|
||||
if (!in_array(trim($aUsers[$i]["act_uid"]) ,$exclude)) {
|
||||
$new[] = $aUsers[$i];
|
||||
$exclude[] = trim($aUsers[$i]["act_uid"]);
|
||||
}
|
||||
}
|
||||
return $new;
|
||||
} catch (Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return starting task by users
|
||||
*
|
||||
* @param string $sProcessUID {@min 32} {@max 32}
|
||||
* @param string $sUserUID {@min 32} {@max 32}
|
||||
*
|
||||
* return array
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function getProjectStartingTaskUsers($sProcessUID, $sUserUID)
|
||||
{
|
||||
try {
|
||||
$oProcess = \ProcessPeer::retrieveByPK( $sProcessUID );
|
||||
if (is_null($oProcess)) {
|
||||
throw (new \Exception( 'This id for `prj_uid`: '. $sProcessUID .' does not correspond to a registered process'));
|
||||
}
|
||||
$oUser = \UsersPeer::retrieveByPK($sUserUID);
|
||||
if (is_null($oUser)) {
|
||||
throw (new \Exception( 'This id for `usr_uid`: '. $sUserUID .' does not correspond to a registered user'));
|
||||
}
|
||||
$aUsers = array();
|
||||
\G::LoadClass( 'case' );
|
||||
$oCase = new \Cases();
|
||||
$startTasks = $oCase->getStartCases($sUserUID);
|
||||
if (sizeof($startTasks) > 1) {
|
||||
foreach ($startTasks as $task) {
|
||||
if ((isset( $task['pro_uid'] )) && ($task['pro_uid'] == $sProcessUID)) {
|
||||
$taskValue = explode( '(', $task['value'] );
|
||||
$tasksLastIndex = count( $taskValue ) - 1;
|
||||
$taskValue = explode( ')', $taskValue[$tasksLastIndex] );
|
||||
$aUsers[] = array('act_uid' => $task['uid'],
|
||||
'act_name' => $taskValue[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (sizeof($aUsers) < 1) {
|
||||
throw (new \Exception( 'This user `usr_uid`: '. $sUserUID .' does not have initial activities assigned in this project.'));
|
||||
}
|
||||
return $aUsers;
|
||||
} catch (Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the user that can start a task
|
||||
*
|
||||
* @param string $sProcessUID {@min 32} {@max 32}
|
||||
* @param string $sActivityUID {@min 32} {@max 32}
|
||||
* @param array $oData
|
||||
*
|
||||
* return array
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function postProjectWsUserCanStartTask($sProcessUID, $sActivityUID, $oData)
|
||||
{
|
||||
try {
|
||||
$oProcess = \ProcessPeer::retrieveByPK( $sProcessUID );
|
||||
if (is_null($oProcess)) {
|
||||
throw (new \Exception( 'This id for `prj_uid`: '. $sProcessUID .' does not correspond to a registered process'));
|
||||
}
|
||||
/**
|
||||
* process_webEntryValidate
|
||||
* validates if the username and password are valid data and if the user assigned
|
||||
* to the webentry has the rights and persmissions required
|
||||
*/
|
||||
$sTASKS = $sActivityUID;
|
||||
$sWS_USER = trim( $oData['username'] );
|
||||
$sWS_PASS = trim( $oData['password'] );
|
||||
if (\G::is_https()) {
|
||||
$http = 'https://';
|
||||
} else {
|
||||
$http = 'http://';
|
||||
}
|
||||
$endpoint = $http . $_SERVER['HTTP_HOST'] . '/sys' . SYS_SYS . '/' . SYS_LANG . '/' . SYS_SKIN . '/services/wsdl2';
|
||||
@$client = new \SoapClient( $endpoint );
|
||||
$user = $sWS_USER;
|
||||
$pass = $sWS_PASS;
|
||||
$params = array ('userid' => $user,'password' => $pass);
|
||||
$result = $client->__SoapCall('login', array ($params));
|
||||
$fields['status_code'] = $result->status_code;
|
||||
$fields['message'] = 'ProcessMaker WebService version: ' . $result->version . "\n" . $result->message;
|
||||
$fields['version'] = $result->version;
|
||||
$fields['time_stamp'] = $result->timestamp;
|
||||
$messageCode = 1;
|
||||
\G::LoadClass( 'Task' );
|
||||
\G::LoadClass( 'User' );
|
||||
\G::LoadClass( 'TaskUser' );
|
||||
\G::LoadClass( 'Groupwf' );
|
||||
/**
|
||||
* note added by gustavo cruz gustavo-at-colosa-dot-com
|
||||
* This is a little check to see if the GroupUser class has been declared or not.
|
||||
* Seems that the problem its present in a windows installation of PM however.
|
||||
* It's seems that could be replicated in a Linux server easily.
|
||||
* I recomend that in some way check already if a imported class is declared
|
||||
* somewhere else or maybe delegate the task to the G Class LoadClass method.
|
||||
*/
|
||||
if (! class_exists( 'GroupUser' )) {
|
||||
\G::LoadClass( 'GroupUser' );
|
||||
}
|
||||
// if the user has been authenticated, then check if has the rights or
|
||||
// permissions to create the webentry
|
||||
if ($result->status_code == 0) {
|
||||
$oCriteria = new \Criteria( 'workflow' );
|
||||
$oCriteria->addSelectColumn( \UsersPeer::USR_UID );
|
||||
$oCriteria->addSelectColumn( \TaskUserPeer::USR_UID );
|
||||
$oCriteria->addSelectColumn( \TaskUserPeer::TAS_UID );
|
||||
$oCriteria->addSelectColumn( \UsersPeer::USR_USERNAME );
|
||||
$oCriteria->addSelectColumn( \UsersPeer::USR_FIRSTNAME );
|
||||
$oCriteria->addSelectColumn( \UsersPeer::USR_LASTNAME );
|
||||
$oCriteria->addSelectColumn( \TaskPeer::PRO_UID );
|
||||
$oCriteria->addJoin( \TaskUserPeer::USR_UID, \UsersPeer::USR_UID, \Criteria::LEFT_JOIN );
|
||||
$oCriteria->addJoin( \TaskUserPeer::TAS_UID, \TaskPeer::TAS_UID, \Criteria::LEFT_JOIN );
|
||||
if ($sTASKS) {
|
||||
$oCriteria->add( \TaskUserPeer::TAS_UID, $sTASKS );
|
||||
}
|
||||
$oCriteria->add( \UsersPeer::USR_USERNAME, $sWS_USER );
|
||||
$oCriteria->add( \TaskPeer::PRO_UID, $sProcessUID );
|
||||
$userIsAssigned = \TaskUserPeer::doCount( $oCriteria );
|
||||
// if the user is not assigned directly, maybe a have the task a group with the user
|
||||
if ($userIsAssigned < 1) {
|
||||
$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->addJoin( \UsersPeer::USR_UID, \GroupUserPeer::USR_UID, \Criteria::LEFT_JOIN );
|
||||
$oCriteria->addJoin( \GroupUserPeer::GRP_UID, \TaskUserPeer::USR_UID, \Criteria::LEFT_JOIN );
|
||||
$oCriteria->addJoin( \TaskUserPeer::TAS_UID, \TaskPeer::TAS_UID, \Criteria::LEFT_JOIN );
|
||||
if ($sTASKS) {
|
||||
$oCriteria->add( \TaskUserPeer::TAS_UID, $sTASKS );
|
||||
}
|
||||
$oCriteria->add( \UsersPeer::USR_USERNAME, $sWS_USER );
|
||||
$oCriteria->add( \TaskPeer::PRO_UID, $sProcessUID );
|
||||
$userIsAssigned = \GroupUserPeer::doCount( $oCriteria );
|
||||
if (! ($userIsAssigned >= 1)) {
|
||||
if ($sTASKS) {
|
||||
throw (new \Exception( "The `usr_uid` `" . $sWS_USER . "` doesn't have the activity `act_uid` `" . $sTASKS . "` assigned"));
|
||||
} else {
|
||||
throw (new \Exception( "The `usr_uid` `" . $sWS_USER . "` doesn't have an activity assigned"));
|
||||
}
|
||||
}
|
||||
}
|
||||
$oDataset = \TaskUserPeer::doSelectRS($oCriteria);
|
||||
$oDataset->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
$oDataset->next();
|
||||
while ($aRow = $oDataset->getRow()) {
|
||||
$messageCode = array('usr_uid' => $aRow['USR_UID'],
|
||||
'usr_username' => $aRow['USR_USERNAME'],
|
||||
'usr_firstname' => $aRow['USR_FIRSTNAME'],
|
||||
'usr_lastname' => $aRow['USR_LASTNAME']);
|
||||
$oDataset->next();
|
||||
}
|
||||
} else {
|
||||
throw (new \Exception( $result->message));
|
||||
}
|
||||
return $messageCode;
|
||||
} catch (Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* User Login
|
||||
*
|
||||
* @param string $username Username
|
||||
* @param string $password Password
|
||||
*
|
||||
* return object Return object $response
|
||||
* $response->status_code, 0 when User has been authenticated, any number otherwise
|
||||
* $response->message, message
|
||||
*/
|
||||
public function userLogin($username, $password)
|
||||
{
|
||||
try {
|
||||
$http = (\G::is_https())? "https://" : "http://";
|
||||
|
||||
$client = new \SoapClient($http . $_SERVER["HTTP_HOST"] . "/sys" . SYS_SYS . "/" . SYS_LANG . "/" . SYS_SKIN . "/services/wsdl2");
|
||||
|
||||
$params = array(
|
||||
"userid" => $username,
|
||||
"password" => "md5:" . md5($password)
|
||||
);
|
||||
|
||||
$response = $client->login($params);
|
||||
|
||||
return $response;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify if the User is assigned to Task
|
||||
*
|
||||
* @param string $userUid Unique id of User
|
||||
* @param string $taskUid Unique id of Task
|
||||
*
|
||||
* return bool Return true if the User is assigned to Task, false otherwise
|
||||
*/
|
||||
public function userIsAssignedToTask($userUid, $taskUid)
|
||||
{
|
||||
try {
|
||||
$criteria = new \Criteria("workflow");
|
||||
|
||||
$criteria->addSelectColumn(\TaskUserPeer::TAS_UID);
|
||||
$criteria->add(\TaskUserPeer::TAS_UID, $taskUid, \Criteria::EQUAL);
|
||||
$criteria->add(\TaskUserPeer::USR_UID, $userUid, \Criteria::EQUAL);
|
||||
|
||||
$rsCriteria = \TaskUserPeer::doSelectRS($criteria);
|
||||
|
||||
//If the User is not assigned directly, maybe a have the Task a Group with the User
|
||||
if (!$rsCriteria->next()) {
|
||||
$criteria = new \Criteria("workflow");
|
||||
|
||||
$criteria->addSelectColumn(\UsersPeer::USR_UID);
|
||||
$criteria->addJoin(\UsersPeer::USR_UID, \GroupUserPeer::USR_UID, \Criteria::LEFT_JOIN);
|
||||
$criteria->addJoin(\GroupUserPeer::GRP_UID, \TaskUserPeer::USR_UID, \Criteria::LEFT_JOIN);
|
||||
$criteria->add(\TaskUserPeer::TAS_UID, $taskUid, \Criteria::EQUAL);
|
||||
$criteria->add(\UsersPeer::USR_UID, $userUid, \Criteria::EQUAL);
|
||||
|
||||
$rsCriteria = \UsersPeer::doSelectRS($criteria);
|
||||
|
||||
if (!$rsCriteria->next()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
928
workflow/engine/src/ProcessMaker/BusinessModel/Step.php
Normal file
928
workflow/engine/src/ProcessMaker/BusinessModel/Step.php
Normal file
@@ -0,0 +1,928 @@
|
||||
<?php
|
||||
namespace ProcessMaker\BusinessModel;
|
||||
|
||||
class Step
|
||||
{
|
||||
private $formatFieldNameInUppercase = true;
|
||||
private $arrayParamException = array(
|
||||
"stepUid" => "STEP_UID",
|
||||
"taskUid" => "TAS_UID",
|
||||
"processUid" => "PRO_UID",
|
||||
"stepTypeObj" => "STEP_TYPE_OBJ",
|
||||
"stepUidObj" => "STEP_UID_OBJ",
|
||||
"stepCondition" => "STEP_CONDITION",
|
||||
"stepPosition" => "STEP_POSITION",
|
||||
"stepMode" => "STEP_MODE"
|
||||
);
|
||||
|
||||
/**
|
||||
* 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->setArrayParamException($this->arrayParamException);
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set exception messages for parameters
|
||||
*
|
||||
* @param array $arrayData Data with the params
|
||||
*
|
||||
* return void
|
||||
*/
|
||||
public function setArrayParamException($arrayData)
|
||||
{
|
||||
try {
|
||||
foreach ($arrayData as $key => $value) {
|
||||
$this->arrayParamException[$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 record in table STEP
|
||||
*
|
||||
* @param string $taskUid Unique id of Task
|
||||
* @param string $type Type of Step (DYNAFORM, INPUT_DOCUMENT, OUTPUT_DOCUMENT)
|
||||
* @param string $objectUid Unique id of Object
|
||||
* @param int $position Position
|
||||
* @param string $stepUidExclude Unique id of Step to exclude
|
||||
*
|
||||
* return bool Return true if exists the record in table STEP, false otherwise
|
||||
*/
|
||||
public function existsRecord($taskUid, $type, $objectUid, $position = 0, $stepUidExclude = "")
|
||||
{
|
||||
try {
|
||||
$criteria = new \Criteria("workflow");
|
||||
|
||||
$criteria->addSelectColumn(\StepPeer::STEP_UID);
|
||||
$criteria->add(\StepPeer::TAS_UID, $taskUid, \Criteria::EQUAL);
|
||||
|
||||
if ($stepUidExclude != "") {
|
||||
$criteria->add(\StepPeer::STEP_UID, $stepUidExclude, \Criteria::NOT_EQUAL);
|
||||
}
|
||||
|
||||
if ($type != "") {
|
||||
$criteria->add(\StepPeer::STEP_TYPE_OBJ, $type, \Criteria::EQUAL);
|
||||
}
|
||||
|
||||
if ($objectUid != "") {
|
||||
$criteria->add(\StepPeer::STEP_UID_OBJ, $objectUid, \Criteria::EQUAL);
|
||||
}
|
||||
|
||||
if ($position > 0) {
|
||||
$criteria->add(\StepPeer::STEP_POSITION, $position, \Criteria::EQUAL);
|
||||
}
|
||||
|
||||
$rsCriteria = \StepPeer::doSelectRS($criteria);
|
||||
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
|
||||
if ($rsCriteria->next()) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify if exists the "Object UID" in the corresponding table
|
||||
*
|
||||
* @param string $type Type of Step (DYNAFORM, INPUT_DOCUMENT, OUTPUT_DOCUMENT)
|
||||
* @param string $objectUid Unique id of Object
|
||||
*
|
||||
* return strin Return empty string if $objectUid exists in the corresponding table, return string with data if $objectUid doesn't exist
|
||||
*/
|
||||
public function existsObjectUid($type, $objectUid)
|
||||
{
|
||||
try {
|
||||
$msg = "";
|
||||
|
||||
switch ($type) {
|
||||
case "DYNAFORM":
|
||||
$dynaform = new \Dynaform();
|
||||
|
||||
if (!$dynaform->dynaformExists($objectUid)) {
|
||||
$msg = str_replace(array("{0}", "{1}"), array($objectUid, "DYNAFORM"), "The UID \"{0}\" does not exist in table {1}");
|
||||
}
|
||||
break;
|
||||
case "INPUT_DOCUMENT":
|
||||
$inputdoc = new \InputDocument();
|
||||
|
||||
if (!$inputdoc->InputExists($objectUid)) {
|
||||
$msg = str_replace(array("{0}", "{1}"), array($objectUid, "INPUT_DOCUMENT"), "The UID \"{0}\" does not exist in table {1}");
|
||||
}
|
||||
break;
|
||||
case "OUTPUT_DOCUMENT":
|
||||
$outputdoc = new \OutputDocument();
|
||||
|
||||
if (!$outputdoc->OutputExists($objectUid)) {
|
||||
$msg = str_replace(array("{0}", "{1}"), array($objectUid, "OUTPUT_DOCUMENT"), "The UID \"{0}\" does not exist in table {1}");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return $msg;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify if Type Object has invalid value
|
||||
*
|
||||
* @param string $stepTypeObj Type Object
|
||||
*
|
||||
* return void Throw exception if Type Object has invalid value
|
||||
*/
|
||||
public function throwExceptionIfHaveInvalidValueInTypeObj($stepTypeObj)
|
||||
{
|
||||
if (!in_array($stepTypeObj, array("DYNAFORM", "INPUT_DOCUMENT", "OUTPUT_DOCUMENT", "EXTERNAL"))) {
|
||||
$field = $this->arrayParamException["stepTypeObj"];
|
||||
throw (new \Exception(str_replace(array("{0}"), array($field), "Invalid value specified for \"{0}\"")));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify if Mode has invalid value
|
||||
*
|
||||
* @param string $stepMode Mode
|
||||
*
|
||||
* return void Throw exception if Mode has invalid value
|
||||
*/
|
||||
public function throwExceptionIfHaveInvalidValueInMode($stepMode)
|
||||
{
|
||||
if (!in_array($stepMode, array("EDIT", "VIEW"))) {
|
||||
$field = $this->arrayParamException["stepMode"];
|
||||
|
||||
throw (new \Exception(str_replace(array("{0}"), array($field), "Invalid value specified for \"{0}\"")));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify if doesn't exist the Step in table STEP
|
||||
*
|
||||
* @param string $stepUid Unique id of Step
|
||||
*
|
||||
* return void Throw exception if doesn't exist the Step in table STEP
|
||||
*/
|
||||
public function throwExceptionIfNotExistsStep($stepUid)
|
||||
{
|
||||
$step = new \Step();
|
||||
|
||||
if (!$step->StepExists($stepUid)) {
|
||||
$field = $this->arrayParamException["stepUid"];
|
||||
|
||||
$msg = str_replace(array("{0}"), array($field), "Invalid value specified for \"{0}\"") . " / ";
|
||||
$msg = $msg . str_replace(array("{0}", "{1}"), array($stepUid, "STEP"), "The UID \"{0}\" does not exist in table {1}");
|
||||
|
||||
throw (new \Exception($msg));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify if doesn't exist the Task in table TASK
|
||||
*
|
||||
* @param string $taskUid Unique id of Task
|
||||
*
|
||||
* return void Throw exception if doesn't exist the Task in table TASK
|
||||
*/
|
||||
public function throwExceptionIfNotExistsTask($taskUid)
|
||||
{
|
||||
$task = new \Task();
|
||||
|
||||
if (!$task->taskExists($taskUid)) {
|
||||
$field = $this->arrayParamException["taskUid"];
|
||||
|
||||
$msg = str_replace(array("{0}"), array($field), "Invalid value specified for \"{0}\"") . " / ";
|
||||
$msg = $msg . str_replace(array("{0}", "{1}"), array($taskUid, "TASK"), "The UID \"{0}\" does not exist in table {1}");
|
||||
|
||||
throw (new \Exception($msg));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify if doesn't exist the Process in table PROCESS
|
||||
*
|
||||
* @param string $processUid Unique id of Process
|
||||
*
|
||||
* return void Throw exception if doesn't exist the Process in table PROCESS
|
||||
*/
|
||||
public function throwExceptionIfNotExistsProcess($processUid)
|
||||
{
|
||||
$process = new \Process();
|
||||
|
||||
if (!$process->exists($processUid)) {
|
||||
$field = $this->arrayParamException["processUid"];
|
||||
|
||||
$msg = str_replace(array("{0}"), array($field), "Invalid value specified for \"{0}\"") . " / ";
|
||||
$msg = $msg . str_replace(array("{0}", "{1}"), array($processUid, "PROCESS"), "The UID \"{0}\" does not exist in table {1}");
|
||||
|
||||
throw (new \Exception($msg));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Step for a Task
|
||||
*
|
||||
* @param string $taskUid Unique id of Task
|
||||
* @param string $processUid Unique id of Process
|
||||
* @param array $arrayData Data
|
||||
*
|
||||
* return array Return data of the new Step created
|
||||
*/
|
||||
public function create($taskUid, $processUid, $arrayData)
|
||||
{
|
||||
try {
|
||||
$arrayData = array_change_key_case($arrayData, CASE_UPPER);
|
||||
|
||||
unset($arrayData["STEP_UID"]);
|
||||
|
||||
//Verify data
|
||||
$this->throwExceptionIfNotExistsTask($taskUid);
|
||||
|
||||
$this->throwExceptionIfNotExistsProcess($processUid);
|
||||
|
||||
if (!isset($arrayData["STEP_TYPE_OBJ"])) {
|
||||
throw (new \Exception(str_replace(array("{0}"), array($this->arrayParamException["stepTypeObj"]), "The \"{0}\" attribute is not defined")));
|
||||
}
|
||||
|
||||
$arrayData["STEP_TYPE_OBJ"] = trim($arrayData["STEP_TYPE_OBJ"]);
|
||||
|
||||
if ($arrayData["STEP_TYPE_OBJ"] == "") {
|
||||
throw (new \Exception(str_replace(array("{0}"), array($this->arrayParamException["stepTypeObj"]), "The \"{0}\" attribute is empty")));
|
||||
}
|
||||
|
||||
if (!isset($arrayData["STEP_UID_OBJ"])) {
|
||||
throw (new \Exception(str_replace(array("{0}"), array($this->arrayParamException["stepUidObj"]), "The \"{0}\" attribute is not defined")));
|
||||
}
|
||||
|
||||
$arrayData["STEP_UID_OBJ"] = trim($arrayData["STEP_UID_OBJ"]);
|
||||
|
||||
if ($arrayData["STEP_UID_OBJ"] == "") {
|
||||
throw (new \Exception(str_replace(array("{0}"), array($this->arrayParamException["stepUidObj"]), "The \"{0}\" attribute is empty")));
|
||||
}
|
||||
|
||||
if (!isset($arrayData["STEP_MODE"])) {
|
||||
throw (new \Exception(str_replace(array("{0}"), array($this->arrayParamException["stepMode"]), "The \"{0}\" attribute is not defined")));
|
||||
}
|
||||
|
||||
$arrayData["STEP_MODE"] = trim($arrayData["STEP_MODE"]);
|
||||
|
||||
if ($arrayData["STEP_MODE"] == "") {
|
||||
throw (new \Exception(str_replace(array("{0}"), array($this->arrayParamException["stepMode"]), "The \"{0}\" attribute is empty")));
|
||||
}
|
||||
|
||||
$this->throwExceptionIfHaveInvalidValueInTypeObj($arrayData["STEP_TYPE_OBJ"]);
|
||||
|
||||
$this->throwExceptionIfHaveInvalidValueInMode($arrayData["STEP_MODE"]);
|
||||
|
||||
$msg = $this->existsObjectUid($arrayData["STEP_TYPE_OBJ"], $arrayData["STEP_UID_OBJ"]);
|
||||
|
||||
if ($msg != "") {
|
||||
throw (new \Exception($msg));
|
||||
}
|
||||
|
||||
if ($this->existsRecord($taskUid, $arrayData["STEP_TYPE_OBJ"], $arrayData["STEP_UID_OBJ"])) {
|
||||
throw (new \Exception(str_replace(array("{0}", "{1}"), array($taskUid . ", " . $arrayData["STEP_TYPE_OBJ"] . ", " . $arrayData["STEP_UID_OBJ"], "STEP"), "The record \"{0}\", exists in table {1}")));
|
||||
}
|
||||
|
||||
//Create
|
||||
$step = new \Step();
|
||||
|
||||
$stepUid = $step->create(array(
|
||||
"PRO_UID" => $processUid,
|
||||
"TAS_UID" => $taskUid,
|
||||
"STEP_POSITION" => $step->getNextPosition($taskUid)
|
||||
));
|
||||
|
||||
if (!isset($arrayData["STEP_POSITION"]) || $arrayData["STEP_POSITION"] == "") {
|
||||
unset($arrayData["STEP_POSITION"]);
|
||||
}
|
||||
|
||||
$arrayData = $this->update($stepUid, $arrayData);
|
||||
|
||||
//Return
|
||||
unset($arrayData["STEP_UID"]);
|
||||
|
||||
$arrayData = array_merge(array("STEP_UID" => $stepUid), $arrayData);
|
||||
|
||||
if (!$this->formatFieldNameInUppercase) {
|
||||
$arrayData = array_change_key_case($arrayData, CASE_LOWER);
|
||||
}
|
||||
|
||||
return $arrayData;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update Step of a Task
|
||||
*
|
||||
* @param string $stepUid Unique id of Step
|
||||
* @param array $arrayData Data
|
||||
*
|
||||
* return array Return data of the Step updated
|
||||
*/
|
||||
public function update($stepUid, $arrayData)
|
||||
{
|
||||
try {
|
||||
$arrayData = array_change_key_case($arrayData, CASE_UPPER);
|
||||
|
||||
//Verify data
|
||||
$this->throwExceptionIfNotExistsStep($stepUid);
|
||||
|
||||
//Load Step
|
||||
$step = new \Step();
|
||||
$arrayStepData = $step->load($stepUid);
|
||||
|
||||
$taskUid = $arrayStepData["TAS_UID"];
|
||||
$proUid = $arrayStepData["PRO_UID"];
|
||||
|
||||
//Verify data
|
||||
if (isset($arrayData["STEP_TYPE_OBJ"]) && !isset($arrayData["STEP_UID_OBJ"])) {
|
||||
throw (new \Exception(str_replace(array("{0}"), array($this->arrayParamException["stepUidObj"]), "The \"{0}\" attribute is not defined")));
|
||||
}
|
||||
|
||||
if (!isset($arrayData["STEP_TYPE_OBJ"]) && isset($arrayData["STEP_UID_OBJ"])) {
|
||||
throw (new \Exception(str_replace(array("{0}"), array($this->arrayParamException["stepTypeObj"]), "The \"{0}\" attribute is not defined")));
|
||||
}
|
||||
|
||||
if (isset($arrayData["STEP_TYPE_OBJ"])) {
|
||||
$arrayData["STEP_TYPE_OBJ"] = trim($arrayData["STEP_TYPE_OBJ"]);
|
||||
|
||||
if ($arrayData["STEP_TYPE_OBJ"] == "") {
|
||||
throw (new \Exception(str_replace(array("{0}"), array($this->arrayParamException["stepTypeObj"]), "The \"{0}\" attribute is empty")));
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($arrayData["STEP_UID_OBJ"])) {
|
||||
$arrayData["STEP_UID_OBJ"] = trim($arrayData["STEP_UID_OBJ"]);
|
||||
|
||||
if ($arrayData["STEP_UID_OBJ"] == "") {
|
||||
throw (new \Exception(str_replace(array("{0}"), array($this->arrayParamException["stepUidObj"]), "The \"{0}\" attribute is empty")));
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($arrayData["STEP_MODE"])) {
|
||||
$arrayData["STEP_MODE"] = trim($arrayData["STEP_MODE"]);
|
||||
|
||||
if ($arrayData["STEP_MODE"] == "") {
|
||||
throw (new \Exception(str_replace(array("{0}"), array($this->arrayParamException["stepMode"]), "The \"{0}\" attribute is empty")));
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($arrayData["STEP_TYPE_OBJ"])) {
|
||||
$this->throwExceptionIfHaveInvalidValueInTypeObj($arrayData["STEP_TYPE_OBJ"]);
|
||||
}
|
||||
|
||||
if (isset($arrayData["STEP_MODE"])) {
|
||||
$this->throwExceptionIfHaveInvalidValueInMode($arrayData["STEP_MODE"]);
|
||||
}
|
||||
|
||||
if (isset($arrayData["STEP_TYPE_OBJ"]) && isset($arrayData["STEP_UID_OBJ"])) {
|
||||
$msg = $this->existsObjectUid($arrayData["STEP_TYPE_OBJ"], $arrayData["STEP_UID_OBJ"]);
|
||||
|
||||
if ($msg != "") {
|
||||
throw (new \Exception($msg));
|
||||
}
|
||||
|
||||
if ($this->existsRecord($taskUid, $arrayData["STEP_TYPE_OBJ"], $arrayData["STEP_UID_OBJ"], 0, $stepUid)) {
|
||||
throw (new \Exception(str_replace(array("{0}", "{1}"), array($taskUid . ", " . $arrayData["STEP_TYPE_OBJ"] . ", " . $arrayData["STEP_UID_OBJ"], "STEP"), "The record \"{0}\", exists in table {1}")));
|
||||
}
|
||||
}
|
||||
|
||||
//Update
|
||||
$step = new \Step();
|
||||
|
||||
$arrayData["STEP_UID"] = $stepUid;
|
||||
$tempPosition = (isset($arrayData["STEP_POSITION"])) ? $arrayData["STEP_POSITION"] : $arrayStepData["STEP_POSITION"];
|
||||
$arrayData["STEP_POSITION"] = $arrayStepData["STEP_POSITION"];
|
||||
$result = $step->update($arrayData);
|
||||
|
||||
if (isset($tempPosition) && ($tempPosition != $arrayStepData["STEP_POSITION"])) {
|
||||
$this->moveSteps($proUid, $taskUid, $stepUid, $tempPosition);
|
||||
}
|
||||
|
||||
//Return
|
||||
unset($arrayData["STEP_UID"]);
|
||||
$arrayData["STEP_POSITION"] = $tempPosition;
|
||||
|
||||
if (!$this->formatFieldNameInUppercase) {
|
||||
$arrayData = array_change_key_case($arrayData, CASE_LOWER);
|
||||
}
|
||||
|
||||
return $arrayData;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete Step of a Task
|
||||
*
|
||||
* @param string $stepUid Unique id of Step
|
||||
*
|
||||
* return void
|
||||
*/
|
||||
public function delete($stepUid)
|
||||
{
|
||||
try {
|
||||
//Verify data
|
||||
$this->throwExceptionIfNotExistsStep($stepUid);
|
||||
|
||||
//Get position
|
||||
$criteria = new \Criteria("workflow");
|
||||
|
||||
$criteria->add(\StepPeer::STEP_UID, $stepUid, \Criteria::EQUAL);
|
||||
|
||||
$rsCriteria = \StepPeer::doSelectRS($criteria);
|
||||
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
|
||||
$rsCriteria->next();
|
||||
|
||||
$row = $rsCriteria->getRow();
|
||||
|
||||
$position = (int)($row["STEP_POSITION"]);
|
||||
|
||||
//Delete
|
||||
$step = new \Step();
|
||||
|
||||
$step->reOrder($stepUid, $position);
|
||||
$step->remove($stepUid);
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all Steps of a Task
|
||||
*
|
||||
* @param string $taskUid Unique id of Task
|
||||
*
|
||||
* return array Return an array with all Steps of a Task
|
||||
*/
|
||||
public function getSteps($taskUid)
|
||||
{
|
||||
try {
|
||||
$arrayStep = array();
|
||||
|
||||
$step = new \ProcessMaker\BusinessModel\Step();
|
||||
$step->setFormatFieldNameInUppercase($this->formatFieldNameInUppercase);
|
||||
$step->setArrayParamException($this->arrayParamException);
|
||||
|
||||
//Verify data
|
||||
$this->throwExceptionIfNotExistsTask($taskUid);
|
||||
|
||||
//Get data
|
||||
$criteria = new \Criteria("workflow");
|
||||
|
||||
$criteria->add(\StepPeer::TAS_UID, $taskUid, \Criteria::EQUAL);
|
||||
$criteria->addAscendingOrderByColumn(\StepPeer::STEP_POSITION);
|
||||
|
||||
$rsCriteria = \StepPeer::doSelectRS($criteria);
|
||||
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
|
||||
while ($rsCriteria->next()) {
|
||||
$row = $rsCriteria->getRow();
|
||||
|
||||
$arrayData = $step->getStep($row["STEP_UID"]);
|
||||
|
||||
if (count($arrayData) > 0) {
|
||||
$arrayStep[] = $arrayData;
|
||||
}
|
||||
}
|
||||
|
||||
//Return
|
||||
return $arrayStep;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data of a Step
|
||||
*
|
||||
* @param string $stepUid Unique id of Step
|
||||
*
|
||||
* return array Return an array with data of a Step
|
||||
*/
|
||||
public function getStep($stepUid)
|
||||
{
|
||||
try {
|
||||
$arrayStep = array();
|
||||
|
||||
//Verify data
|
||||
$this->throwExceptionIfNotExistsStep($stepUid);
|
||||
|
||||
//Get data
|
||||
//Call plugin
|
||||
$pluginRegistry = &\PMPluginRegistry::getSingleton();
|
||||
$externalSteps = $pluginRegistry->getSteps();
|
||||
|
||||
$criteria = new \Criteria("workflow");
|
||||
|
||||
$criteria->add(\StepPeer::STEP_UID, $stepUid, \Criteria::EQUAL);
|
||||
|
||||
$rsCriteria = \StepPeer::doSelectRS($criteria);
|
||||
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
|
||||
$rsCriteria->next();
|
||||
|
||||
$row = $rsCriteria->getRow();
|
||||
|
||||
$titleObj = "";
|
||||
$descriptionObj = "";
|
||||
|
||||
switch ($row["STEP_TYPE_OBJ"]) {
|
||||
case "DYNAFORM":
|
||||
$dynaform = new \Dynaform();
|
||||
$arrayData = $dynaform->load($row["STEP_UID_OBJ"]);
|
||||
|
||||
$titleObj = $arrayData["DYN_TITLE"];
|
||||
$descriptionObj = $arrayData["DYN_DESCRIPTION"];
|
||||
break;
|
||||
case "INPUT_DOCUMENT":
|
||||
$inputDocument = new \InputDocument();
|
||||
$arrayData = $inputDocument->getByUid($row["STEP_UID_OBJ"]);
|
||||
|
||||
if ($arrayData === false) {
|
||||
return $arrayStep;
|
||||
}
|
||||
|
||||
$titleObj = $arrayData["INP_DOC_TITLE"];
|
||||
$descriptionObj = $arrayData["INP_DOC_DESCRIPTION"];
|
||||
break;
|
||||
case "OUTPUT_DOCUMENT":
|
||||
$outputDocument = new \OutputDocument();
|
||||
$arrayData = $outputDocument->getByUid($row["STEP_UID_OBJ"]);
|
||||
|
||||
if ($arrayData === false) {
|
||||
return $arrayStep;
|
||||
}
|
||||
|
||||
$titleObj = $arrayData["OUT_DOC_TITLE"];
|
||||
$descriptionObj = $arrayData["OUT_DOC_DESCRIPTION"];
|
||||
break;
|
||||
case "EXTERNAL":
|
||||
$titleObj = "unknown " . $row["STEP_UID"];
|
||||
|
||||
if (is_array($externalSteps) && count($externalSteps) > 0) {
|
||||
foreach ($externalSteps as $key => $value) {
|
||||
if ($value->sStepId == $row["STEP_UID_OBJ"]) {
|
||||
$titleObj = $value->sStepTitle;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
//Return
|
||||
$arrayStep = array(
|
||||
$this->getFieldNameByFormatFieldName("STEP_UID") => $stepUid,
|
||||
$this->getFieldNameByFormatFieldName("STEP_TYPE_OBJ") => $row["STEP_TYPE_OBJ"],
|
||||
$this->getFieldNameByFormatFieldName("STEP_UID_OBJ") => $row["STEP_UID_OBJ"],
|
||||
$this->getFieldNameByFormatFieldName("STEP_CONDITION") => $row["STEP_CONDITION"],
|
||||
$this->getFieldNameByFormatFieldName("STEP_POSITION") => (int)($row["STEP_POSITION"]),
|
||||
$this->getFieldNameByFormatFieldName("STEP_MODE") => $row["STEP_MODE"],
|
||||
$this->getFieldNameByFormatFieldName("OBJ_TITLE") => $titleObj,
|
||||
$this->getFieldNameByFormatFieldName("OBJ_DESCRIPTION") => $descriptionObj
|
||||
);
|
||||
|
||||
return $arrayStep;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get available Triggers of a Step
|
||||
*
|
||||
* @param string $stepUid Unique id of Step
|
||||
* @param string $type Type (BEFORE, AFTER, BEFORE_ASSIGNMENT, BEFORE_ROUTING, AFTER_ROUTING)
|
||||
* @param string $taskUid Unique id of Task
|
||||
*
|
||||
* return array Return an array with the Triggers available of a Step
|
||||
*/
|
||||
public function getAvailableTriggers($stepUid, $type, $taskUid = "")
|
||||
{
|
||||
try {
|
||||
$arrayAvailableTrigger = array();
|
||||
|
||||
//Verify data
|
||||
if ($stepUid != "") {
|
||||
$this->throwExceptionIfNotExistsStep($stepUid);
|
||||
}
|
||||
|
||||
if ($stepUid == "") {
|
||||
$this->throwExceptionIfNotExistsTask($taskUid);
|
||||
}
|
||||
|
||||
//Get data
|
||||
$trigger = new \ProcessMaker\BusinessModel\Trigger();
|
||||
|
||||
$flagStepAssignTask = 0;
|
||||
|
||||
if ($stepUid != "") {
|
||||
//Load Step
|
||||
$step = new \Step();
|
||||
|
||||
$arrayStepData = $step->load($stepUid);
|
||||
|
||||
$processUid = $arrayStepData["PRO_UID"];
|
||||
} else {
|
||||
//Load Task
|
||||
$task = new \Task();
|
||||
|
||||
$arrayTaskData = $task->load($taskUid);
|
||||
|
||||
$processUid = $arrayTaskData["PRO_UID"];
|
||||
|
||||
//Set variables
|
||||
$flagStepAssignTask = 1;
|
||||
|
||||
switch ($type) {
|
||||
case "BEFORE_ASSIGNMENT":
|
||||
$stepUid = "-1";
|
||||
$type = "BEFORE";
|
||||
break;
|
||||
case "BEFORE_ROUTING":
|
||||
$stepUid = "-2";
|
||||
$type = "BEFORE";
|
||||
break;
|
||||
case "AFTER_ROUTING":
|
||||
$stepUid = "-2";
|
||||
$type = "AFTER";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//Get data
|
||||
//Get Uids
|
||||
$arrayUid = array();
|
||||
|
||||
$criteria = new \Criteria("workflow");
|
||||
|
||||
$criteria->addSelectColumn(\StepTriggerPeer::TRI_UID);
|
||||
$criteria->add(\StepTriggerPeer::STEP_UID, $stepUid, \Criteria::EQUAL);
|
||||
|
||||
if ($flagStepAssignTask == 1) {
|
||||
$criteria->add(\StepTriggerPeer::TAS_UID, $taskUid, \Criteria::EQUAL);
|
||||
}
|
||||
|
||||
$criteria->add(\StepTriggerPeer::ST_TYPE, $type, \Criteria::EQUAL);
|
||||
|
||||
$rsCriteria = \StepTriggerPeer::doSelectRS($criteria);
|
||||
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
|
||||
while ($rsCriteria->next()) {
|
||||
$row = $rsCriteria->getRow();
|
||||
|
||||
$arrayUid[] = $row["TRI_UID"];
|
||||
}
|
||||
|
||||
//Criteria
|
||||
$criteria = $trigger->getTriggerCriteria();
|
||||
|
||||
$criteria->add(\TriggersPeer::TRI_UID, $arrayUid, \Criteria::NOT_IN);
|
||||
$criteria->add(\TriggersPeer::PRO_UID, $processUid, \Criteria::EQUAL);
|
||||
$criteria->addAscendingOrderByColumn("TRI_TITLE");
|
||||
|
||||
$rsCriteria = \TriggersPeer::doSelectRS($criteria);
|
||||
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
|
||||
while ($rsCriteria->next()) {
|
||||
$row = $rsCriteria->getRow();
|
||||
|
||||
$arrayAvailableTrigger[] = array(
|
||||
$this->getFieldNameByFormatFieldName("TRI_UID") => $row["TRI_UID"],
|
||||
$this->getFieldNameByFormatFieldName("TRI_TITLE") => $row["TRI_TITLE"],
|
||||
$this->getFieldNameByFormatFieldName("TRI_DESCRIPTION") => $row["TRI_DESCRIPTION"],
|
||||
$this->getFieldNameByFormatFieldName("TRI_TYPE") => $row["TRI_TYPE"],
|
||||
$this->getFieldNameByFormatFieldName("TRI_WEBBOT") => $row["TRI_WEBBOT"],
|
||||
$this->getFieldNameByFormatFieldName("TRI_PARAM") => $row["TRI_PARAM"]
|
||||
);
|
||||
}
|
||||
|
||||
//Return
|
||||
return $arrayAvailableTrigger;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all Triggers of a Step
|
||||
*
|
||||
* @param string $stepUid Unique id of Step
|
||||
* @param string $taskUid Unique id of Task
|
||||
*
|
||||
* return array Return an array with all Triggers of a Step
|
||||
*/
|
||||
public function getTriggers($stepUid, $taskUid = "")
|
||||
{
|
||||
try {
|
||||
$arrayTrigger = array();
|
||||
|
||||
//Verify data
|
||||
if ($stepUid != "") {
|
||||
$this->throwExceptionIfNotExistsStep($stepUid);
|
||||
}
|
||||
|
||||
if ($stepUid == "") {
|
||||
$this->throwExceptionIfNotExistsTask($taskUid);
|
||||
}
|
||||
|
||||
//Get data
|
||||
$bmTrigger = new \ProcessMaker\BusinessModel\Trigger();
|
||||
$bmStepTrigger = new \ProcessMaker\BusinessModel\Step\Trigger();
|
||||
|
||||
$stepTrigger = new \StepTrigger();
|
||||
|
||||
if ($stepUid != "") {
|
||||
//Load Step
|
||||
$step = new \Step();
|
||||
|
||||
$arrayStepData = $step->load($stepUid);
|
||||
|
||||
$taskUid = $arrayStepData["TAS_UID"];
|
||||
}
|
||||
|
||||
$arrayTriggerType1 = array(
|
||||
"BEFORE" => "BEFORE",
|
||||
"AFTER" => "AFTER"
|
||||
);
|
||||
|
||||
$arrayTriggerType2 = array(
|
||||
"BEFORE_ASSIGNMENT" => "BEFORE",
|
||||
"BEFORE_ROUTING" => "BEFORE",
|
||||
"AFTER_ROUTING" => "AFTER"
|
||||
);
|
||||
|
||||
$arrayTriggerType = ($stepUid != "")? $arrayTriggerType1 : $arrayTriggerType2;
|
||||
|
||||
foreach ($arrayTriggerType as $index => $value) {
|
||||
$triggerType = $index;
|
||||
$type = $value;
|
||||
|
||||
$flagStepAssignTask = 0;
|
||||
|
||||
switch ($triggerType) {
|
||||
case "BEFORE_ASSIGNMENT":
|
||||
$stepUid = "-1";
|
||||
$flagStepAssignTask = 1;
|
||||
break;
|
||||
case "BEFORE_ROUTING":
|
||||
$stepUid = "-2";
|
||||
$flagStepAssignTask = 1;
|
||||
break;
|
||||
case "AFTER_ROUTING":
|
||||
$stepUid = "-2";
|
||||
$flagStepAssignTask = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
$stepTrigger->orderPosition($stepUid, $taskUid, $type);
|
||||
|
||||
//Criteria
|
||||
$criteria = $bmTrigger->getTriggerCriteria();
|
||||
|
||||
$criteria->addSelectColumn(\StepTriggerPeer::ST_TYPE);
|
||||
$criteria->addSelectColumn(\StepTriggerPeer::ST_CONDITION);
|
||||
$criteria->addSelectColumn(\StepTriggerPeer::ST_POSITION);
|
||||
$criteria->addJoin(\StepTriggerPeer::TRI_UID, \TriggersPeer::TRI_UID, \Criteria::LEFT_JOIN);
|
||||
$criteria->add(\StepTriggerPeer::STEP_UID, $stepUid, \Criteria::EQUAL);
|
||||
$criteria->add(\StepTriggerPeer::TAS_UID, $taskUid, \Criteria::EQUAL);
|
||||
$criteria->add(\StepTriggerPeer::ST_TYPE, $type, \Criteria::EQUAL);
|
||||
$criteria->addAscendingOrderByColumn(\StepTriggerPeer::ST_POSITION);
|
||||
|
||||
$rsCriteria = \StepTriggerPeer::doSelectRS($criteria);
|
||||
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
|
||||
while ($rsCriteria->next()) {
|
||||
$row = $rsCriteria->getRow();
|
||||
|
||||
if ($flagStepAssignTask == 1) {
|
||||
$row["ST_TYPE"] = $triggerType;
|
||||
}
|
||||
|
||||
$arrayTrigger[] = $bmStepTrigger->getTriggerDataFromRecord($row);
|
||||
}
|
||||
}
|
||||
|
||||
return $arrayTrigger;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate Process Uid
|
||||
* @var string $pro_uid. Uid for Process
|
||||
* @var string $tas_uid. Uid for Task
|
||||
* @var string $step_uid. Uid for Step
|
||||
* @var string $step_pos. Position for Step
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function moveSteps($pro_uid, $tas_uid, $step_uid, $step_pos) {
|
||||
$this->setFormatFieldNameInUppercase(false);
|
||||
$this->setArrayParamException(array("taskUid" => "act_uid"));
|
||||
$aSteps = $this->getSteps($tas_uid);
|
||||
|
||||
foreach ($aSteps as $dataStep) {
|
||||
if ($dataStep['step_uid'] == $step_uid) {
|
||||
$prStepPos = (int)$dataStep['step_position'];
|
||||
}
|
||||
}
|
||||
$seStepPos = $step_pos;
|
||||
|
||||
//Principal Step is up
|
||||
if ($prStepPos == $seStepPos) {
|
||||
return true;
|
||||
} elseif ($prStepPos < $seStepPos) {
|
||||
$modPos = 'UP';
|
||||
$newPos = $seStepPos;
|
||||
$iniPos = $prStepPos+1;
|
||||
$finPos = $seStepPos;
|
||||
} else {
|
||||
$modPos = 'DOWN';
|
||||
$newPos = $seStepPos;
|
||||
$iniPos = $seStepPos;
|
||||
$finPos = $prStepPos-1;
|
||||
}
|
||||
|
||||
$range = range($iniPos, $finPos);
|
||||
foreach ($aSteps as $dataStep) {
|
||||
if ((in_array($dataStep['step_position'], $range)) && ($dataStep['step_uid'] != $step_uid)) {
|
||||
$stepChangeIds[] = $dataStep['step_uid'];
|
||||
$stepChangePos[] = $dataStep['step_position'];
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($stepChangeIds as $key => $value) {
|
||||
if ($modPos == 'UP') {
|
||||
$tempPos = ((int)$stepChangePos[$key])-1;
|
||||
$this->changePosStep($value, $tempPos);
|
||||
} else {
|
||||
$tempPos = ((int)$stepChangePos[$key])+1;
|
||||
$this->changePosStep($value, $tempPos);
|
||||
}
|
||||
}
|
||||
$this->changePosStep($step_uid, $newPos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate Process Uid
|
||||
* @var string $pro_uid. Uid for process
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function changePosStep ($step_uid, $pos)
|
||||
{
|
||||
$data = array(
|
||||
'STEP_UID' => $step_uid,
|
||||
'STEP_POSITION' => $pos
|
||||
);
|
||||
$oStep = new \Step();
|
||||
$oStep->update($data);
|
||||
}
|
||||
}
|
||||
|
||||
454
workflow/engine/src/ProcessMaker/BusinessModel/Step/Trigger.php
Normal file
454
workflow/engine/src/ProcessMaker/BusinessModel/Step/Trigger.php
Normal file
@@ -0,0 +1,454 @@
|
||||
<?php
|
||||
namespace ProcessMaker\BusinessModel\Step;
|
||||
|
||||
use \ProcessMaker\BusinessModel\Step;
|
||||
|
||||
class Trigger
|
||||
{
|
||||
/**
|
||||
* Verify if exists the record in table STEP_TRIGGER
|
||||
*
|
||||
* @param string $stepUid Unique id of Step
|
||||
* @param string $type Type (BEFORE, AFTER)
|
||||
* @param string $taskUid Unique id of Task
|
||||
* @param string $triggerUid Unique id of Trigger
|
||||
* @param int $position Position
|
||||
* @param string $triggerUidExclude Unique id of Trigger to exclude
|
||||
*
|
||||
* return bool Return true if exists the record in table STEP_TRIGGER, false otherwise
|
||||
*/
|
||||
public function existsRecord($stepUid, $type, $taskUid, $triggerUid, $position = 0, $triggerUidExclude = "")
|
||||
{
|
||||
try {
|
||||
$criteria = new \Criteria("workflow");
|
||||
|
||||
$criteria->addSelectColumn(\StepTriggerPeer::STEP_UID);
|
||||
$criteria->add(\StepTriggerPeer::STEP_UID, $stepUid, \Criteria::EQUAL);
|
||||
$criteria->add(\StepTriggerPeer::ST_TYPE, $type, \Criteria::EQUAL);
|
||||
$criteria->add(\StepTriggerPeer::TAS_UID, $taskUid, \Criteria::EQUAL);
|
||||
|
||||
if ($triggerUid != "") {
|
||||
$criteria->add(\StepTriggerPeer::TRI_UID, $triggerUid, \Criteria::EQUAL);
|
||||
}
|
||||
|
||||
if ($position > 0) {
|
||||
$criteria->add(\StepTriggerPeer::ST_POSITION, $position, \Criteria::EQUAL);
|
||||
}
|
||||
|
||||
if ($triggerUidExclude != "") {
|
||||
$criteria->add(\StepTriggerPeer::TRI_UID, $triggerUidExclude, \Criteria::NOT_EQUAL);
|
||||
}
|
||||
|
||||
$rsCriteria = \StepTriggerPeer::doSelectRS($criteria);
|
||||
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
|
||||
if ($rsCriteria->next()) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign Trigger to a Step
|
||||
*
|
||||
* @param string $stepUid Unique id of Step
|
||||
* @param string $type Type (BEFORE, AFTER, BEFORE_ASSIGNMENT, BEFORE_ROUTING, AFTER_ROUTING)
|
||||
* @param string $taskUid Unique id of Task
|
||||
* @param string $triggerUid Unique id of Trigger
|
||||
* @param array $arrayData Data
|
||||
*
|
||||
* return array Data of the Trigger assigned to a Step
|
||||
*/
|
||||
public function create($stepUid, $type, $taskUid, $triggerUid, $arrayData)
|
||||
{
|
||||
try {
|
||||
$stepUidIni = $stepUid;
|
||||
$typeIni = $type;
|
||||
|
||||
$flagStepAssignTask = 0;
|
||||
|
||||
if ($stepUid == "") {
|
||||
$flagStepAssignTask = 1;
|
||||
|
||||
switch ($type) {
|
||||
case "BEFORE_ASSIGNMENT":
|
||||
$stepUid = "-1";
|
||||
$type = "BEFORE";
|
||||
break;
|
||||
case "BEFORE_ROUTING":
|
||||
$stepUid = "-2";
|
||||
$type = "BEFORE";
|
||||
break;
|
||||
case "AFTER_ROUTING":
|
||||
$stepUid = "-2";
|
||||
$type = "AFTER";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//Verify data
|
||||
if ($flagStepAssignTask == 0) {
|
||||
$step = new \Step();
|
||||
|
||||
if (!$step->StepExists($stepUid)) {
|
||||
throw (new \Exception(str_replace(array("{0}", "{1}"), array($stepUid, "STEP"), "The UID \"{0}\" doesn't exist in table {1}")));
|
||||
}
|
||||
}
|
||||
|
||||
$task = new \Task();
|
||||
|
||||
if (!$task->taskExists($taskUid)) {
|
||||
throw (new \Exception(str_replace(array("{0}", "{1}"), array($taskUid, "TASK"), "The UID \"{0}\" doesn't exist in table {1}")));
|
||||
}
|
||||
|
||||
$trigger = new \Triggers();
|
||||
|
||||
if (!$trigger->TriggerExists($triggerUid)) {
|
||||
throw (new \Exception(str_replace(array("{0}", "{1}"), array($triggerUid, "TRIGGERS"), "The UID \"{0}\" doesn't exist in table {1}")));
|
||||
}
|
||||
|
||||
if ($this->existsRecord($stepUid, $type, $taskUid, $triggerUid)) {
|
||||
throw (new \Exception(str_replace(array("{0}", "{1}"), array($stepUid . ", " . $type . ", " . $taskUid . ", " . $triggerUid, "STEP_TRIGGER"), "The record \"{0}\", exists in table {1}")));
|
||||
}
|
||||
|
||||
//Create
|
||||
$stepTrigger = new \StepTrigger();
|
||||
$posIni = $stepTrigger->getNextPosition($stepUid, $type, $taskUid);
|
||||
$stepTrigger->createRow(array(
|
||||
"STEP_UID" => $stepUid,
|
||||
"TAS_UID" => $taskUid,
|
||||
"TRI_UID" => $triggerUid,
|
||||
"ST_TYPE" => $type,
|
||||
"ST_CONDITION" => (isset($arrayData['st_condition'])) ? $arrayData['st_condition'] : '',
|
||||
"ST_POSITION" => $posIni
|
||||
));
|
||||
|
||||
$arrayData = $this->update($stepUid, $typeIni, $taskUid, $triggerUid, $arrayData);
|
||||
|
||||
return $arrayData;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update Trigger of a Step
|
||||
*
|
||||
* @param string $stepUid Unique id of Step
|
||||
* @param string $type Type (BEFORE, AFTER, BEFORE_ASSIGNMENT, BEFORE_ROUTING, AFTER_ROUTING)
|
||||
* @param string $taskUid Unique id of Task
|
||||
* @param string $triggerUid Unique id of Trigger
|
||||
* @param array $arrayData Data
|
||||
*
|
||||
* return array Data updated of the Trigger assigned to a Step
|
||||
*/
|
||||
public function update($stepUid, $type, $taskUid, $triggerUid, $arrayData)
|
||||
{
|
||||
try {
|
||||
$flagStepAssignTask = 0;
|
||||
|
||||
if (($stepUid == "") || ($stepUid == "-1") || ($stepUid == "-2")) {
|
||||
$flagStepAssignTask = 1;
|
||||
|
||||
switch ($type) {
|
||||
case "BEFORE_ASSIGNMENT":
|
||||
$stepUid = "-1";
|
||||
$type = "BEFORE";
|
||||
break;
|
||||
case "BEFORE_ROUTING":
|
||||
$stepUid = "-2";
|
||||
$type = "BEFORE";
|
||||
break;
|
||||
case "AFTER_ROUTING":
|
||||
$stepUid = "-2";
|
||||
$type = "AFTER";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//Verify data
|
||||
if ($flagStepAssignTask == 0) {
|
||||
$step = new \Step();
|
||||
|
||||
if (!$step->StepExists($stepUid)) {
|
||||
throw (new \Exception(str_replace(array("{0}", "{1}"), array($stepUid, "STEP"), "The UID \"{0}\" doesn't exist in table {1}")));
|
||||
}
|
||||
}
|
||||
|
||||
$trigger = new \Triggers();
|
||||
|
||||
if (!$trigger->TriggerExists($triggerUid)) {
|
||||
throw (new \Exception(str_replace(array("{0}", "{1}"), array($triggerUid, "TRIGGERS"), "The UID \"{0}\" doesn't exist in table {1}")));
|
||||
}
|
||||
|
||||
//Update
|
||||
$stepTrigger = new \StepTrigger();
|
||||
|
||||
$arrayUpdateData = array();
|
||||
|
||||
$arrayUpdateData["STEP_UID"] = $stepUid;
|
||||
$arrayUpdateData["TAS_UID"] = $taskUid;
|
||||
$arrayUpdateData["TRI_UID"] = $triggerUid;
|
||||
$arrayUpdateData["ST_TYPE"] = $type;
|
||||
|
||||
if (isset($arrayData["st_condition"])) {
|
||||
$arrayUpdateData["ST_CONDITION"] = $arrayData["st_condition"];
|
||||
}
|
||||
|
||||
if (isset($arrayData["st_position"]) && $arrayData["st_position"] != "") {
|
||||
$tempPos = (int)($arrayData["st_position"]);
|
||||
}
|
||||
|
||||
$stepTrigger->update($arrayUpdateData);
|
||||
if (isset($tempPos)) {
|
||||
$this->moveStepTriggers($taskUid, $stepUid, $triggerUid, $type, $tempPos);
|
||||
}
|
||||
return array_change_key_case($arrayUpdateData, CASE_LOWER);
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete Trigger of a Step
|
||||
*
|
||||
* @param string $stepUid Unique id of Step
|
||||
* @param string $type Type (BEFORE, AFTER, BEFORE_ASSIGNMENT, BEFORE_ROUTING, AFTER_ROUTING)
|
||||
* @param string $taskUid Unique id of Task
|
||||
* @param string $triggerUid Unique id of Trigger
|
||||
*
|
||||
* return void
|
||||
*/
|
||||
public function delete($stepUid, $type, $taskUid, $triggerUid)
|
||||
{
|
||||
try {
|
||||
if ($stepUid == "") {
|
||||
switch ($type) {
|
||||
case "BEFORE_ASSIGNMENT":
|
||||
$stepUid = "-1";
|
||||
$type = "BEFORE";
|
||||
break;
|
||||
case "BEFORE_ROUTING":
|
||||
$stepUid = "-2";
|
||||
$type = "BEFORE";
|
||||
break;
|
||||
case "AFTER_ROUTING":
|
||||
$stepUid = "-2";
|
||||
$type = "AFTER";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//Verify data
|
||||
if (!$this->existsRecord($stepUid, $type, $taskUid, $triggerUid)) {
|
||||
throw (new \Exception(str_replace(array("{0}", "{1}"), array($stepUid . ", " . $type . ", " . $taskUid . ", " . $triggerUid, "STEP_TRIGGER"), "The record \"{0}\", doesn't exist in table {1}")));
|
||||
}
|
||||
|
||||
//Get position
|
||||
$stepTrigger = new \StepTrigger();
|
||||
|
||||
$arrayData = $stepTrigger->load($stepUid, $taskUid, $triggerUid, $type);
|
||||
|
||||
$position = (int)($arrayData["ST_POSITION"]);
|
||||
|
||||
//Delete
|
||||
$stepTrigger = new \StepTrigger();
|
||||
|
||||
$stepTrigger->reOrder($stepUid, $taskUid, $type, $position);
|
||||
$stepTrigger->remove($stepUid, $taskUid, $triggerUid, $type);
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data of a Trigger from a record
|
||||
*
|
||||
* @param array $record Record
|
||||
*
|
||||
* return array Return an array with data of a Trigger
|
||||
*/
|
||||
public function getTriggerDataFromRecord($record)
|
||||
{
|
||||
try {
|
||||
return array(
|
||||
"tri_uid" => $record["TRI_UID"],
|
||||
"tri_title" => $record["TRI_TITLE"],
|
||||
"tri_description" => $record["TRI_DESCRIPTION"],
|
||||
"st_type" => $record["ST_TYPE"],
|
||||
"st_condition" => $record["ST_CONDITION"],
|
||||
"st_position" => (int)($record["ST_POSITION"])
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data of a Trigger
|
||||
*
|
||||
* @param string $stepUid Unique id of Step
|
||||
* @param string $type Type (BEFORE, AFTER, BEFORE_ASSIGNMENT, BEFORE_ROUTING, AFTER_ROUTING)
|
||||
* @param string $taskUid Unique id of Task
|
||||
* @param string $triggerUid Unique id of Trigger
|
||||
*
|
||||
* return array Return an array with data of a Trigger
|
||||
*/
|
||||
public function getTrigger($stepUid, $type, $taskUid, $triggerUid)
|
||||
{
|
||||
try {
|
||||
$typeIni = $type;
|
||||
|
||||
$flagStepAssignTask = 0;
|
||||
|
||||
if ($stepUid == "") {
|
||||
$flagStepAssignTask = 1;
|
||||
|
||||
switch ($type) {
|
||||
case "BEFORE_ASSIGNMENT":
|
||||
$stepUid = "-1";
|
||||
$type = "BEFORE";
|
||||
break;
|
||||
case "BEFORE_ROUTING":
|
||||
$stepUid = "-2";
|
||||
$type = "BEFORE";
|
||||
break;
|
||||
case "AFTER_ROUTING":
|
||||
$stepUid = "-2";
|
||||
$type = "AFTER";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//Verify data
|
||||
if (!$this->existsRecord($stepUid, $type, $taskUid, $triggerUid)) {
|
||||
throw (new \Exception(str_replace(array("{0}", "{1}"), array($stepUid . ", " . $type . ", " . $taskUid . ", " . $triggerUid, "STEP_TRIGGER"), "The record \"{0}\", doesn't exist in table {1}")));
|
||||
}
|
||||
|
||||
//Get data
|
||||
$trigger = new \ProcessMaker\BusinessModel\Trigger();
|
||||
|
||||
$criteria = $trigger->getTriggerCriteria();
|
||||
|
||||
$criteria->addSelectColumn(\StepTriggerPeer::ST_TYPE);
|
||||
$criteria->addSelectColumn(\StepTriggerPeer::ST_CONDITION);
|
||||
$criteria->addSelectColumn(\StepTriggerPeer::ST_POSITION);
|
||||
$criteria->addJoin(\StepTriggerPeer::TRI_UID, \TriggersPeer::TRI_UID, \Criteria::LEFT_JOIN);
|
||||
$criteria->add(\TriggersPeer::TRI_UID, $triggerUid, \Criteria::EQUAL);
|
||||
$criteria->add(\StepTriggerPeer::STEP_UID, $stepUid, \Criteria::EQUAL);
|
||||
$criteria->add(\StepTriggerPeer::TAS_UID, $taskUid, \Criteria::EQUAL);
|
||||
$criteria->add(\StepTriggerPeer::ST_TYPE, $type, \Criteria::EQUAL);
|
||||
|
||||
$rsCriteria = \StepTriggerPeer::doSelectRS($criteria);
|
||||
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
|
||||
$rsCriteria->next();
|
||||
|
||||
$row = $rsCriteria->getRow();
|
||||
|
||||
if ($flagStepAssignTask == 1) {
|
||||
$row["ST_TYPE"] = $typeIni;
|
||||
}
|
||||
|
||||
return $this->getTriggerDataFromRecord($row);
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate Process Uid
|
||||
* @var string $pro_uid. Uid for Process
|
||||
* @var string $tas_uid. Uid for Task
|
||||
* @var string $step_uid. Uid for Step
|
||||
* @var string $step_pos. Position for Step
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function moveStepTriggers($tasUid, $stepUid, $triUid, $type, $newPos) {
|
||||
$stepTrigger = new \ProcessMaker\BusinessModel\Step();
|
||||
$tempStep = $stepUid;
|
||||
$typeCompare = $type;
|
||||
if ($tempStep == '-1' || $tempStep == '-2') {
|
||||
$tempStep = '';
|
||||
if (($stepUid == '-1') && ($type == 'BEFORE')) {
|
||||
$typeCompare = "BEFORE_ASSIGNMENT";
|
||||
} elseif (($stepUid == '-2') && ($type == 'BEFORE')) {
|
||||
$typeCompare = "BEFORE_ROUTING";
|
||||
} elseif (($stepUid == '-2') && ($type == 'AFTER')) {
|
||||
$typeCompare = "AFTER_ROUTING";
|
||||
}
|
||||
}
|
||||
$aStepTriggers = $stepTrigger->getTriggers($tempStep, $tasUid);
|
||||
foreach ($aStepTriggers as $dataStep) {
|
||||
if (($dataStep['st_type'] == $typeCompare) && ($dataStep['tri_uid'] == $triUid)) {
|
||||
$prStepPos = (int)$dataStep['st_position'];
|
||||
}
|
||||
}
|
||||
$seStepPos = $newPos;
|
||||
|
||||
//Principal Step is up
|
||||
if ($prStepPos == $seStepPos) {
|
||||
return true;
|
||||
} elseif ($prStepPos < $seStepPos) {
|
||||
$modPos = 'UP';
|
||||
$newPos = $seStepPos;
|
||||
$iniPos = $prStepPos+1;
|
||||
$finPos = $seStepPos;
|
||||
} else {
|
||||
$modPos = 'DOWN';
|
||||
$newPos = $seStepPos;
|
||||
$iniPos = $seStepPos;
|
||||
$finPos = $prStepPos-1;
|
||||
}
|
||||
|
||||
$range = range($iniPos, $finPos);
|
||||
foreach ($aStepTriggers as $dataStep) {
|
||||
if (($dataStep['st_type'] == $typeCompare) && (in_array($dataStep['st_position'], $range)) && ($dataStep['tri_uid'] != $triUid)) {
|
||||
$stepChangeIds[] = $dataStep['tri_uid'];
|
||||
$stepChangePos[] = $dataStep['st_position'];
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($stepChangeIds as $key => $value) {
|
||||
if ($modPos == 'UP') {
|
||||
$tempPos = ((int)$stepChangePos[$key])-1;
|
||||
$this->changePosStep($stepUid, $tasUid, $value, $type, $tempPos);
|
||||
} else {
|
||||
$tempPos = ((int)$stepChangePos[$key])+1;
|
||||
$this->changePosStep($stepUid, $tasUid, $value, $type, $tempPos);
|
||||
}
|
||||
}
|
||||
$this->changePosStep($stepUid, $tasUid, $triUid, $type, $newPos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate Process Uid
|
||||
* @var string $pro_uid. Uid for process
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function changePosStep ($stepUid, $tasUid, $triUid, $type, $pos)
|
||||
{
|
||||
$data = array(
|
||||
'STEP_UID' => $stepUid,
|
||||
'TAS_UID' => $tasUid,
|
||||
'TRI_UID' => $triUid,
|
||||
'ST_TYPE' => $type,
|
||||
'ST_POSITION' => $pos
|
||||
);
|
||||
$StepTrigger = new \StepTrigger();
|
||||
$StepTrigger->update($data);
|
||||
}
|
||||
}
|
||||
|
||||
151
workflow/engine/src/ProcessMaker/BusinessModel/Subprocess.php
Normal file
151
workflow/engine/src/ProcessMaker/BusinessModel/Subprocess.php
Normal file
@@ -0,0 +1,151 @@
|
||||
<?php
|
||||
namespace ProcessMaker\BusinessModel;
|
||||
|
||||
use \G;
|
||||
use \SubProcessPeer;
|
||||
|
||||
class Subprocess
|
||||
{
|
||||
/**
|
||||
* Get SubProcess in Process
|
||||
*
|
||||
* return object
|
||||
*/
|
||||
public function getSubprocesss($pro_uid, $tas_uid)
|
||||
{
|
||||
try {
|
||||
$pro_uid = $this->validateProUid($pro_uid);
|
||||
$tas_uid = $this->validateTasUid($tas_uid);
|
||||
|
||||
$oCriteria = new \Criteria('workflow');
|
||||
$del = \DBAdapter::getStringDelimiter();
|
||||
$oCriteria->add(SubProcessPeer::PRO_PARENT, $pro_uid);
|
||||
$oCriteria->add(SubProcessPeer::TAS_PARENT, $tas_uid);
|
||||
|
||||
$oCriteria->addAsColumn('CON_VALUE', 'C1.CON_VALUE', 'CON_TITLE');
|
||||
$oCriteria->addAlias("C1", 'CONTENT');
|
||||
$tasTitleConds = array();
|
||||
$tasTitleConds[] = array(SubProcessPeer::TAS_PARENT, 'C1.CON_ID' );
|
||||
$tasTitleConds[] = array('C1.CON_CATEGORY', $del . 'TAS_TITLE' . $del );
|
||||
$tasTitleConds[] = array('C1.CON_LANG', $del . SYS_LANG . $del );
|
||||
$oCriteria->addJoinMC($tasTitleConds, \Criteria::LEFT_JOIN);
|
||||
|
||||
$oDataset = SubProcessPeer::doSelectRS($oCriteria);
|
||||
$oDataset->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
$oDataset->next();
|
||||
$aRow = $oDataset->getRow();
|
||||
$aRow = array_change_key_case($aRow, CASE_LOWER);
|
||||
|
||||
$response['spr_uid'] = $aRow['sp_uid'];
|
||||
$response['spr_pro_parent'] = $aRow['pro_parent'];
|
||||
$response['spr_tas_parent'] = $aRow['tas_parent'];
|
||||
$response['spr_pro'] = $aRow['pro_uid'];
|
||||
$response['spr_tas'] = $aRow['tas_uid'];
|
||||
$response['spr_name'] = $aRow['con_value'];
|
||||
$response['spr_synchronous'] = $aRow['sp_synchronous'];
|
||||
$response['spr_variables_out'] = unserialize($aRow['sp_variables_out']);
|
||||
if ((int)$response['spr_synchronous'] === 1) {
|
||||
$response['spr_variables_in'] = unserialize($aRow['sp_variables_in']);
|
||||
}
|
||||
return $response;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Put SubProcess in Process
|
||||
* @var string $pro_uid. Uid for Process
|
||||
* @var string $spr_uid. Uid for SubProcess
|
||||
* @var array $spr_data. Data for SubProcess
|
||||
*
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function putSubprocesss($pro_uid, $tas_uid, $spr_data)
|
||||
{
|
||||
$pro_uid = $this->validateProUid($pro_uid);
|
||||
$tas_uid = $this->validateTasUid($tas_uid);
|
||||
if (empty($spr_data)) {
|
||||
throw (new \Exception("The request data is empty."));
|
||||
}
|
||||
if (isset($spr_data['spr_pro'])) {
|
||||
$spr_data['spr_pro'] = $this->validateProUid($spr_data['spr_pro']);
|
||||
}
|
||||
if (isset($spr_data['spr_tas'])) {
|
||||
$spr_data['spr_tas'] = $this->validateTasUid($spr_data['spr_tas']);
|
||||
}
|
||||
|
||||
$dataTemp = $this->getSubprocesss($pro_uid, $tas_uid);
|
||||
$spr_data = array_merge($dataTemp, $spr_data);
|
||||
$spr_data['spr_variables_in'] = (isset($spr_data['spr_variables_in'])) ? $spr_data['spr_variables_in'] : array();
|
||||
|
||||
$oSubProcess = new \SubProcess();
|
||||
$aData = array (
|
||||
'SP_UID' => $spr_data['spr_uid'],
|
||||
'PRO_UID' => $spr_data['spr_pro'],
|
||||
'TAS_UID' => $spr_data['spr_tas'],
|
||||
'PRO_PARENT' => $pro_uid,
|
||||
'TAS_PARENT' => $tas_uid,
|
||||
'SP_TYPE' => 'SIMPLE',
|
||||
'SP_SYNCHRONOUS' => (int)$spr_data['spr_synchronous'],
|
||||
'SP_SYNCHRONOUS_TYPE' => 'ALL',
|
||||
'SP_SYNCHRONOUS_WAIT' => 0,
|
||||
'SP_VARIABLES_OUT' => serialize( $spr_data['spr_variables_out'] ),
|
||||
'SP_VARIABLES_IN' => serialize( $spr_data['spr_variables_in'] ),
|
||||
'SP_GRID_IN' => ''
|
||||
);
|
||||
$oSubProcess->update( $aData );
|
||||
|
||||
$lang = defined( 'SYS_LANG' ) ? SYS_LANG : 'en';
|
||||
\Content::addContent( 'TAS_TITLE', '', $tas_uid, $lang, $spr_data['spr_name']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate Process Uid
|
||||
* @var string $pro_uid. Uid for process
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function validateProUid ($pro_uid)
|
||||
{
|
||||
$pro_uid = trim($pro_uid);
|
||||
if ($pro_uid == '') {
|
||||
throw (new \Exception("The project with prj_uid: '', does not exist."));
|
||||
}
|
||||
$oProcess = new \Process();
|
||||
if (!($oProcess->processExists($pro_uid))) {
|
||||
throw (new \Exception("The project with prj_uid: '$pro_uid', does not exist."));
|
||||
}
|
||||
return $pro_uid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate Task Uid
|
||||
* @var string $tas_uid. Uid for task
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function validateTasUid($tas_uid)
|
||||
{
|
||||
$tas_uid = trim($tas_uid);
|
||||
if ($tas_uid == '') {
|
||||
throw (new \Exception("The task with tas_uid: '', does not exist."));
|
||||
}
|
||||
$oTask = new \Task();
|
||||
if (!($oTask->taskExists($tas_uid))) {
|
||||
throw (new \Exception("The task with tas_uid: '$tas_uid', does not exist."));
|
||||
}
|
||||
return $tas_uid;
|
||||
}
|
||||
}
|
||||
|
||||
1112
workflow/engine/src/ProcessMaker/BusinessModel/Table.php
Normal file
1112
workflow/engine/src/ProcessMaker/BusinessModel/Table.php
Normal file
File diff suppressed because it is too large
Load Diff
2190
workflow/engine/src/ProcessMaker/BusinessModel/Task.php
Normal file
2190
workflow/engine/src/ProcessMaker/BusinessModel/Task.php
Normal file
File diff suppressed because it is too large
Load Diff
300
workflow/engine/src/ProcessMaker/BusinessModel/Trigger.php
Normal file
300
workflow/engine/src/ProcessMaker/BusinessModel/Trigger.php
Normal file
@@ -0,0 +1,300 @@
|
||||
<?php
|
||||
namespace ProcessMaker\BusinessModel;
|
||||
|
||||
class Trigger
|
||||
{
|
||||
/**
|
||||
* Get criteria for Trigger
|
||||
*
|
||||
* return object
|
||||
*/
|
||||
public function getTriggerCriteria()
|
||||
{
|
||||
try {
|
||||
$delimiter = \DBAdapter::getStringDelimiter();
|
||||
|
||||
$criteria = new \Criteria("workflow");
|
||||
|
||||
$criteria->addSelectColumn(\TriggersPeer::TRI_UID);
|
||||
$criteria->addAsColumn("TRI_TITLE", "CT.CON_VALUE");
|
||||
$criteria->addAsColumn("TRI_DESCRIPTION", "CD.CON_VALUE");
|
||||
$criteria->addSelectColumn(\TriggersPeer::TRI_TYPE);
|
||||
$criteria->addSelectColumn(\TriggersPeer::TRI_WEBBOT);
|
||||
$criteria->addSelectColumn(\TriggersPeer::TRI_PARAM);
|
||||
|
||||
$criteria->addAlias("CT", \ContentPeer::TABLE_NAME);
|
||||
$criteria->addAlias("CD", \ContentPeer::TABLE_NAME);
|
||||
|
||||
$arrayCondition = array();
|
||||
$arrayCondition[] = array(\TriggersPeer::TRI_UID, "CT.CON_ID", \Criteria::EQUAL);
|
||||
$arrayCondition[] = array("CT.CON_CATEGORY", $delimiter . "TRI_TITLE" . $delimiter, \Criteria::EQUAL);
|
||||
$arrayCondition[] = array("CT.CON_LANG", $delimiter . SYS_LANG . $delimiter, \Criteria::EQUAL);
|
||||
$criteria->addJoinMC($arrayCondition, \Criteria::LEFT_JOIN);
|
||||
|
||||
$arrayCondition = array();
|
||||
$arrayCondition[] = array(\TriggersPeer::TRI_UID, "CD.CON_ID", \Criteria::EQUAL);
|
||||
$arrayCondition[] = array("CD.CON_CATEGORY", $delimiter . "TRI_DESCRIPTION" . $delimiter, \Criteria::EQUAL);
|
||||
$arrayCondition[] = array("CD.CON_LANG", $delimiter . SYS_LANG . $delimiter, \Criteria::EQUAL);
|
||||
$criteria->addJoinMC($arrayCondition, \Criteria::LEFT_JOIN);
|
||||
|
||||
return $criteria;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* List of Triggers in process
|
||||
* @var string $sProcessUID. Uid for Process
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getTriggers($sProcessUID = '')
|
||||
{
|
||||
$criteria = $this->getTriggerCriteria();
|
||||
|
||||
$criteria->add(\TriggersPeer::PRO_UID, $sProcessUID);
|
||||
$criteria->addAscendingOrderByColumn('TRI_TITLE');
|
||||
|
||||
$oDataset = \TriggersPeer::doSelectRS($criteria);
|
||||
$oDataset->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
|
||||
$oDataset->next();
|
||||
$triggersArray = array();
|
||||
//$triggersArray[] = array('TRI_UID' => 'char', 'PRO_UID' => 'char', 'TRI_TITLE' => 'char', 'TRI_DESCRIPTION' => 'char');
|
||||
while ($aRow = $oDataset->getRow()) {
|
||||
if (($aRow['TRI_TITLE'] == null) || ($aRow['TRI_TITLE'] == "")) {
|
||||
// There is no transaltion for this Trigger name, try to get/regenerate the label
|
||||
$triggerObj = $this->getDataTrigger($aRow['TRI_UID']);
|
||||
$aRow['TRI_TITLE'] = $triggerObj['tri_title'];
|
||||
$aRow['TRI_DESCRIPTION'] = $triggerObj['tri_description'];
|
||||
} else {
|
||||
if ($aRow['TRI_PARAM'] != '' && $aRow['TRI_PARAM'] != 'PRIVATE') {
|
||||
$aRow['TRI_PARAM'] = unserialize($aRow['TRI_PARAM']);
|
||||
$aRow['TRI_PARAM'] = \G::json_encode($aRow['TRI_PARAM']);
|
||||
}
|
||||
}
|
||||
$triggersArray[] = array_change_key_case($aRow, CASE_LOWER);
|
||||
$oDataset->next();
|
||||
}
|
||||
return $triggersArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data for TriggerUid
|
||||
* @var string $sTriggerUID. Uid for Trigger
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDataTrigger($sTriggerUID = '')
|
||||
{
|
||||
$triggerO = new \Triggers();
|
||||
$triggerArray = $triggerO->load($sTriggerUID);
|
||||
if (isset($triggerArray['PRO_UID'])) {
|
||||
unset($triggerArray['PRO_UID']);
|
||||
}
|
||||
if ($triggerArray['TRI_PARAM'] != '' && $triggerArray['TRI_PARAM'] != 'PRIVATE') {
|
||||
$triggerArray['TRI_PARAM'] = unserialize($triggerArray['TRI_PARAM']);
|
||||
$triggerArray['TRI_PARAM'] = \G::json_encode($triggerArray['TRI_PARAM']);
|
||||
}
|
||||
$triggerArray = array_change_key_case($triggerArray, CASE_LOWER);
|
||||
return $triggerArray;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete Trigger
|
||||
* @var string $sTriggerUID. Uid for Trigger
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteTrigger($sTriggerUID = '')
|
||||
{
|
||||
$oTrigger = new \Triggers();
|
||||
$oTrigger->load( $sTriggerUID );
|
||||
$res = $oTrigger->verifyDependecies($sTriggerUID);
|
||||
$messageEnd = '';
|
||||
if ($res->code != 0) {
|
||||
foreach ($res->dependencies as $Object => $aDeps) {
|
||||
$nDeps = count( $aDeps );
|
||||
$message = str_replace( '{N}', $nDeps, \G::LoadTranslation( 'ID_TRIGGERS_VALIDATION_ERR2' ) );
|
||||
$message = str_replace( '{Object}', $Object, $message );
|
||||
$messageEnd .= $message . "\n";
|
||||
foreach ($aDeps as $dep) {
|
||||
if (substr( $Object, - 1 ) == 's') {
|
||||
$Object = substr( $Object, 0, strlen( $Object ) - 1 );
|
||||
}
|
||||
$message = str_replace( '{Object}', $Object, \G::LoadTranslation( 'ID_TRIGGERS_VALIDATION_ERR3' ) );
|
||||
$message = str_replace( '{Description}', '"' . $dep['DESCRIPTION'] . '"', $message );
|
||||
$messageEnd .= $message . "\n";
|
||||
}
|
||||
$messageEnd .= "\n";
|
||||
}
|
||||
throw new \Exception($messageEnd);
|
||||
}
|
||||
|
||||
$oTrigger->remove( $sTriggerUID );
|
||||
$oStepTrigger = new \StepTrigger();
|
||||
$oStepTrigger->removeTrigger( $sTriggerUID );
|
||||
}
|
||||
|
||||
/**
|
||||
* Save Data for Trigger
|
||||
* @var string $sProcessUID. Uid for Process
|
||||
* @var string $dataTrigger. Data for Trigger
|
||||
* @var string $create. Create o Update Trigger
|
||||
* @var string $sTriggerUid. Uid for Trigger
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function saveTrigger($sProcessUID = '', $dataTrigger = array(), $create = false, $sTriggerUid = '')
|
||||
{
|
||||
if ( ($sProcessUID == '') || (count($dataTrigger) == 0) ) {
|
||||
return false;
|
||||
}
|
||||
$dataTrigger = array_change_key_case($dataTrigger, CASE_UPPER);
|
||||
|
||||
if ( $create && (isset($dataTrigger['TRI_UID'])) ) {
|
||||
unset($dataTrigger['TRI_UID']);
|
||||
}
|
||||
|
||||
$dataTrigger= (array)$dataTrigger;
|
||||
$dataTrigger['TRI_TYPE'] = 'SCRIPT';
|
||||
|
||||
if (isset($dataTrigger['TRI_TITLE'])) {
|
||||
if (!$this->verifyNameTrigger($sProcessUID, $dataTrigger['TRI_TITLE'], $sTriggerUid)) {
|
||||
throw new \Exception('A trigger with the same name already exists in this process');
|
||||
}
|
||||
}
|
||||
|
||||
$dataTrigger['PRO_UID'] = $sProcessUID;
|
||||
$oTrigger = new \Triggers();
|
||||
if ($create) {
|
||||
$oTrigger->create( $dataTrigger );
|
||||
$dataTrigger['TRI_UID'] = $oTrigger->getTriUid();
|
||||
}
|
||||
|
||||
$oTrigger->update( $dataTrigger );
|
||||
if ($create) {
|
||||
$dataResp = $oTrigger->load( $dataTrigger['TRI_UID'] );
|
||||
$dataResp = array_change_key_case($dataResp, CASE_LOWER);
|
||||
if (isset($dataResp['pro_uid'])) {
|
||||
unset($dataResp['pro_uid']);
|
||||
}
|
||||
return $dataResp;
|
||||
}
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify name for trigger in process
|
||||
* @var string $sProcessUID. Uid for Process
|
||||
* @var string $sTriggerName. Name for Trigger
|
||||
* @var string $sTriggerUid. Uid for Trigger
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function verifyNameTrigger($sProcessUID, $sTriggerName, $sTriggerUid = '')
|
||||
{
|
||||
$oCriteria = new \Criteria("workflow");
|
||||
$oCriteria->addSelectColumn( \TriggersPeer::TRI_UID );
|
||||
$oCriteria->add( \TriggersPeer::PRO_UID, $sProcessUID );
|
||||
if ($sTriggerUid != '') {
|
||||
$oCriteria->add( \TriggersPeer::TRI_UID, $sTriggerUid, \Criteria::NOT_EQUAL);
|
||||
}
|
||||
$oDataset = \TriggersPeer::doSelectRS( $oCriteria );
|
||||
$oDataset->setFetchmode( \ResultSet::FETCHMODE_ASSOC );
|
||||
while ($oDataset->next()) {
|
||||
$aRow = $oDataset->getRow();
|
||||
|
||||
$oCriteria1 = new \Criteria( 'workflow' );
|
||||
$oCriteria1->addSelectColumn( 'COUNT(*) AS TRIGGERS' );
|
||||
$oCriteria1->add( \ContentPeer::CON_CATEGORY, 'TRI_TITLE' );
|
||||
$oCriteria1->add( \ContentPeer::CON_ID, $aRow['TRI_UID'] );
|
||||
$oCriteria1->add( \ContentPeer::CON_VALUE, $sTriggerName );
|
||||
$oCriteria1->add( \ContentPeer::CON_LANG, SYS_LANG );
|
||||
$oDataset1 = \ContentPeer::doSelectRS( $oCriteria1 );
|
||||
$oDataset1->setFetchmode( \ResultSet::FETCHMODE_ASSOC );
|
||||
$oDataset1->next();
|
||||
$aRow1 = $oDataset1->getRow();
|
||||
|
||||
if ($aRow1['TRIGGERS']) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify if doesn't exists the Trigger in table TRIGGERS
|
||||
*
|
||||
* @param string $triggerUid Unique id of Trigger
|
||||
* @param string $processUid Unique id of Process
|
||||
* @param string $fieldNameForException Field name for the exception
|
||||
*
|
||||
* return void Throw exception if doesn't exists the Trigger in table TRIGGERS
|
||||
*/
|
||||
public function throwExceptionIfNotExistsTrigger($triggerUid, $processUid, $fieldNameForException)
|
||||
{
|
||||
try {
|
||||
$criteria = new \Criteria("workflow");
|
||||
|
||||
$criteria->addSelectColumn(\TriggersPeer::TRI_UID);
|
||||
|
||||
if ($processUid != "") {
|
||||
$criteria->add(\TriggersPeer::PRO_UID, $processUid, \Criteria::EQUAL);
|
||||
}
|
||||
|
||||
$criteria->add(\TriggersPeer::TRI_UID, $triggerUid, \Criteria::EQUAL);
|
||||
|
||||
$rsCriteria = \TriggersPeer::doSelectRS($criteria);
|
||||
|
||||
if (!$rsCriteria->next()) {
|
||||
$msg = str_replace(array("{0}", "{1}"), array($fieldNameForException, $triggerUid), "The trigger with {0}: {1}, does not exist");
|
||||
|
||||
throw (new \Exception($msg));
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify if exists the title of a Trigger
|
||||
*
|
||||
* @param string $processUid Unique id of Process
|
||||
* @param string $triggerTitle Title
|
||||
* @param string $fieldNameForException Field name for the exception
|
||||
* @param string $triggerUidExclude Unique id of Trigger to exclude
|
||||
*
|
||||
* return void Throw exception if exists the title of a Trigger
|
||||
*/
|
||||
public function throwExceptionIfExistsTitle($processUid, $triggerTitle, $fieldNameForException, $triggerUidExclude = "")
|
||||
{
|
||||
try {
|
||||
if (!$this->verifyNameTrigger($processUid, $triggerTitle, $triggerUidExclude)) {
|
||||
$msg = str_replace(array("{0}", "{1}"), array($fieldNameForException, $triggerTitle), "The trigger title with {0}: \"{1}\" already exists");
|
||||
|
||||
throw (new \Exception($msg));
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
964
workflow/engine/src/ProcessMaker/BusinessModel/TriggerWizard.php
Normal file
964
workflow/engine/src/ProcessMaker/BusinessModel/TriggerWizard.php
Normal file
@@ -0,0 +1,964 @@
|
||||
<?php
|
||||
namespace ProcessMaker\BusinessModel;
|
||||
|
||||
class TriggerWizard
|
||||
{
|
||||
private $arrayFieldDefinition = array(
|
||||
"TRI_UID" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "triggerUid"),
|
||||
|
||||
"TRI_TITLE" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "triggerTitle"),
|
||||
"TRI_DESCRIPTION" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "triggerDescription"),
|
||||
"TRI_TYPE" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array("SCRIPT"), "fieldNameAux" => "triggerType"),
|
||||
"TRI_WEBBOT" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "triggerWebbot"),
|
||||
"TRI_PARAM" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "triggerParam")
|
||||
);
|
||||
|
||||
private $formatFieldNameInUppercase = true;
|
||||
|
||||
private $arrayFieldNameForException = array(
|
||||
"processUid" => "PRO_UID",
|
||||
"libraryName" => "LIB_NAME",
|
||||
"methodName" => "MTH_NAME",
|
||||
"triggerParams" => "TRI_PARAMS"
|
||||
);
|
||||
|
||||
private $library;
|
||||
|
||||
/**
|
||||
* Constructor of the class
|
||||
*
|
||||
* return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
try {
|
||||
foreach ($this->arrayFieldDefinition as $key => $value) {
|
||||
$this->arrayFieldNameForException[$value["fieldNameAux"]] = $key;
|
||||
}
|
||||
|
||||
//Library
|
||||
\G::LoadClass("triggerLibrary");
|
||||
|
||||
$this->library = \triggerLibrary::getSingleton();
|
||||
} 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($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 doesn't exists the name of the library
|
||||
*
|
||||
* @param string $libraryName Library name
|
||||
* @param string $libraryFieldNameForException Field name for the exception
|
||||
*
|
||||
* return void Throw exception if doesn't exists the name of the library
|
||||
*/
|
||||
public function throwExceptionIfNotExistsLibrary($libraryName, $libraryFieldNameForException)
|
||||
{
|
||||
try {
|
||||
$arrayLibrary = $this->library->getRegisteredClasses();
|
||||
|
||||
if (!isset($arrayLibrary[$this->libraryGetLibraryName($libraryName)])) {
|
||||
$msg = str_replace(array("{0}", "{1}"), array($libraryFieldNameForException, $libraryName), "The library with {0}: \"{1}\" does not exist");
|
||||
|
||||
throw (new \Exception($msg));
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify if doesn't exists the method in the library
|
||||
*
|
||||
* @param string $libraryName Library name
|
||||
* @param string $methodName Method name
|
||||
* @param string $libraryFieldNameForException Field name for the exception
|
||||
* @param string $methodFieldNameForException Field name for the exception
|
||||
*
|
||||
* return void Throw exception if doesn't exists the method in the library
|
||||
*/
|
||||
public function throwExceptionIfNotExistsMethodInLibrary($libraryName, $methodName, $libraryFieldNameForException, $methodFieldNameForException)
|
||||
{
|
||||
try {
|
||||
$this->throwExceptionIfNotExistsLibrary($libraryName, $libraryFieldNameForException);
|
||||
|
||||
$library = $this->library->getLibraryDefinition($this->libraryGetLibraryName($libraryName));
|
||||
|
||||
if (!isset($library->methods[$methodName])) {
|
||||
$msg = str_replace(array("{0}", "{1}"), array($methodFieldNameForException, $methodName), "The function with {0}: \"{1}\" does not exist in the library");
|
||||
|
||||
throw (new \Exception($msg));
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify if wizard is invalid for the trigger
|
||||
*
|
||||
* @param string $libraryName Library name
|
||||
* @param string $methodName Method name
|
||||
* @param string $triggerUid Unique id of Trigger
|
||||
* @param string $libraryFieldNameForException Field name for the exception
|
||||
* @param string $methodFieldNameForException Field name for the exception
|
||||
* @param string $triggerUidFieldNameForException Field name for the exception
|
||||
*
|
||||
* return void Throw exception if wizard is invalid for the trigger
|
||||
*/
|
||||
public function throwExceptionIfLibraryAndMethodIsInvalidForTrigger($libraryName, $methodName, $triggerUid, $libraryFieldNameForException, $methodFieldNameForException, $triggerUidFieldNameForException)
|
||||
{
|
||||
try {
|
||||
//Verify data
|
||||
$this->throwExceptionIfNotExistsMethodInLibrary($libraryName, $methodName, $libraryFieldNameForException, $methodFieldNameForException);
|
||||
|
||||
$trigger = new \ProcessMaker\BusinessModel\Trigger();
|
||||
|
||||
$trigger->throwExceptionIfNotExistsTrigger($triggerUid, "", $triggerUidFieldNameForException);
|
||||
|
||||
//Get data
|
||||
$trigger = new \Triggers();
|
||||
|
||||
$arrayTriggerData = $trigger->load($triggerUid);
|
||||
|
||||
$triggerParam = unserialize($arrayTriggerData["TRI_PARAM"]);
|
||||
|
||||
if ($arrayTriggerData["TRI_PARAM"] == "" || !isset($triggerParam["hash"])) {
|
||||
$msg = str_replace(array("{0}", "{1}"), array($triggerUidFieldNameForException, $triggerUid), "The trigger with {0}: {1}, has not been created with the wizard");
|
||||
|
||||
throw (new \Exception($msg));
|
||||
}
|
||||
|
||||
$arrayTriggerData["TRI_PARAM"] = $triggerParam;
|
||||
|
||||
if (md5($arrayTriggerData["TRI_WEBBOT"]) != $arrayTriggerData["TRI_PARAM"]["hash"]) {
|
||||
$msg = str_replace(array("{0}", "{1}"), array($triggerUidFieldNameForException, $triggerUid), "The trigger with {0}: {1}, has been modified manually. It is invalid for the wizard");
|
||||
|
||||
throw (new \Exception($msg));
|
||||
}
|
||||
|
||||
$triggerParamLibraryName = (preg_match("/^class\.?(.*)\.pmFunctions\.php$/", $arrayTriggerData["TRI_PARAM"]["params"]["LIBRARY_CLASS"], $arrayMatch))? ((isset($arrayMatch[1]) && $arrayMatch[1] != "")? $arrayMatch[1] : "pmFunctions") : $arrayTriggerData["TRI_PARAM"]["params"]["LIBRARY_CLASS"];
|
||||
$triggerParamMethodName = $arrayTriggerData["TRI_PARAM"]["params"]["PMFUNTION_NAME"];
|
||||
|
||||
if ($libraryName != $triggerParamLibraryName || $methodName != $triggerParamMethodName) {
|
||||
$msg = str_replace(array("{0}", "{1}", "{2}", "{3}"), array($libraryName, $methodName, $triggerUidFieldNameForException, $triggerUid), "The wizard with the library \"{0}\" and function \"{1}\", is invalid for the trigger with {2}: {3}");
|
||||
|
||||
throw (new \Exception($msg));
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate TRI_PARAMS data
|
||||
*
|
||||
* @param string $libraryName Library name
|
||||
* @param string $methodName Method name
|
||||
* @param array $arrayData Data
|
||||
* @param string $libraryFieldNameForException Field name for the exception
|
||||
* @param string $methodFieldNameForException Field name for the exception
|
||||
* @param string $fieldNameForException Field name for the exception
|
||||
*
|
||||
* return array Return array. Throw exception otherwise, if TRI_PARAMS data has an invalid value
|
||||
*/
|
||||
public function throwExceptionIfDataNotMetTriggerParamsDefinition($libraryName, $methodName, $arrayData, $libraryFieldNameForException, $methodFieldNameForException, $fieldNameForException)
|
||||
{
|
||||
try {
|
||||
$arrayData = array_change_key_case($arrayData, CASE_UPPER);
|
||||
|
||||
$arrayParamData = array();
|
||||
|
||||
//Verify data
|
||||
$this->throwExceptionIfNotExistsMethodInLibrary($libraryName, $methodName, $libraryFieldNameForException, $methodFieldNameForException);
|
||||
|
||||
//Set variables
|
||||
$nInputParam = count($this->methodGetInputParams($libraryName, $methodName));
|
||||
$nOutputParam = count($this->methodGetOutputParams($libraryName, $methodName));
|
||||
|
||||
if ($nInputParam > 0 || $nOutputParam > 0) {
|
||||
if (!isset($arrayData["TRI_PARAMS"])) {
|
||||
throw (new \Exception(str_replace(array("{0}"), array($fieldNameForException), "The \"{0}\" attribute is not defined")));
|
||||
}
|
||||
|
||||
if (!is_array($arrayData["TRI_PARAMS"])) {
|
||||
throw (new \Exception(str_replace(array("{0}"), array($fieldNameForException), "The \"{0}\" attribute is not array")));
|
||||
}
|
||||
|
||||
$arrayData["TRI_PARAMS"] = array_change_key_case($arrayData["TRI_PARAMS"], CASE_UPPER);
|
||||
|
||||
if ($nInputParam > 0) {
|
||||
if (!isset($arrayData["TRI_PARAMS"]["INPUT"])) {
|
||||
throw (new \Exception(str_replace(array("{0}"), array($this->getFieldNameByFormatFieldName($fieldNameForException . ".INPUT")), "The \"{0}\" attribute is not defined")));
|
||||
}
|
||||
|
||||
if (!is_array($arrayData["TRI_PARAMS"]["INPUT"])) {
|
||||
throw (new \Exception(str_replace(array("{0}"), array($this->getFieldNameByFormatFieldName($fieldNameForException . ".INPUT")), "The \"{0}\" attribute is not array")));
|
||||
}
|
||||
|
||||
$arrayParamData["input"] = $arrayData["TRI_PARAMS"]["INPUT"];
|
||||
}
|
||||
|
||||
if ($nOutputParam > 0) {
|
||||
if (!isset($arrayData["TRI_PARAMS"]["OUTPUT"])) {
|
||||
throw (new \Exception(str_replace(array("{0}"), array($this->getFieldNameByFormatFieldName($fieldNameForException . ".OUTPUT")), "The \"{0}\" attribute is not defined")));
|
||||
}
|
||||
|
||||
if (!is_array($arrayData["TRI_PARAMS"]["OUTPUT"])) {
|
||||
throw (new \Exception(str_replace(array("{0}"), array($this->getFieldNameByFormatFieldName($fieldNameForException . ".OUTPUT")), "The \"{0}\" attribute is not array")));
|
||||
}
|
||||
|
||||
$arrayParamData["output"] = $arrayData["TRI_PARAMS"]["OUTPUT"];
|
||||
}
|
||||
|
||||
$this->throwExceptionIfDataNotMetParamDefinition($libraryName, $methodName, $arrayParamData, $libraryFieldNameForException, $methodFieldNameForException);
|
||||
}
|
||||
|
||||
return $arrayParamData;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate data by parameter definition
|
||||
*
|
||||
* @param string $libraryName Library name
|
||||
* @param string $methodName Method name
|
||||
* @param array $arrayParamData Data
|
||||
* @param string $libraryFieldNameForException Field name for the exception
|
||||
* @param string $methodFieldNameForException Field name for the exception
|
||||
*
|
||||
* return void Throw exception if data has an invalid value
|
||||
*/
|
||||
public function throwExceptionIfDataNotMetParamDefinition($libraryName, $methodName, $arrayParamData, $libraryFieldNameForException, $methodFieldNameForException)
|
||||
{
|
||||
try {
|
||||
//Verify data
|
||||
$this->throwExceptionIfNotExistsMethodInLibrary($libraryName, $methodName, $libraryFieldNameForException, $methodFieldNameForException);
|
||||
|
||||
//Set variables
|
||||
$arrayMethodInputParam = $this->methodGetInputParams($libraryName, $methodName);
|
||||
$arrayMethodOutputParam = $this->methodGetOutputParams($libraryName, $methodName);
|
||||
|
||||
foreach ($arrayMethodOutputParam as $key => $value) {
|
||||
$arrayMethodOutputParam[$key]["type"] = "string";
|
||||
}
|
||||
|
||||
$arrayVerify = array(
|
||||
array("paramDefinition" => $arrayMethodInputParam, "paramData" => (isset($arrayParamData["input"]))? $arrayParamData["input"] : array()),
|
||||
array("paramDefinition" => $arrayMethodOutputParam, "paramData" => (isset($arrayParamData["output"]))? $arrayParamData["output"] : array())
|
||||
);
|
||||
|
||||
$process = new \ProcessMaker\BusinessModel\Process();
|
||||
|
||||
foreach ($arrayVerify as $key1 => $value1) {
|
||||
if (count($value1["paramDefinition"]) > 0) {
|
||||
$arrayParamDefinition = array();
|
||||
$arrayParamNameForException = array();
|
||||
|
||||
foreach ($value1["paramDefinition"] as $key2 => $value2) {
|
||||
$arrayParamDefinition[$value2["name"]] = array("type" => $value2["type"], "required" => $value2["required"], "empty" => !$value2["required"], "defaultValues" => array(), "fieldNameAux" => $value2["name"]);
|
||||
$arrayParamNameForException[$value2["name"]] = $value2["name"];
|
||||
}
|
||||
|
||||
$process->throwExceptionIfDataNotMetFieldDefinition($value1["paramData"], $arrayParamDefinition, $arrayParamNameForException, true);
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the filename of the library
|
||||
*
|
||||
* @param string $libraryName Library name
|
||||
*
|
||||
* return string Return the filename of the library
|
||||
*/
|
||||
public function libraryGetLibraryName($libraryName)
|
||||
{
|
||||
try {
|
||||
if (!preg_match("/\.pmFunctions\.php$/", $libraryName)) {
|
||||
$libraryName = ($libraryName != "pmFunctions")? $libraryName . ".pmFunctions" : $libraryName;
|
||||
$libraryName = "class." . $libraryName . ".php";
|
||||
}
|
||||
|
||||
return $libraryName;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all input parameters of a method
|
||||
*
|
||||
* @param string $libraryName Library name
|
||||
* @param string $methodName Method name
|
||||
*
|
||||
* return array Return an array with all input parameters of a method
|
||||
*/
|
||||
public function methodGetInputParams($libraryName, $methodName)
|
||||
{
|
||||
try {
|
||||
$arrayParam = array();
|
||||
|
||||
//Verify data
|
||||
$this->throwExceptionIfNotExistsMethodInLibrary($libraryName, $methodName, $this->arrayFieldNameForException["libraryName"], $this->arrayFieldNameForException["methodName"]);
|
||||
|
||||
//Get data
|
||||
$library = $this->library->getLibraryDefinition($this->libraryGetLibraryName($libraryName));
|
||||
$method = $library->methods[$methodName];
|
||||
|
||||
$arrayParameter = array_keys($method->params);
|
||||
|
||||
foreach ($arrayParameter as $key => $value) {
|
||||
$strParam = $value;
|
||||
|
||||
if ($strParam != "") {
|
||||
$arrayp = explode("|", $strParam);
|
||||
|
||||
//Get param
|
||||
$arrayTypeAndMaxLength = array();
|
||||
|
||||
if (preg_match("/^\s*(.+)\s*[\{\[\(]\s*(\d+)\s*[\)\]\}].*$/", $arrayp[0], $arrayMatch)) {
|
||||
$arrayTypeAndMaxLength = array("type" => $arrayMatch[1], "maxLength" => (int)($arrayMatch[2]));
|
||||
} else {
|
||||
$arrayTypeAndMaxLength = array("type" => trim($arrayp[0]));
|
||||
}
|
||||
|
||||
$arrayNameAndDefaultValue = array();
|
||||
|
||||
$arrayNameAndDefaultValue["name"] = "";
|
||||
|
||||
if (preg_match("/^\s*\\\$(\w+)(.*)$/", $arrayp[1], $arrayMatch)) {
|
||||
$arrayNameAndDefaultValue["name"] = $arrayMatch[1];
|
||||
|
||||
$arrayp[1] = $arrayMatch[2];
|
||||
}
|
||||
|
||||
if (preg_match("/^\s*=\s*(.*)$/", $arrayp[1], $arrayMatch)) {
|
||||
$arrayNameAndDefaultValue["defaultValue"] = trim(trim($arrayMatch[1]), "\"'");
|
||||
}
|
||||
|
||||
//Set param
|
||||
$arrayData = array(
|
||||
"name" => $arrayNameAndDefaultValue["name"],
|
||||
"type" => $arrayTypeAndMaxLength["type"],
|
||||
"label" => (isset($arrayp[2]))? trim($arrayp[2]) : $arrayNameAndDefaultValue["name"],
|
||||
"description" => (isset($arrayp[3]))? trim($arrayp[3]) : "",
|
||||
"required" => !isset($arrayNameAndDefaultValue["defaultValue"])
|
||||
);
|
||||
|
||||
if (isset($arrayNameAndDefaultValue["defaultValue"])) {
|
||||
$arrayData["default_value"] = $arrayNameAndDefaultValue["defaultValue"];
|
||||
}
|
||||
|
||||
if (isset($arrayTypeAndMaxLength["maxLength"])) {
|
||||
$arrayData["max_length"] = $arrayTypeAndMaxLength["maxLength"];
|
||||
}
|
||||
|
||||
$arrayParam[] = $arrayData;
|
||||
}
|
||||
}
|
||||
|
||||
//Return
|
||||
return $arrayParam;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all output parameters of a method
|
||||
*
|
||||
* @param string $libraryName Library name
|
||||
* @param string $methodName Method name
|
||||
*
|
||||
* return array Return an array with all output parameters of a method
|
||||
*/
|
||||
public function methodGetOutputParams($libraryName, $methodName)
|
||||
{
|
||||
try {
|
||||
$arrayParam = array();
|
||||
|
||||
//Verify data
|
||||
$this->throwExceptionIfNotExistsMethodInLibrary($libraryName, $methodName, $this->arrayFieldNameForException["libraryName"], $this->arrayFieldNameForException["methodName"]);
|
||||
|
||||
//Get data
|
||||
$library = $this->library->getLibraryDefinition($this->libraryGetLibraryName($libraryName));
|
||||
$method = $library->methods[$methodName];
|
||||
|
||||
if (isset($method->info["return"]) && $method->info["return"] != "") {
|
||||
$strParam = $method->info["return"];
|
||||
|
||||
$arrayp = explode("|", $strParam);
|
||||
|
||||
if (isset($arrayp[0]) && isset($arrayp[1]) && trim(strtoupper($arrayp[0])) != strtoupper(\G::LoadTranslation("ID_NONE"))) {
|
||||
$description = "";
|
||||
|
||||
if (isset($arrayp[3])) {
|
||||
$description = (trim(strtoupper($arrayp[3])) == strtoupper(\G::LoadTranslation("ID_NONE")))? \G::LoadTranslation("ID_NOT_REQUIRED") : trim($arrayp[3]);
|
||||
} else {
|
||||
$description = $strParam;
|
||||
}
|
||||
|
||||
//Set param
|
||||
$arrayParam[] = array(
|
||||
"name" => "tri_answer",
|
||||
"type" => trim($arrayp[0]),
|
||||
"label" => \G::LoadTranslation("ID_TRIGGER_RETURN_LABEL"),
|
||||
"description" => $description,
|
||||
"required" => isset($arrayp[1]) //(trim($arrayp[1]) != "")? true : false
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//Return
|
||||
return $arrayParam;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set values in Trigger fields (TRI_WEBBOT, TRI_PARAM)
|
||||
*
|
||||
* @param string $libraryName Library name
|
||||
* @param string $methodName Method name
|
||||
* @param string $triggerUid Unique id of Trigger
|
||||
* @param array $arrayParamData Data
|
||||
*
|
||||
* return void
|
||||
*/
|
||||
public function setData($libraryName, $methodName, $triggerUid, $arrayParamData)
|
||||
{
|
||||
try {
|
||||
//Verify data
|
||||
$this->throwExceptionIfNotExistsMethodInLibrary($libraryName, $methodName, $this->arrayFieldNameForException["libraryName"], $this->arrayFieldNameForException["methodName"]);
|
||||
|
||||
$trigger = new \ProcessMaker\BusinessModel\Trigger();
|
||||
|
||||
$trigger->throwExceptionIfNotExistsTrigger($triggerUid, "", $this->arrayFieldNameForException["triggerUid"]);
|
||||
|
||||
//Set variables
|
||||
$arrayMethodInputParam = $this->methodGetInputParams($libraryName, $methodName);
|
||||
$arrayMethodOutputParam = $this->methodGetOutputParams($libraryName, $methodName);
|
||||
|
||||
$arrayTriggerParam = array();
|
||||
$arrayScriptMethodParam = array();
|
||||
|
||||
$strParamsNamePhp = "";
|
||||
$strParamsType = "";
|
||||
$strParamsRequired = "";
|
||||
|
||||
//Set variables - Load Trigger
|
||||
$trigger = new \Triggers();
|
||||
|
||||
$arrayTriggerData = $trigger->load($triggerUid);
|
||||
|
||||
$arrayTriggerParam["TRI_UID"] = $triggerUid;
|
||||
$arrayTriggerParam["TRI_TITLE"] = $arrayTriggerData["TRI_TITLE"];
|
||||
$arrayTriggerParam["TRI_DESCRIPTION"] = $arrayTriggerData["TRI_DESCRIPTION"];
|
||||
$arrayTriggerParam["TRI_TYPE"] = $arrayTriggerData["TRI_TYPE"];
|
||||
$arrayTriggerParam["PRO_UID"] = $arrayTriggerData["PRO_UID"];
|
||||
|
||||
//Set variables - Input
|
||||
foreach ($arrayMethodInputParam as $key => $value) {
|
||||
$paramName = $value["name"];
|
||||
$paramType = $value["type"];
|
||||
$paramRequired = $value["required"];
|
||||
$paramDefaultValue = (isset($value["default_value"]))? $value["default_value"] : "";
|
||||
|
||||
//TRI_PARAM
|
||||
if ($paramType != "array") {
|
||||
$arrayTriggerParam[$paramName] = (isset($arrayParamData["input"][$paramName]))? $arrayParamData["input"][$paramName] : $paramDefaultValue;
|
||||
} else {
|
||||
if (isset($arrayParamData["input"][$paramName])) {
|
||||
if (is_array($arrayParamData["input"][$paramName])) {
|
||||
$strArrayElements = "";
|
||||
|
||||
foreach ($arrayParamData["input"][$paramName] as $key2 => $value2) {
|
||||
$strKey = (is_string($key2))? "\"" . $key2 . "\"" : $key2;
|
||||
$strValue = (is_string($value2))? "\"" . str_replace("\"", "\\\"", $value2) . "\"" : $value2;
|
||||
|
||||
$strArrayElements = $strArrayElements . (($strArrayElements != "")? ", " : "") . $strKey . " => " . $strValue;
|
||||
}
|
||||
|
||||
$arrayParamData["input"][$paramName] = "array(" . $strArrayElements . ")";
|
||||
}
|
||||
|
||||
$arrayTriggerParam[$paramName] = $arrayParamData["input"][$paramName];
|
||||
} else {
|
||||
$arrayTriggerParam[$paramName] = $paramDefaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
//Variables
|
||||
$strParamsNamePhp = $strParamsNamePhp . (($strParamsNamePhp != "")? "," : "") . "\$" . $paramName;
|
||||
$strParamsType = $strParamsType . (($strParamsType != "")? "," : "") . $paramType;
|
||||
|
||||
if ($paramRequired) {
|
||||
$strParamsRequired = $strParamsRequired . (($strParamsRequired != "")? "," : "") . $paramName;
|
||||
}
|
||||
|
||||
//Method parameters
|
||||
$paramValue = "\"" . $paramDefaultValue . "\"";
|
||||
|
||||
if (isset($arrayParamData["input"][$paramName])) {
|
||||
if (preg_match("/^.*@@.*$/", $arrayParamData["input"][$paramName])) {
|
||||
$paramValue = trim($arrayParamData["input"][$paramName]);
|
||||
} else {
|
||||
switch ($paramType) {
|
||||
case "int":
|
||||
case "integer":
|
||||
$paramValue = intval($arrayParamData["input"][$paramName]);
|
||||
break;
|
||||
case "float":
|
||||
case "real":
|
||||
case "double":
|
||||
$paramValue = floatval($arrayParamData["input"][$paramName]);
|
||||
break;
|
||||
case "bool":
|
||||
case "boolean":
|
||||
case "array":
|
||||
$paramValue = trim($arrayParamData["input"][$paramName]);
|
||||
break;
|
||||
case "string":
|
||||
$paramValue = "\"" . str_replace("\"", "\\\"", $arrayParamData["input"][$paramName]) . "\"";
|
||||
break;
|
||||
default:
|
||||
if (is_numeric($arrayParamData["input"][$paramName]) ||
|
||||
is_bool($arrayParamData["input"][$paramName]) ||
|
||||
preg_match("/^\s*array\s*\(.*\)\s*$/", $arrayParamData["input"][$paramName])
|
||||
) {
|
||||
$paramValue = trim($arrayParamData["input"][$paramName]);
|
||||
} else {
|
||||
$paramValue = "\"" . str_replace("\"", "\\\"", $arrayParamData["input"][$paramName]) . "\"";
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$arrayScriptMethodParam[] = $paramValue;
|
||||
}
|
||||
|
||||
//Set variables - Output
|
||||
$varReturn = "";
|
||||
|
||||
foreach ($arrayMethodOutputParam as $key => $value) {
|
||||
$paramName = $value["name"];
|
||||
$paramRequired = $value["required"];
|
||||
|
||||
if ($paramRequired && isset($arrayParamData["output"][$paramName]) && trim($arrayParamData["output"][$paramName]) != "") {
|
||||
$arrayTriggerParam[strtoupper($paramName)] = trim($arrayParamData["output"][$paramName]);
|
||||
|
||||
$strParamsRequired = $strParamsRequired . (($strParamsRequired != "")? "," : "") . strtoupper($paramName);
|
||||
|
||||
$varReturn = trim($arrayParamData["output"][$paramName]) . " = ";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//Set data
|
||||
$library = $this->library->getLibraryDefinition($this->libraryGetLibraryName($libraryName));
|
||||
$method = $library->methods[$methodName];
|
||||
|
||||
$strScript = "/*******************************************************";
|
||||
$strScript = $strScript . "\n" . " *";
|
||||
$strScript = $strScript . "\n" . " * Generated by ProcessMaker Trigger Wizard";
|
||||
$strScript = $strScript . "\n" . " * Library: " . trim($library->info["name"]);
|
||||
$strScript = $strScript . "\n" . " * Method: " . trim($method->info["label"]);
|
||||
$strScript = $strScript . "\n" . " * Date: " . date("Y-m-d H:i:s");
|
||||
$strScript = $strScript . "\n" . " *";
|
||||
$strScript = $strScript . "\n" . " * ProcessMaker " . date("Y");
|
||||
$strScript = $strScript . "\n" . " *";
|
||||
$strScript = $strScript . "\n" . " *******************************************************/";
|
||||
$strScript = $strScript . "\n";
|
||||
$strScript = $strScript . "\n" . $varReturn . $methodName . "(" . implode(", ", $arrayScriptMethodParam) . ");";
|
||||
|
||||
$arrayTriggerParam["TRI_WEBBOT"] = $strScript;
|
||||
|
||||
$arrayTriggerParam["__notValidateThisFields__"] = "";
|
||||
$arrayTriggerParam["DynaformRequiredFields"] = "[]";
|
||||
$arrayTriggerParam["PAGED_TABLE_ID"] = "";
|
||||
|
||||
$arrayTriggerParam["LIBRARY_NAME"] = trim($library->info["name"]);
|
||||
$arrayTriggerParam["LIBRARY_CLASS"] = $this->libraryGetLibraryName($libraryName);
|
||||
|
||||
$arrayTriggerParam["PMFUNTION_NAME"] = $methodName;
|
||||
$arrayTriggerParam["PMFUNTION_LABEL"] = trim($method->info["label"]);
|
||||
|
||||
$arrayTriggerParam["ALLFUNCTION"] = $strParamsNamePhp;
|
||||
$arrayTriggerParam["ALLFUNCTION_TYPE"] = $strParamsType;
|
||||
$arrayTriggerParam["FIELDS_REQUIRED"] = $strParamsRequired;
|
||||
|
||||
//Update
|
||||
$result = $trigger->update(array("TRI_UID" => $triggerUid, "TRI_WEBBOT" => $strScript, "TRI_PARAM" => serialize(array("hash" => md5($strScript), "params" => $arrayTriggerParam))));
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Trigger for a Process
|
||||
*
|
||||
* @param string $libraryName Library name
|
||||
* @param string $methodName Method name
|
||||
* @param string $processUid Unique id of Process
|
||||
* @param array $arrayData Data
|
||||
*
|
||||
* return array Return data of the new Trigger created
|
||||
*/
|
||||
public function create($libraryName, $methodName, $processUid, $arrayData)
|
||||
{
|
||||
try {
|
||||
$arrayData = array_change_key_case($arrayData, CASE_UPPER);
|
||||
|
||||
//Verify data
|
||||
$process = new \ProcessMaker\BusinessModel\Process();
|
||||
$trigger = new \ProcessMaker\BusinessModel\Trigger();
|
||||
|
||||
$this->throwExceptionIfNotExistsMethodInLibrary($libraryName, $methodName, $this->arrayFieldNameForException["libraryName"], $this->arrayFieldNameForException["methodName"]);
|
||||
|
||||
$process->throwExceptionIfNotExistsProcess($processUid, $this->arrayFieldNameForException["processUid"]);
|
||||
|
||||
$process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $this->arrayFieldDefinition, $this->arrayFieldNameForException, true);
|
||||
|
||||
$arrayParamData = $this->throwExceptionIfDataNotMetTriggerParamsDefinition($libraryName, $methodName, $arrayData, $this->arrayFieldNameForException["libraryName"], $this->arrayFieldNameForException["methodName"], $this->arrayFieldNameForException["triggerParams"]);
|
||||
|
||||
$trigger->throwExceptionIfExistsTitle($processUid, $arrayData["TRI_TITLE"], $this->arrayFieldNameForException["triggerTitle"]);
|
||||
|
||||
//TRI_PARAMS
|
||||
if (isset($arrayData["TRI_PARAMS"])) {
|
||||
$arrayData["TRI_PARAMS"] = array_change_key_case($arrayData["TRI_PARAMS"], CASE_UPPER);
|
||||
}
|
||||
|
||||
//Create
|
||||
$trigger = new \Triggers();
|
||||
|
||||
$arrayData["PRO_UID"] = $processUid;
|
||||
|
||||
$result = $trigger->create($arrayData);
|
||||
|
||||
$triggerUid = $trigger->getTriUid();
|
||||
|
||||
$this->setData($libraryName, $methodName, $triggerUid, $arrayParamData);
|
||||
|
||||
//Return
|
||||
unset($arrayData["PRO_UID"]);
|
||||
|
||||
$arrayData = array_merge(array("TRI_UID" => $triggerUid), $arrayData);
|
||||
|
||||
if (!$this->formatFieldNameInUppercase) {
|
||||
if (isset($arrayData["TRI_PARAMS"])) {
|
||||
$arrayData["TRI_PARAMS"] = array_change_key_case($arrayData["TRI_PARAMS"], CASE_LOWER);
|
||||
}
|
||||
|
||||
$arrayData = array_change_key_case($arrayData, CASE_LOWER);
|
||||
}
|
||||
|
||||
return $arrayData;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update Trigger
|
||||
*
|
||||
* @param string $libraryName Library name
|
||||
* @param string $methodName Method name
|
||||
* @param string $triggerUid Unique id of Trigger
|
||||
* @param array $arrayData Data
|
||||
*
|
||||
* return array Return data of the Trigger updated
|
||||
*/
|
||||
public function update($libraryName, $methodName, $triggerUid, $arrayData)
|
||||
{
|
||||
try {
|
||||
$arrayData = array_change_key_case($arrayData, CASE_UPPER);
|
||||
|
||||
//Verify data
|
||||
$this->throwExceptionIfLibraryAndMethodIsInvalidForTrigger($libraryName, $methodName, $triggerUid, $this->arrayFieldNameForException["libraryName"], $this->arrayFieldNameForException["methodName"], $this->arrayFieldNameForException["triggerUid"]);
|
||||
|
||||
//Load Trigger
|
||||
$trigger = new \Triggers();
|
||||
|
||||
$arrayTriggerData = $trigger->load($triggerUid);
|
||||
|
||||
$processUid = $arrayTriggerData["PRO_UID"];
|
||||
|
||||
//Verify data
|
||||
$process = new \ProcessMaker\BusinessModel\Process();
|
||||
$trigger = new \ProcessMaker\BusinessModel\Trigger();
|
||||
|
||||
$process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $this->arrayFieldDefinition, $this->arrayFieldNameForException, false);
|
||||
|
||||
if (isset($arrayData["TRI_PARAMS"])) {
|
||||
$arrayParamData = $this->throwExceptionIfDataNotMetTriggerParamsDefinition($libraryName, $methodName, $arrayData, $this->arrayFieldNameForException["libraryName"], $this->arrayFieldNameForException["methodName"], $this->arrayFieldNameForException["triggerParams"]);
|
||||
}
|
||||
|
||||
if (isset($arrayData["TRI_TITLE"])) {
|
||||
$trigger->throwExceptionIfExistsTitle($processUid, $arrayData["TRI_TITLE"], $this->arrayFieldNameForException["triggerTitle"], $triggerUid);
|
||||
}
|
||||
|
||||
//TRI_PARAMS
|
||||
if (isset($arrayData["TRI_PARAMS"])) {
|
||||
$arrayData["TRI_PARAMS"] = array_change_key_case($arrayData["TRI_PARAMS"], CASE_UPPER);
|
||||
}
|
||||
|
||||
//Update
|
||||
$trigger = new \Triggers();
|
||||
|
||||
$arrayData["TRI_UID"] = $triggerUid;
|
||||
|
||||
$result = $trigger->update($arrayData);
|
||||
|
||||
if (isset($arrayData["TRI_PARAMS"])) {
|
||||
$this->setData($libraryName, $methodName, $triggerUid, $arrayParamData);
|
||||
}
|
||||
|
||||
//Return
|
||||
unset($arrayData["TRI_UID"]);
|
||||
|
||||
if (!$this->formatFieldNameInUppercase) {
|
||||
if (isset($arrayData["TRI_PARAMS"])) {
|
||||
$arrayData["TRI_PARAMS"] = array_change_key_case($arrayData["TRI_PARAMS"], CASE_LOWER);
|
||||
}
|
||||
|
||||
$arrayData = array_change_key_case($arrayData, CASE_LOWER);
|
||||
}
|
||||
|
||||
return $arrayData;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Method of the Library
|
||||
*
|
||||
* @param string $libraryName Library name
|
||||
* @param string $methodName Method name
|
||||
*
|
||||
* return array Return an array with the Method of the Library
|
||||
*/
|
||||
public function getMethod($libraryName, $methodName)
|
||||
{
|
||||
try {
|
||||
$arrayMethod = array();
|
||||
|
||||
//Verify data
|
||||
$arrayMethodInputParam = $this->methodGetInputParams($libraryName, $methodName);
|
||||
$arrayMethodOutputParam = $this->methodGetOutputParams($libraryName, $methodName);
|
||||
|
||||
//Get data
|
||||
$library = $this->library->getLibraryDefinition($this->libraryGetLibraryName($libraryName));
|
||||
$method = $library->methods[$methodName];
|
||||
|
||||
$arrayMethod[$this->getFieldNameByFormatFieldName("FN_NAME")] = trim($method->info["name"]);
|
||||
$arrayMethod[$this->getFieldNameByFormatFieldName("FN_DESCRIPTION")] = trim(str_replace("*", "", implode("", $method->info["description"])));
|
||||
$arrayMethod[$this->getFieldNameByFormatFieldName("FN_LABEL")] = trim($method->info["label"]);
|
||||
$arrayMethod[$this->getFieldNameByFormatFieldName("FN_LINK")] = (isset($method->info["link"]) && trim($method->info["link"]) != "")? trim($method->info["link"]) : "";
|
||||
|
||||
if ($this->formatFieldNameInUppercase) {
|
||||
$arrayMethodInputParam = \G::array_change_key_case2($arrayMethodInputParam, CASE_UPPER);
|
||||
$arrayMethodOutputParam = \G::array_change_key_case2($arrayMethodOutputParam, CASE_UPPER);
|
||||
}
|
||||
|
||||
if (count($arrayMethodInputParam) > 0) {
|
||||
$arrayMethod[$this->getFieldNameByFormatFieldName("FN_PARAMS")][$this->getFieldNameByFormatFieldName("INPUT")] = $arrayMethodInputParam;
|
||||
}
|
||||
|
||||
if (count($arrayMethodOutputParam) > 0) {
|
||||
$arrayMethod[$this->getFieldNameByFormatFieldName("FN_PARAMS")][$this->getFieldNameByFormatFieldName("OUTPUT")] = $arrayMethodOutputParam;
|
||||
}
|
||||
|
||||
//Return
|
||||
return $arrayMethod;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Library
|
||||
*
|
||||
* @param string $libraryName Library name
|
||||
*
|
||||
* return array Return an array with the Library
|
||||
*/
|
||||
public function getLibrary($libraryName)
|
||||
{
|
||||
try {
|
||||
$arrayLibrary = array();
|
||||
|
||||
//Verify data
|
||||
$this->throwExceptionIfNotExistsLibrary($libraryName, $this->arrayFieldNameForException["libraryName"]);
|
||||
|
||||
//Get data
|
||||
$library = $this->library->getLibraryDefinition($this->libraryGetLibraryName($libraryName));
|
||||
|
||||
$arrayLibrary[$this->getFieldNameByFormatFieldName("LIB_NAME")] = $libraryName;
|
||||
$arrayLibrary[$this->getFieldNameByFormatFieldName("LIB_TITLE")] = trim($library->info["name"]);
|
||||
$arrayLibrary[$this->getFieldNameByFormatFieldName("LIB_DESCRIPTION")] = trim(str_replace("*", "", implode("", $library->info["description"])));
|
||||
$arrayLibrary[$this->getFieldNameByFormatFieldName("LIB_ICON")] = (isset($library->info["icon"]) && trim($library->info["icon"]) != "")? trim($library->info["icon"]) : "/images/browse.gif";
|
||||
$arrayLibrary[$this->getFieldNameByFormatFieldName("LIB_CLASS_NAME")] = trim($library->info["className"]);
|
||||
|
||||
$arrayMethod = array();
|
||||
|
||||
if (count($library->methods) > 0) {
|
||||
ksort($library->methods, SORT_STRING);
|
||||
|
||||
foreach ($library->methods as $key => $value) {
|
||||
$methodName = $key;
|
||||
|
||||
$arrayMethod[] = $this->getMethod($libraryName, $methodName);
|
||||
}
|
||||
}
|
||||
|
||||
$arrayLibrary[$this->getFieldNameByFormatFieldName("LIB_FUNCTIONS")] = $arrayMethod;
|
||||
|
||||
//Return
|
||||
return $arrayLibrary;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data of a Trigger
|
||||
*
|
||||
* @param string $libraryName Library name
|
||||
* @param string $methodName Method name
|
||||
* @param string $triggerUid Unique id of Trigger
|
||||
*
|
||||
* return array Return an array with data of a Trigger
|
||||
*/
|
||||
public function getTrigger($libraryName, $methodName, $triggerUid)
|
||||
{
|
||||
try {
|
||||
//Verify data
|
||||
$this->throwExceptionIfLibraryAndMethodIsInvalidForTrigger($libraryName, $methodName, $triggerUid, $this->arrayFieldNameForException["libraryName"], $this->arrayFieldNameForException["methodName"], $this->arrayFieldNameForException["triggerUid"]);
|
||||
|
||||
//Get data
|
||||
$trigger = new \Triggers();
|
||||
|
||||
$arrayTriggerData = $trigger->load($triggerUid);
|
||||
|
||||
$arrayTriggerData["TRI_PARAM"] = unserialize($arrayTriggerData["TRI_PARAM"]);
|
||||
|
||||
$arrayMethodInputParam = $this->methodGetInputParams($libraryName, $methodName);
|
||||
$arrayMethodOutputParam = $this->methodGetOutputParams($libraryName, $methodName);
|
||||
|
||||
//Params
|
||||
$arrayMethodInputParamValue = array();
|
||||
|
||||
foreach ($arrayMethodInputParam as $key => $value) {
|
||||
$paramName = $value["name"];
|
||||
$paramDefaultValue = (isset($value["default_value"]))? $value["default_value"] : "";
|
||||
|
||||
$arrayMethodInputParamValue[$paramName] = (isset($arrayTriggerData["TRI_PARAM"]["params"][$paramName]))? $arrayTriggerData["TRI_PARAM"]["params"][$paramName] : $paramDefaultValue;
|
||||
}
|
||||
|
||||
$arrayMethodOutputParamValue = array();
|
||||
|
||||
foreach ($arrayMethodOutputParam as $key => $value) {
|
||||
$paramName = $value["name"];
|
||||
$paramRequired = $value["required"];
|
||||
|
||||
if ($paramRequired) {
|
||||
if (isset($arrayTriggerData["TRI_PARAM"]["params"][strtolower($paramName)])) {
|
||||
$paramValue = trim($arrayTriggerData["TRI_PARAM"]["params"][strtolower($paramName)]);
|
||||
} else {
|
||||
if (isset($arrayTriggerData["TRI_PARAM"]["params"][strtoupper($paramName)])) {
|
||||
$paramValue = trim($arrayTriggerData["TRI_PARAM"]["params"][strtoupper($paramName)]);
|
||||
} else {
|
||||
$paramValue = "";
|
||||
}
|
||||
}
|
||||
|
||||
$arrayMethodOutputParamValue[$paramName] = $paramValue;
|
||||
}
|
||||
}
|
||||
|
||||
if (count($arrayMethodInputParamValue) > 0) {
|
||||
$arrayTriggerData[$this->getFieldNameByFormatFieldName("TRI_PARAMS")][$this->getFieldNameByFormatFieldName("INPUT")] = $arrayMethodInputParamValue;
|
||||
}
|
||||
|
||||
if (count($arrayMethodOutputParamValue) > 0) {
|
||||
$arrayTriggerData[$this->getFieldNameByFormatFieldName("TRI_PARAMS")][$this->getFieldNameByFormatFieldName("OUTPUT")] = $arrayMethodOutputParamValue;
|
||||
}
|
||||
|
||||
//Return
|
||||
unset($arrayTriggerData["PRO_UID"]);
|
||||
unset($arrayTriggerData["TRI_WEBBOT"]);
|
||||
unset($arrayTriggerData["TRI_PARAM"]);
|
||||
|
||||
if (!$this->formatFieldNameInUppercase) {
|
||||
$arrayTriggerData = array_change_key_case($arrayTriggerData, CASE_LOWER);
|
||||
}
|
||||
|
||||
return $arrayTriggerData;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
786
workflow/engine/src/ProcessMaker/BusinessModel/User.php
Normal file
786
workflow/engine/src/ProcessMaker/BusinessModel/User.php
Normal file
@@ -0,0 +1,786 @@
|
||||
<?php
|
||||
namespace ProcessMaker\BusinessModel;
|
||||
use \G;
|
||||
|
||||
class User
|
||||
{
|
||||
/**
|
||||
* Create User Uid
|
||||
*
|
||||
* @param array $arrayData Data
|
||||
*
|
||||
* return id
|
||||
*/
|
||||
public function createUser($aData)
|
||||
{
|
||||
require_once (PATH_RBAC_HOME . "engine" . PATH_SEP . "classes" . PATH_SEP . "model" . PATH_SEP . "RbacUsers.php");
|
||||
$this->userObj = new \RbacUsers();
|
||||
if (class_exists('PMPluginRegistry')) {
|
||||
$pluginRegistry = & \PMPluginRegistry::getSingleton();
|
||||
if ($pluginRegistry->existsTrigger(PM_BEFORE_CREATE_USER)) {
|
||||
try {
|
||||
$pluginRegistry->executeTriggers(PM_BEFORE_CREATE_USER, null);
|
||||
} catch(Exception $error) {
|
||||
throw new Exception($error->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
$oConnection = \Propel::getConnection(\RbacUsersPeer::DATABASE_NAME);
|
||||
try {
|
||||
$oRBACUsers = new \RbacUsers();
|
||||
do {
|
||||
$aData['USR_UID'] = \G::generateUniqueID();
|
||||
} while ($oRBACUsers->load($aData['USR_UID']));
|
||||
$oRBACUsers->fromArray($aData, \BasePeer::TYPE_FIELDNAME);
|
||||
$iResult = $oRBACUsers->save();
|
||||
return $aData['USR_UID'];
|
||||
} catch (Exception $oError) {
|
||||
$oConnection->rollback();
|
||||
throw($oError);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* to put role an user
|
||||
*
|
||||
* @access public
|
||||
* @param string $sUserUID
|
||||
* @param string $sRolCode
|
||||
* @return void
|
||||
*/
|
||||
public function assignRoleToUser ($sUserUID = '', $sRolCode = '')
|
||||
{
|
||||
require_once (PATH_RBAC_HOME . "engine" . PATH_SEP . "classes" . PATH_SEP . "model" . PATH_SEP . "Roles.php");
|
||||
require_once (PATH_RBAC_HOME . "engine" . PATH_SEP . "classes" . PATH_SEP . "model" . PATH_SEP . "UsersRoles.php");
|
||||
$this->usersRolesObj = new \UsersRoles();
|
||||
$this->rolesObj = new \Roles();
|
||||
$aRol = $this->rolesObj->loadByCode( $sRolCode );
|
||||
$this->usersRolesObj->create( $sUserUID, $aRol['ROL_UID'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* to test Password
|
||||
*
|
||||
* @access public
|
||||
* @param string $sPassword
|
||||
* @return array
|
||||
*/
|
||||
public function testPassword ($sPassword = '')
|
||||
{
|
||||
require_once (PATH_TRUNK . "workflow" . PATH_SEP . "engine" . PATH_SEP . "classes" . PATH_SEP . "model" . PATH_SEP . "UsersProperties.php");
|
||||
$oUserProperty = new \UsersProperties();
|
||||
$aFields = array();
|
||||
$dateNow = date('Y-m-d H:i:s');
|
||||
$aErrors = $oUserProperty->validatePassword($sPassword, $dateNow, $dateNow);
|
||||
if (!empty($aErrors)) {
|
||||
if (!defined('NO_DISPLAY_USERNAME')) {
|
||||
define('NO_DISPLAY_USERNAME', 1);
|
||||
}
|
||||
$aFields = array();
|
||||
$aFields['DESCRIPTION'] = \G::LoadTranslation('ID_POLICY_ALERT');
|
||||
foreach ($aErrors as $sError) {
|
||||
switch ($sError) {
|
||||
case 'ID_PPP_MINIMUM_LENGTH':
|
||||
$aFields['DESCRIPTION'] .= ' - ' . \G::LoadTranslation($sError) . ': ' . PPP_MINIMUM_LENGTH .'. ';
|
||||
$aFields[substr($sError, 3)] = PPP_MINIMUM_LENGTH;
|
||||
break;
|
||||
case 'ID_PPP_MAXIMUM_LENGTH':
|
||||
$aFields['DESCRIPTION'] .= ' - ' . \G::LoadTranslation($sError) . ': ' . PPP_MAXIMUM_LENGTH .'. ';
|
||||
$aFields[substr($sError, 3)] = PPP_MAXIMUM_LENGTH;
|
||||
break;
|
||||
case 'ID_PPP_EXPIRATION_IN':
|
||||
$aFields['DESCRIPTION'] .= ' - ' . \G::LoadTranslation($sError) . ' ' . PPP_EXPIRATION_IN . ' ' . \G::LoadTranslation('ID_DAYS') .'. ';
|
||||
$aFields[substr($sError, 3)] = PPP_EXPIRATION_IN;
|
||||
break;
|
||||
default:
|
||||
$aFields['DESCRIPTION'] .= ' - ' . \G::LoadTranslation($sError);
|
||||
$aFields[substr($sError, 3)] = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$aFields['DESCRIPTION'] .= \G::LoadTranslation('ID_PLEASE_CHANGE_PASSWORD_POLICY');
|
||||
$aFields['STATUS'] = false;
|
||||
} else {
|
||||
$aFields['DESCRIPTION'] = \G::LoadTranslation('ID_PASSWORD_COMPLIES_POLICIES');
|
||||
$aFields['STATUS'] = true;
|
||||
}
|
||||
return $aFields;
|
||||
}
|
||||
|
||||
/**
|
||||
* change status of an user
|
||||
*
|
||||
* @access public
|
||||
* @param array $sUserUID
|
||||
* @return void
|
||||
*/
|
||||
public function changeUserStatus ($sUserUID = '', $sStatus = 'ACTIVE')
|
||||
{
|
||||
require_once (PATH_RBAC_HOME . "engine" . PATH_SEP . "classes" . PATH_SEP . "model" . PATH_SEP . "RbacUsers.php");
|
||||
$this->userObj = new \RbacUsers();
|
||||
if ($sStatus === 'ACTIVE') {
|
||||
$sStatus = 1;
|
||||
}
|
||||
$aFields = $this->userObj->load( $sUserUID );
|
||||
$aFields['USR_STATUS'] = $sStatus;
|
||||
$this->userObj->update( $aFields );
|
||||
}
|
||||
|
||||
/**
|
||||
* remove a role from an user
|
||||
*
|
||||
* @access public
|
||||
* @param array $sUserUID
|
||||
* @return void
|
||||
*/
|
||||
public function removeRolesFromUser ($sUserUID = '')
|
||||
{
|
||||
$oCriteria = new \Criteria( 'rbac' );
|
||||
$oCriteria->add( \UsersRolesPeer::USR_UID, $sUserUID );
|
||||
\UsersRolesPeer::doDelete( $oCriteria );
|
||||
}
|
||||
|
||||
/**
|
||||
* updated an user
|
||||
*
|
||||
* @access public
|
||||
* @param array $aData
|
||||
* @param string $sRolCode
|
||||
* @return void
|
||||
*/
|
||||
public function updateUser ($aData = array(), $sRolCode = '')
|
||||
{
|
||||
require_once (PATH_RBAC_HOME . "engine" . PATH_SEP . "classes" . PATH_SEP . "model" . PATH_SEP . "RbacUsers.php");
|
||||
$this->userObj = new \RbacUsers();
|
||||
if (isset( $aData['USR_STATUS'] )) {
|
||||
if ($aData['USR_STATUS'] == 'ACTIVE') {
|
||||
$aData['USR_STATUS'] = 1;
|
||||
}
|
||||
}
|
||||
$this->userObj->update( $aData );
|
||||
if ($sRolCode != '') {
|
||||
$this->removeRolesFromUser( $aData['USR_UID'] );
|
||||
$this->assignRoleToUser( $aData['USR_UID'], $sRolCode );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the roles and permission for one RBAC_user
|
||||
*
|
||||
* gets the Role and their permissions for one User
|
||||
*
|
||||
* @author Fernando Ontiveros Lira <fernando@colosa.com>
|
||||
* @access public
|
||||
*
|
||||
* @param string $sSystem the system
|
||||
* @param string $sUser the user
|
||||
* @return $this->aUserInfo[ $sSystem ]
|
||||
*/
|
||||
public function loadUserRolePermission ($sSystem, $sUser)
|
||||
{
|
||||
//in previous versions we provided a path data and session we will cache the session Info for this user
|
||||
//now this is deprecated, and all the aUserInfo is in the memcache
|
||||
require_once (PATH_RBAC_HOME . "engine" . PATH_SEP . "classes" . PATH_SEP . "model" . PATH_SEP . "UsersRoles.php");
|
||||
require_once (PATH_RBAC_HOME . "engine" . PATH_SEP . "classes" . PATH_SEP . "model" . PATH_SEP . "Systems.php");
|
||||
require_once (PATH_RBAC_HOME . "engine" . PATH_SEP . "classes" . PATH_SEP . "model" . PATH_SEP . "RbacUsers.php");
|
||||
$this->sSystem = $sSystem;
|
||||
$this->usersRolesObj = new \UsersRoles();
|
||||
$this->systemObj = new \Systems();
|
||||
$fieldsSystem = $this->systemObj->loadByCode( $sSystem );
|
||||
$fieldsRoles = $this->usersRolesObj->getRolesBySystem( $fieldsSystem['SYS_UID'], $sUser );
|
||||
$fieldsPermissions = $this->usersRolesObj->getAllPermissions( $fieldsRoles['ROL_UID'], $sUser );
|
||||
$this->userObj = new \RbacUsers();
|
||||
$this->aUserInfo['USER_INFO'] = $this->userObj->load( $sUser );
|
||||
$this->aUserInfo[$sSystem]['SYS_UID'] = $fieldsSystem['SYS_UID'];
|
||||
$this->aUserInfo[$sSystem]['ROLE'] = $fieldsRoles;
|
||||
$this->aUserInfo[$sSystem]['PERMISSIONS'] = $fieldsPermissions;
|
||||
return $fieldsPermissions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create User
|
||||
*
|
||||
* @param array $arrayData Data
|
||||
*
|
||||
* return array Return data of the new User created
|
||||
*/
|
||||
public function create($arrayData)
|
||||
{
|
||||
try {
|
||||
global $RBAC;
|
||||
require_once (PATH_TRUNK . "workflow" . PATH_SEP . "engine" . PATH_SEP . "classes" . PATH_SEP . "model" . PATH_SEP . "Users.php");
|
||||
$arrayData = array_change_key_case($arrayData, CASE_UPPER);
|
||||
$form = $arrayData;
|
||||
if ($form['USR_REPLACED_BY'] != '') {
|
||||
$oReplacedBy = \UsersPeer::retrieveByPK($form['USR_REPLACED_BY']);
|
||||
if (is_null($oReplacedBy)) {
|
||||
throw new \Exception('`usr_replaced_by`:'.$form['USR_REPLACED_BY'].' '.\G::LoadTranslation('ID_AUTHENTICATION_SOURCE_INVALID'));
|
||||
}
|
||||
}
|
||||
if ($form['USR_COUNTRY'] != '') {
|
||||
$oCountry = \IsoCountryPeer::retrieveByPK($form['USR_COUNTRY']);
|
||||
if (is_null($oCountry)) {
|
||||
throw new \Exception('Invalid value for `usr_country`: '.$form['USR_COUNTRY']);
|
||||
}
|
||||
}
|
||||
if ($form['USR_CITY'] != '') {
|
||||
$oCity = \IsoSubdivisionPeer::retrieveByPK($form['USR_COUNTRY'], $form['USR_CITY']);
|
||||
if (is_null($oCity)) {
|
||||
throw new \Exception('Invalid value for `usr_city`: '.$form['USR_CITY']);
|
||||
}
|
||||
}
|
||||
if ($form['USR_LOCATION'] != '') {
|
||||
$oLocation = \IsoLocationPeer::retrieveByPK($form['USR_COUNTRY'], $form['USR_LOCATION']);
|
||||
if (is_null($oLocation)) {
|
||||
throw new \Exception('Invalid value for `usr_location`: '.$form['USR_LOCATION']);
|
||||
}
|
||||
}
|
||||
if ($form['USR_COUNTRY'] != '') {
|
||||
$oReplacedBy = \IsoCountryPeer::retrieveByPK($form['USR_COUNTRY']);
|
||||
if (is_null($oReplacedBy)) {
|
||||
throw new \Exception('Invalid value for `usr_country`: '.$form['USR_COUNTRY']);
|
||||
}
|
||||
}
|
||||
if (isset($arrayData['USR_UID'])) {
|
||||
$form['USR_UID'] = $arrayData['USR_UID'];
|
||||
} else {
|
||||
$form['USR_UID'] = '';
|
||||
}
|
||||
$sConfirm = $this->testPassword($form['USR_NEW_PASS']);
|
||||
if ($sConfirm['STATUS'] != 1) {
|
||||
throw new \Exception('`usr_new_pass`. '.$sConfirm['DESCRIPTION']);
|
||||
}
|
||||
if ($form['USR_NEW_PASS'] != $form['USR_CNF_PASS']) {
|
||||
throw new \Exception('`usr_new_pass or usr_cnf_pass`. '.\G::LoadTranslation('ID_NEW_PASS_SAME_OLD_PASS'));
|
||||
}
|
||||
$form['USR_PASSWORD'] = md5($form['USR_NEW_PASS']);
|
||||
if (!isset($form['USR_CITY'])) {
|
||||
$form['USR_CITY'] = '';
|
||||
}
|
||||
if (!isset($form['USR_LOCATION'])) {
|
||||
$form['USR_LOCATION'] = '';
|
||||
}
|
||||
if (!isset($form['USR_AUTH_USER_DN'])) {
|
||||
$form['USR_AUTH_USER_DN'] = '';
|
||||
}
|
||||
$criteria = new \Criteria();
|
||||
$criteria->addSelectColumn(\UsersPeer::USR_USERNAME);
|
||||
$criteria->add(\UsersPeer::USR_USERNAME, utf8_encode($arrayData['USR_USERNAME']));
|
||||
if (\UsersPeer::doCount($criteria) > 0) {
|
||||
throw new \Exception('`usr_username`. '.\G::LoadTranslation('ID_USERNAME_ALREADY_EXISTS', array('USER_ID' => $arrayData['USR_USERNAME'])));
|
||||
}
|
||||
if ($form['USR_USERNAME'] == '') {
|
||||
throw new \Exception('`usr_name`. '.\G::LoadTranslation('ID_MSG_ERROR_USR_USERNAME'));
|
||||
} else {
|
||||
$aData['USR_USERNAME'] = $form['USR_USERNAME'];
|
||||
}
|
||||
$aData['USR_PASSWORD'] = $form['USR_PASSWORD'];
|
||||
if ($form['USR_FIRSTNAME'] == '') {
|
||||
throw new \Exception('`usr_firstname`. '.\G::LoadTranslation('ID_MSG_ERROR_USR_FIRSTNAME'));
|
||||
} else {
|
||||
$aData['USR_FIRSTNAME'] = $form['USR_FIRSTNAME'];
|
||||
}
|
||||
if ($form['USR_LASTNAME'] == '') {
|
||||
throw new \Exception('`usr_lastname`. '.\G::LoadTranslation('ID_MSG_ERROR_USR_LASTNAME'));
|
||||
} else {
|
||||
$aData['USR_LASTNAME'] = $form['USR_LASTNAME'];
|
||||
}
|
||||
if ($form['USR_EMAIL'] == '') {
|
||||
throw new \Exception('Invalid value specified for `usr_email`, can`t be null.');
|
||||
} else {
|
||||
if (!filter_var($form['USR_EMAIL'], FILTER_VALIDATE_EMAIL)) {
|
||||
throw new \Exception('`usr_email`. '.\G::LoadTranslation('ID_INCORRECT_EMAIL'));
|
||||
} else {
|
||||
$aData['USR_EMAIL'] = $form['USR_EMAIL'];
|
||||
}
|
||||
}
|
||||
if ($form['USR_DUE_DATE'] == '') {
|
||||
throw new \Exception('`usr_due_date`. '.\G::LoadTranslation('ID_MSG_ERROR_DUE_DATE'));
|
||||
} else {
|
||||
$dueDate = explode("-", $form['USR_DUE_DATE']);
|
||||
if (ctype_digit($dueDate[0])) {
|
||||
if (checkdate($dueDate[1], $dueDate[2], $dueDate[0]) == false) {
|
||||
throw new \Exception('`usr_due_date`. '.\G::LoadTranslation('ID_MSG_ERROR_DUE_DATE'));
|
||||
} else {
|
||||
$aData['USR_DUE_DATE'] = $form['USR_DUE_DATE'];
|
||||
}
|
||||
} else {
|
||||
throw new \Exception('`usr_due_date`. '.\G::LoadTranslation('ID_MSG_ERROR_DUE_DATE'));
|
||||
}
|
||||
}
|
||||
$aData['USR_CREATE_DATE'] = date('Y-m-d H:i:s');
|
||||
$aData['USR_UPDATE_DATE'] = date('Y-m-d H:i:s');
|
||||
$aData['USR_BIRTHDAY'] = date('Y-m-d');
|
||||
$aData['USR_AUTH_USER_DN'] = $form['USR_AUTH_USER_DN'];
|
||||
$statusWF = $form['USR_STATUS'];
|
||||
if ($form['USR_STATUS'] == '') {
|
||||
throw new \Exception('Invalid value specified for `usr_status`, can`t be null');
|
||||
} else {
|
||||
if ($form['USR_STATUS'] == 'ACTIVE' || $form['USR_STATUS'] == 'INACTIVE' || $form['USR_STATUS'] == 'VACATION') {
|
||||
$aData['USR_STATUS'] = $form['USR_STATUS'];
|
||||
} else {
|
||||
throw new \Exception('`usr_status`. Invalid value for status field.');
|
||||
}
|
||||
}
|
||||
if ($form['USR_ROLE'] == '') {
|
||||
throw new \Exception('Invalid value specified for `usr_role`, can`t be null');
|
||||
} else {
|
||||
$oCriteria = new \Criteria('rbac');
|
||||
$oCriteria->add(\RolesPeer::ROL_CODE, $form['USR_ROLE']);
|
||||
$oDataset = \RolesPeer::doSelectRS($oCriteria);
|
||||
$oDataset->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
$oDataset->next();
|
||||
$aRow = $oDataset->getRow();
|
||||
if ($oDataset->getRow()) {
|
||||
$aData['USR_ROLE'] = $form['USR_ROLE'];
|
||||
} else {
|
||||
throw new \Exception('`usr_role`. Invalid value for role field.');
|
||||
}
|
||||
}
|
||||
try {
|
||||
if ($aData['USR_STATUS'] == 'ACTIVE') {
|
||||
$aData['USR_STATUS'] = 1;
|
||||
}
|
||||
if ($aData['USR_STATUS'] == 'INACTIVE') {
|
||||
$aData['USR_STATUS'] = 0;
|
||||
}
|
||||
$sUserUID = $this->createUser($aData);
|
||||
if ($form['USR_ROLE'] != '') {
|
||||
$this->assignRoleToUser($sUserUID, $form['USR_ROLE']);
|
||||
}
|
||||
} catch(Exception $oError) {
|
||||
throw new \Exception($oError->getMessage());
|
||||
}
|
||||
$aData['USR_STATUS'] = $statusWF;
|
||||
$aData['USR_UID'] = $sUserUID;
|
||||
$aData['USR_COUNTRY'] = $form['USR_COUNTRY'];
|
||||
$aData['USR_CITY'] = $form['USR_CITY'];
|
||||
$aData['USR_LOCATION'] = $form['USR_LOCATION'];
|
||||
$aData['USR_ADDRESS'] = $form['USR_ADDRESS'];
|
||||
$aData['USR_PHONE'] = $form['USR_PHONE'];
|
||||
$aData['USR_ZIP_CODE'] = $form['USR_ZIP_CODE'];
|
||||
$aData['USR_POSITION'] = $form['USR_POSITION'];
|
||||
$aData['USR_REPLACED_BY'] = $form['USR_REPLACED_BY'];
|
||||
$oUser = new \Users();
|
||||
$oUser -> create( $aData );
|
||||
if ((isset($form['USR_CALENDAR']))) {
|
||||
//Save Calendar ID for this user
|
||||
\G::LoadClass("calendar");
|
||||
$calendarObj = new \Calendar();
|
||||
$calendarObj->assignCalendarTo($sUserUID, $form['USR_CALENDAR'], 'USER');
|
||||
}
|
||||
$oCriteria = $this->getUser($sUserUID);
|
||||
return $oCriteria;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update User
|
||||
*
|
||||
* @param string $usrUid Unique id of User
|
||||
* @param array $arrayData Data
|
||||
* @param string $usrLoggedUid Unique id of User logged
|
||||
*
|
||||
* return array Return data of the User updated
|
||||
*/
|
||||
public function update($usrUid, $arrayData, $usrLoggedUid)
|
||||
{
|
||||
try {
|
||||
global $RBAC;
|
||||
$arrayData = array_change_key_case($arrayData, CASE_UPPER);
|
||||
$form = $arrayData;
|
||||
$countPermission = 0;
|
||||
$permission = $this->loadUserRolePermission($RBAC->sSystem, $usrLoggedUid);
|
||||
foreach ($permission as $key => $value) {
|
||||
if ($value["PER_CODE"] == 'PM_USERS') {
|
||||
$countPermission+=1;
|
||||
}
|
||||
}
|
||||
if ($countPermission != 1) {
|
||||
throw new \Exception('This user: '.$usrLoggedUid. ', can`t update the data.');
|
||||
}
|
||||
$criteria = new \Criteria();
|
||||
$criteria->addSelectColumn(\UsersPeer::USR_USERNAME);
|
||||
$criteria->add(\UsersPeer::USR_USERNAME, utf8_encode($arrayData['USR_USERNAME']));
|
||||
if (\UsersPeer::doCount($criteria) > 0) {
|
||||
throw new \Exception('`usr_username`. '.\G::LoadTranslation('ID_USERNAME_ALREADY_EXISTS', array('USER_ID' => $arrayData['USR_USERNAME'])));
|
||||
}
|
||||
if (isset($usrUid)) {
|
||||
$form['USR_UID'] = $usrUid;
|
||||
} else {
|
||||
$form['USR_UID'] = '';
|
||||
}
|
||||
if (!isset($form['USR_NEW_PASS'])) {
|
||||
$form['USR_NEW_PASS'] = '';
|
||||
}
|
||||
if ($form['USR_NEW_PASS'] != '') {
|
||||
$form['USR_PASSWORD'] = md5($form['USR_NEW_PASS']);
|
||||
}
|
||||
if (!isset($form['USR_AUTH_USER_DN'])) {
|
||||
$form['USR_AUTH_USER_DN'] = '';
|
||||
}
|
||||
$aData['USR_UID'] = $form['USR_UID'];
|
||||
if ($form['USR_USERNAME'] != '') {
|
||||
$aData['USR_USERNAME'] = $form['USR_USERNAME'];
|
||||
}
|
||||
if (isset($form['USR_PASSWORD'])) {
|
||||
if ($form['USR_PASSWORD'] != '') {
|
||||
if ($form['USR_NEW_PASS'] != $form['USR_CNF_PASS']) {
|
||||
throw new \Exception('`usr_new_pass or usr_cnf_pass`. '.\G::LoadTranslation('ID_NEW_PASS_SAME_OLD_PASS'));
|
||||
}
|
||||
$aData['USR_PASSWORD'] = $form['USR_PASSWORD'];
|
||||
require_once (PATH_TRUNK . "workflow" . PATH_SEP . "engine" . PATH_SEP . "classes" . PATH_SEP . "model" . PATH_SEP . "UsersProperties.php");
|
||||
$oUserProperty = new \UsersProperties();
|
||||
$aUserProperty = $oUserProperty->loadOrCreateIfNotExists($form['USR_UID'], array('USR_PASSWORD_HISTORY' => serialize(array(md5($form['USR_PASSWORD'])))));
|
||||
$memKey = 'rbacSession' . session_id();
|
||||
$memcache = & \PMmemcached::getSingleton(defined('SYS_SYS') ? SYS_SYS : '' );
|
||||
if (($RBAC->aUserInfo = $memcache->get($memKey)) === false) {
|
||||
$this->loadUserRolePermission($RBAC->sSystem, $usrLoggedUid);
|
||||
$memcache->set($memKey, $RBAC->aUserInfo, \PMmemcached::EIGHT_HOURS);
|
||||
}
|
||||
if ($RBAC->aUserInfo['PROCESSMAKER']['ROLE']['ROL_CODE'] == 'PROCESSMAKER_ADMIN') {
|
||||
$aUserProperty['USR_LAST_UPDATE_DATE'] = date('Y-m-d H:i:s');
|
||||
$aUserProperty['USR_LOGGED_NEXT_TIME'] = 1;
|
||||
$oUserProperty->update($aUserProperty);
|
||||
}
|
||||
$aErrors = $oUserProperty->validatePassword($form['USR_NEW_PASS'], $aUserProperty['USR_LAST_UPDATE_DATE'], 0);
|
||||
if (count($aErrors) > 0) {
|
||||
$sDescription = \G::LoadTranslation('ID_POLICY_ALERT') . ':,';
|
||||
foreach ($aErrors as $sError) {
|
||||
switch ($sError) {
|
||||
case 'ID_PPP_MINIMUN_LENGTH':
|
||||
$sDescription .= ' - ' . \G::LoadTranslation($sError) . ': ' . PPP_MINIMUN_LENGTH . '. ';
|
||||
break;
|
||||
case 'ID_PPP_MAXIMUN_LENGTH':
|
||||
$sDescription .= ' - ' . \G::LoadTranslation($sError) . ': ' . PPP_MAXIMUN_LENGTH . '. ';
|
||||
break;
|
||||
case 'ID_PPP_EXPIRATION_IN':
|
||||
$sDescription .= ' - ' . \G::LoadTranslation($sError) . ' ' . PPP_EXPIRATION_IN . ' ' . G::LoadTranslation('ID_DAYS') . '. ';
|
||||
break;
|
||||
default:
|
||||
$sDescription .= ' - ' . \G::LoadTranslation($sError) . ',';
|
||||
break;
|
||||
}
|
||||
}
|
||||
$sDescription .= '' . \G::LoadTranslation('ID_PLEASE_CHANGE_PASSWORD_POLICY');
|
||||
throw new \Exception('`usr_new_pass or usr_cnf_pass`. '.$sDescription);
|
||||
}
|
||||
$aHistory = unserialize($aUserProperty['USR_PASSWORD_HISTORY']);
|
||||
if (!is_array($aHistory)) {
|
||||
$aHistory = array();
|
||||
}
|
||||
if (!defined('PPP_PASSWORD_HISTORY')) {
|
||||
define('PPP_PASSWORD_HISTORY', 0);
|
||||
}
|
||||
if (PPP_PASSWORD_HISTORY > 0) {
|
||||
//it's looking a password igual into aHistory array that was send for post in md5 way
|
||||
$c = 0;
|
||||
$sw = 1;
|
||||
while (count($aHistory) >= 1 && count($aHistory) > $c && $sw) {
|
||||
if (strcmp(trim($aHistory[$c]), trim($form['USR_PASSWORD'])) == 0) {
|
||||
$sw = 0;
|
||||
}
|
||||
$c++;
|
||||
}
|
||||
if ($sw == 0) {
|
||||
$sDescription = \G::LoadTranslation('ID_POLICY_ALERT') . ':<br /><br />';
|
||||
$sDescription .= ' - ' . \G::LoadTranslation('PASSWORD_HISTORY') . ': ' . PPP_PASSWORD_HISTORY . '<br />';
|
||||
$sDescription .= '<br />' . \G::LoadTranslation('ID_PLEASE_CHANGE_PASSWORD_POLICY') . '';
|
||||
throw new \Exception('`usr_new_pass or usr_cnf_pass`. '.$sDescription);
|
||||
}
|
||||
if (count($aHistory) >= PPP_PASSWORD_HISTORY) {
|
||||
$sLastPassw = array_shift($aHistory);
|
||||
}
|
||||
$aHistory[] = $form['USR_PASSWORD'];
|
||||
}
|
||||
$aUserProperty['USR_LAST_UPDATE_DATE'] = date('Y-m-d H:i:s');
|
||||
$aUserProperty['USR_LOGGED_NEXT_TIME'] = 1;
|
||||
$aUserProperty['USR_PASSWORD_HISTORY'] = serialize($aHistory);
|
||||
$oUserProperty->update($aUserProperty);
|
||||
}
|
||||
}
|
||||
if ($form['USR_FIRSTNAME'] != '') {
|
||||
$aData['USR_FIRSTNAME'] = $form['USR_FIRSTNAME'];
|
||||
}
|
||||
if ($form['USR_LASTNAME'] != '') {
|
||||
$aData['USR_LASTNAME'] = $form['USR_LASTNAME'];
|
||||
}
|
||||
if ($form['USR_EMAIL'] != '') {
|
||||
if (!filter_var($form['USR_EMAIL'], FILTER_VALIDATE_EMAIL)) {
|
||||
throw new \Exception('`usr_email`. '.\G::LoadTranslation('ID_INCORRECT_EMAIL'));
|
||||
} else {
|
||||
$aData['USR_EMAIL'] = $form['USR_EMAIL'];
|
||||
}
|
||||
}
|
||||
if ($form['USR_DUE_DATE'] != '') {
|
||||
$dueDate = explode("-", $form['USR_DUE_DATE']);
|
||||
if (ctype_digit($dueDate[0])) {
|
||||
if (checkdate($dueDate[1], $dueDate[2], $dueDate[0]) == false) {
|
||||
throw new \Exception('`usr_due_date`. '.\G::LoadTranslation('ID_MSG_ERROR_DUE_DATE'));
|
||||
} else {
|
||||
$aData['USR_DUE_DATE'] = $form['USR_DUE_DATE'];
|
||||
}
|
||||
} else {
|
||||
throw new \Exception('`usr_due_date`. '.\G::LoadTranslation('ID_MSG_ERROR_DUE_DATE'));
|
||||
}
|
||||
}
|
||||
$aData['USR_UPDATE_DATE'] = date('Y-m-d H:i:s');
|
||||
if ($form['USR_STATUS'] != '') {
|
||||
$aData['USR_STATUS'] = $form['USR_STATUS'];
|
||||
}
|
||||
if ($form['USR_ROLE'] != '') {
|
||||
$oCriteria = new \Criteria('rbac');
|
||||
$oCriteria->add(\RolesPeer::ROL_CODE, $form['USR_ROLE']);
|
||||
$oDataset = \RolesPeer::doSelectRS($oCriteria);
|
||||
$oDataset->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
$oDataset->next();
|
||||
$aRow = $oDataset->getRow();
|
||||
if ($oDataset->getRow()) {
|
||||
$aData['USR_ROLE'] = $form['USR_ROLE'];
|
||||
} else {
|
||||
throw new \Exception('`usr_role`. Invalid value for field.');
|
||||
}
|
||||
$this->updateUser($aData, $form['USR_ROLE']);
|
||||
} else {
|
||||
$this->updateUser($aData);
|
||||
}
|
||||
if ($form['USR_COUNTRY'] != '') {
|
||||
$oReplacedBy = \IsoCountryPeer::retrieveByPK($form['USR_COUNTRY']);
|
||||
if (is_null($oReplacedBy)) {
|
||||
throw new \Exception('Invalid value for `usr_country`: '.$form['USR_COUNTRY']);
|
||||
} else {
|
||||
$aData['USR_COUNTRY'] = $form['USR_COUNTRY'];
|
||||
$aData['USR_CITY'] = '';
|
||||
$aData['USR_LOCATION'] = '';
|
||||
}
|
||||
}
|
||||
if ($form['USR_CITY'] != '') {
|
||||
$oCity = \IsoSubdivisionPeer::retrieveByPK($form['USR_COUNTRY'], $form['USR_CITY']);
|
||||
if (is_null($oCity)) {
|
||||
throw new \Exception('Invalid value for `usr_city`: '.$form['USR_CITY']);
|
||||
} else {
|
||||
$aData['USR_CITY'] = $form['USR_CITY'];
|
||||
}
|
||||
}
|
||||
if ($form['USR_LOCATION'] != '') {
|
||||
$oLocation = \IsoLocationPeer::retrieveByPK($form['USR_COUNTRY'], $form['USR_LOCATION']);
|
||||
if (is_null($oLocation)) {
|
||||
throw new \Exception('Invalid value for `usr_location`: '.$form['USR_LOCATION']);
|
||||
} else {
|
||||
$aData['USR_LOCATION'] = $form['USR_LOCATION'];
|
||||
}
|
||||
}
|
||||
$aData['USR_ADDRESS'] = $form['USR_ADDRESS'];
|
||||
$aData['USR_PHONE'] = $form['USR_PHONE'];
|
||||
$aData['USR_ZIP_CODE'] = $form['USR_ZIP_CODE'];
|
||||
$aData['USR_POSITION'] = $form['USR_POSITION'];
|
||||
if ($form['USR_ROLE'] != '') {
|
||||
$aData['USR_ROLE'] = $form['USR_ROLE'];
|
||||
}
|
||||
if ($form['USR_REPLACED_BY'] != '') {
|
||||
$oReplacedBy = \UsersPeer::retrieveByPK($form['USR_REPLACED_BY']);
|
||||
if (is_null($oReplacedBy)) {
|
||||
throw new \Exception('`usr_replaced_by`:'.$form['USR_REPLACED_BY'].' '.\G::LoadTranslation('ID_AUTHENTICATION_SOURCE_INVALID'));
|
||||
} else {
|
||||
$aData['USR_REPLACED_BY'] = $form['USR_REPLACED_BY'];
|
||||
}
|
||||
}
|
||||
if (isset($form['USR_AUTH_USER_DN'])) {
|
||||
$aData['USR_AUTH_USER_DN'] = $form['USR_AUTH_USER_DN'];
|
||||
}
|
||||
require_once (PATH_TRUNK . "workflow" . PATH_SEP . "engine" . PATH_SEP . "classes" . PATH_SEP . "model" . PATH_SEP . "Users.php");
|
||||
$oUser = new \Users();
|
||||
$oUser->update($aData);
|
||||
$oCriteria = $this->getUser($usrUid);
|
||||
return $oCriteria;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Authenticate User
|
||||
*
|
||||
* @param array $arrayData Data
|
||||
*
|
||||
* return array Return data of the User updated
|
||||
*/
|
||||
public function authenticate($arrayData)
|
||||
{
|
||||
try {
|
||||
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete User
|
||||
*
|
||||
* @param string $usrUid Unique id of User
|
||||
*
|
||||
* return void
|
||||
*/
|
||||
public function delete($usrUid)
|
||||
{
|
||||
try {
|
||||
\G::LoadClass('case');
|
||||
$oProcessMap = new \Cases();
|
||||
$USR_UID = $usrUid;
|
||||
$total = 0;
|
||||
$history = 0;
|
||||
$c = $oProcessMap->getCriteriaUsersCases('TO_DO', $USR_UID);
|
||||
$total += \ApplicationPeer::doCount($c);
|
||||
$c = $oProcessMap->getCriteriaUsersCases('DRAFT', $USR_UID);
|
||||
$total += \ApplicationPeer::doCount($c);
|
||||
$c = $oProcessMap->getCriteriaUsersCases('COMPLETED', $USR_UID);
|
||||
$history += \ApplicationPeer::doCount($c);
|
||||
$c = $oProcessMap->getCriteriaUsersCases('CANCELLED', $USR_UID);
|
||||
$history += \ApplicationPeer::doCount($c);
|
||||
if ($total > 0) {
|
||||
throw (new \Exception( 'The user with usr_uid: '. $USR_UID .', cannot be deleted while it has cases assigned.'));
|
||||
} else {
|
||||
$UID = $usrUid;
|
||||
\G::LoadClass('tasks');
|
||||
$oTasks = new \Tasks();
|
||||
$oTasks->ofToAssignUserOfAllTasks($UID);
|
||||
\G::LoadClass('groups');
|
||||
$oGroups = new \Groups();
|
||||
$oGroups->removeUserOfAllGroups($UID);
|
||||
$this->changeUserStatus($UID, 'CLOSED');
|
||||
$_GET['USR_USERNAME'] = '';
|
||||
$this->updateUser(array('USR_UID' => $UID, 'USR_USERNAME' => $_GET['USR_USERNAME']), '');
|
||||
require_once (PATH_TRUNK . "workflow" . PATH_SEP . "engine" . PATH_SEP . "classes" . PATH_SEP . "model" . PATH_SEP . "Users.php");
|
||||
$oUser = new \Users();
|
||||
$aFields = $oUser->load($UID);
|
||||
$aFields['USR_STATUS'] = 'CLOSED';
|
||||
$aFields['USR_USERNAME'] = '';
|
||||
$oUser->update($aFields);
|
||||
//Delete Dashboard
|
||||
require_once (PATH_TRUNK . "workflow" . PATH_SEP . "engine" . PATH_SEP . "classes" . PATH_SEP . "model" . PATH_SEP . "DashletInstance.php");
|
||||
$criteria = new \Criteria( 'workflow' );
|
||||
$criteria->add( \DashletInstancePeer::DAS_INS_OWNER_UID, $UID );
|
||||
$criteria->add( \DashletInstancePeer::DAS_INS_OWNER_TYPE , 'USER');
|
||||
\DashletInstancePeer::doDelete( $criteria );
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all Users
|
||||
*
|
||||
* @param string $filter
|
||||
* @param int $start
|
||||
* @param int $limit
|
||||
*
|
||||
* return array Return an array with all Users
|
||||
*/
|
||||
public function getUsers($filter, $start, $limit)
|
||||
{
|
||||
try {
|
||||
$aUserInfo = array();
|
||||
require_once (PATH_TRUNK . "workflow" . PATH_SEP . "engine" . PATH_SEP . "classes" . PATH_SEP . "model" . PATH_SEP . "Users.php");
|
||||
$oCriteria = new \Criteria();
|
||||
if ($filter != '') {
|
||||
$oCriteria->add( $oCriteria->getNewCriterion( \UsersPeer::USR_USERNAME, "%$filter%", \Criteria::LIKE )->addOr( $oCriteria->getNewCriterion( \UsersPeer::USR_FIRSTNAME, "%$filter%", \Criteria::LIKE ) )->addOr( $oCriteria->getNewCriterion( \UsersPeer::USR_LASTNAME, "%$filter%", \Criteria::LIKE ) ) );
|
||||
}
|
||||
if ($start) {
|
||||
if ($start < 0) {
|
||||
throw (new \Exception( 'Invalid value specified for `start`.'));
|
||||
} else {
|
||||
$oCriteria->setOffset($start);
|
||||
}
|
||||
}
|
||||
if ($limit != '') {
|
||||
if ($limit < 0) {
|
||||
throw (new \Exception( 'Invalid value specified for `limit`.'));
|
||||
} else {
|
||||
if ($limit == 0) {
|
||||
return $aUserInfo;
|
||||
} else {
|
||||
$oCriteria->setLimit($limit);
|
||||
}
|
||||
}
|
||||
}
|
||||
$oCriteria->add(\UsersPeer::USR_STATUS, 'CLOSED', \Criteria::ALT_NOT_EQUAL);
|
||||
$oDataset = \UsersPeer::doSelectRS($oCriteria);
|
||||
$oDataset->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
while ($oDataset->next()) {
|
||||
$aRow1 = $oDataset->getRow();
|
||||
$aRow1 = array_change_key_case($aRow1, CASE_LOWER);
|
||||
$aUserInfo[] = $aRow1;
|
||||
}
|
||||
//Return
|
||||
return $aUserInfo;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data of a User
|
||||
*
|
||||
* @param string $userUid Unique id of User
|
||||
*
|
||||
* return array Return an array with data of a User
|
||||
*/
|
||||
public function getUser($userUid)
|
||||
{
|
||||
try {
|
||||
$filter = '';
|
||||
$aUserInfo = array();
|
||||
$oUser = \UsersPeer::retrieveByPK($userUid);
|
||||
if (is_null($oUser)) {
|
||||
throw (new \Exception( 'This id for `usr_uid`: '. $userUid .' does not correspond to a registered user'));
|
||||
}
|
||||
require_once (PATH_TRUNK . "workflow" . PATH_SEP . "engine" . PATH_SEP . "classes" . PATH_SEP . "model" . PATH_SEP . "Users.php");
|
||||
$oCriteria = new \Criteria();
|
||||
if ($filter != '') {
|
||||
$oCriteria->add( $oCriteria->getNewCriterion( \UsersPeer::USR_USERNAME, "%$filter%", \Criteria::LIKE )->addOr( $oCriteria->getNewCriterion( \UsersPeer::USR_FIRSTNAME, "%$filter%", \Criteria::LIKE ) )->addOr( $oCriteria->getNewCriterion( \UsersPeer::USR_LASTNAME, "%$filter%", \Criteria::LIKE ) ) );
|
||||
}
|
||||
$oCriteria->add(\UsersPeer::USR_UID, $userUid);
|
||||
$oCriteria->add(\UsersPeer::USR_STATUS, 'CLOSED', \Criteria::ALT_NOT_EQUAL);
|
||||
$oDataset = \UsersPeer::doSelectRS($oCriteria);
|
||||
$oDataset->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
while ($oDataset->next()) {
|
||||
$aRow1 = $oDataset->getRow();
|
||||
$aRow1 = array_change_key_case($aRow1, CASE_LOWER);
|
||||
$aUserInfo = $aRow1;
|
||||
}
|
||||
//Return
|
||||
return $aUserInfo;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload image User
|
||||
*
|
||||
* @param string $userUid Unique id of User
|
||||
*
|
||||
*/
|
||||
public function uploadImage($userUid)
|
||||
{
|
||||
try {
|
||||
if ($_FILES['USR_PHOTO']['error'] != 1) {
|
||||
if ($_FILES['USR_PHOTO']['tmp_name'] != '') {
|
||||
$aAux = explode('.', $_FILES['USR_PHOTO']['name']);
|
||||
\G::uploadFile($_FILES['USR_PHOTO']['tmp_name'], PATH_IMAGES_ENVIRONMENT_USERS, $userUid . '.' . $aAux[1]);
|
||||
\G::resizeImage(PATH_IMAGES_ENVIRONMENT_USERS . $userUid . '.' . $aAux[1], 96, 96, PATH_IMAGES_ENVIRONMENT_USERS . $userUid . '.gif');
|
||||
}
|
||||
} else {
|
||||
$result->success = false;
|
||||
$result->fileError = true;
|
||||
throw (new \Exception($result));
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
335
workflow/engine/src/ProcessMaker/BusinessModel/Validator.php
Normal file
335
workflow/engine/src/ProcessMaker/BusinessModel/Validator.php
Normal file
@@ -0,0 +1,335 @@
|
||||
<?php
|
||||
namespace ProcessMaker\BusinessModel;
|
||||
|
||||
/**
|
||||
* Validator fields
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @protected
|
||||
*/
|
||||
class Validator{
|
||||
/**
|
||||
* Validate dep_uid
|
||||
* @var string $dep_uid. Uid for Departament
|
||||
* @var string $nameField. Name of field for message
|
||||
*
|
||||
* @access public
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
static public function depUid($dep_uid, $nameField = 'dep_uid')
|
||||
{
|
||||
$dep_uid = trim($dep_uid);
|
||||
if ($dep_uid == '') {
|
||||
throw (new \Exception("The departament with $nameField: '' does not exist."));
|
||||
}
|
||||
$oDepartment = new \Department();
|
||||
if (!($oDepartment->existsDepartment($dep_uid))) {
|
||||
throw (new \Exception("The departament with $nameField: '$dep_uid' does not exist."));
|
||||
}
|
||||
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("The departament with dep_title: '' is incorrect."));
|
||||
}
|
||||
|
||||
$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("The departament with dep_title: '$dep_title' already exists."));
|
||||
}
|
||||
return $dep_title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate dep_status
|
||||
* @var string $dep_uid. Uid for Departament
|
||||
* @var string $nameField. Name of field for message
|
||||
*
|
||||
* @access public
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
static public function depStatus($dep_status)
|
||||
{
|
||||
$dep_status = trim($dep_status);
|
||||
$values = array('ACTIVE', 'INACTIVE');
|
||||
if (!in_array($dep_status, $values)) {
|
||||
throw (new \Exception("The departament with dep_status: '$dep_status' is incorrect."));
|
||||
}
|
||||
return $dep_status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate usr_uid
|
||||
*
|
||||
* @param string $usr_uid, Uid for user
|
||||
* @param string $nameField . Name of field for message
|
||||
*
|
||||
* @access public
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
static public function usrUid($usr_uid, $nameField = 'usr_uid')
|
||||
{
|
||||
$usr_uid = trim($usr_uid);
|
||||
if ($usr_uid == '') {
|
||||
throw (new \Exception("The user with $nameField: '' does not exist."));
|
||||
}
|
||||
$oUsers = new \Users();
|
||||
if (!($oUsers->userExists($usr_uid))) {
|
||||
throw (new \Exception("The user with $nameField: '$usr_uid' does not exist."));
|
||||
}
|
||||
return $usr_uid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate app_uid
|
||||
*
|
||||
* @param string $app_uid, Uid for application
|
||||
* @param string $nameField . Name of field for message
|
||||
*
|
||||
* @access public
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
static public function appUid($app_uid, $nameField = 'app_uid')
|
||||
{
|
||||
$app_uid = trim($app_uid);
|
||||
if ($app_uid == '') {
|
||||
throw (new \Exception("The application with $nameField: '' does not exist."));
|
||||
}
|
||||
$oApplication = new \Application();
|
||||
if (!($oApplication->exists($app_uid))) {
|
||||
throw (new \Exception("The application with $nameField: '$app_uid' does not exist."));
|
||||
}
|
||||
return $app_uid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate app_uid
|
||||
*
|
||||
* @param string $tri_uid, Uid for trigger
|
||||
* @param string $nameField . Name of field for message
|
||||
*
|
||||
* @access public
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
static public function triUid($tri_uid, $nameField = 'tri_uid')
|
||||
{
|
||||
$tri_uid = trim($tri_uid);
|
||||
if ($tri_uid == '') {
|
||||
throw (new \Exception("The trigger with $nameField: '' does not exist."));
|
||||
}
|
||||
$oTriggers = new \Triggers();
|
||||
if (!($oTriggers->TriggerExists($tri_uid))) {
|
||||
throw (new \Exception("The trigger with $nameField: '$tri_uid' does not exist."));
|
||||
}
|
||||
return $tri_uid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate pro_uid
|
||||
*
|
||||
* @param string $pro_uid, Uid for process
|
||||
* @param string $nameField . Name of field for message
|
||||
*
|
||||
* @access public
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
static public function proUid($pro_uid, $nameField = 'pro_uid')
|
||||
{
|
||||
$pro_uid = trim($pro_uid);
|
||||
if ($pro_uid == '') {
|
||||
throw (new \Exception("The process with $nameField: '' does not exist."));
|
||||
}
|
||||
$oProcess = new \Process();
|
||||
if (!($oProcess->exists($pro_uid))) {
|
||||
throw (new \Exception("The process with $nameField: '$pro_uid' does not exist."));
|
||||
}
|
||||
return $pro_uid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate cat_uid
|
||||
*
|
||||
* @param string $cat_uid, Uid for category
|
||||
* @param string $nameField . Name of field for message
|
||||
*
|
||||
* @access public
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
static public function catUid($cat_uid, $nameField = 'cat_uid')
|
||||
{
|
||||
$cat_uid = trim($cat_uid);
|
||||
if ($cat_uid == '') {
|
||||
throw (new \Exception("The category with $nameField: '' does not exist."));
|
||||
}
|
||||
$oCategory = new \ProcessCategory();
|
||||
if (!($oCategory->exists($cat_uid))) {
|
||||
throw (new \Exception("The category with $nameField: '$cat_uid' does not exist."));
|
||||
}
|
||||
return $cat_uid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate date
|
||||
*
|
||||
* @param string $date, Date for validate
|
||||
* @param string $nameField . Name of field for message
|
||||
*
|
||||
* @access public
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
static public function isDate($date, $format = 'Y-m-d H:i:s', $nameField = 'app_uid')
|
||||
{
|
||||
$date = trim($date);
|
||||
if ($date == '') {
|
||||
throw (new \Exception("The value '' is not a valid date for the format '$format'."));
|
||||
}
|
||||
$d = \DateTime::createFromFormat($format, $date);
|
||||
if (!($d && $d->format($format) == $date)) {
|
||||
throw (new \Exception("The value '$date' is not a valid date for the format '$format'."));
|
||||
}
|
||||
return $date;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate is array
|
||||
* @var array $field. Field type array
|
||||
*
|
||||
* @access public
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
static public function isArray($field, $nameField)
|
||||
{
|
||||
if (!is_array($field)) {
|
||||
throw (new \Exception("Invalid value for '$nameField' it must be an array."));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate is string
|
||||
* @var array $field. Field type string
|
||||
*
|
||||
* @access public
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
static public function isString($field, $nameField)
|
||||
{
|
||||
if (!is_string($field)) {
|
||||
throw (new \Exception("Invalid value for '$nameField' it must be a string."));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate is integer
|
||||
* @var array $field. Field type integer
|
||||
*
|
||||
* @access public
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
static public function isInteger($field, $nameField)
|
||||
{
|
||||
if (!is_integer($field)) {
|
||||
throw (new \Exception("Invalid value for '$nameField' it must be a integer."));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate is boolean
|
||||
* @var boolean $field. Field type boolean
|
||||
*
|
||||
* @access public
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
static public function isBoolean($field, $nameField)
|
||||
{
|
||||
if (!is_bool($field)) {
|
||||
throw (new \Exception("Invalid value for '$nameField' it must be a boolean."));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate is boolean
|
||||
* @var boolean $field. Field type boolean
|
||||
*
|
||||
* @access public
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
static public function isNotEmpty($field, $nameField)
|
||||
{
|
||||
if (empty($field)) {
|
||||
throw (new \Exception("The field '$nameField' is empty."));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
622
workflow/engine/src/ProcessMaker/BusinessModel/WebEntry.php
Normal file
622
workflow/engine/src/ProcessMaker/BusinessModel/WebEntry.php
Normal file
@@ -0,0 +1,622 @@
|
||||
<?php
|
||||
namespace ProcessMaker\BusinessModel;
|
||||
|
||||
class WebEntry
|
||||
{
|
||||
private $arrayFieldDefinition = array(
|
||||
"TAS_UID" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "taskUid"),
|
||||
"DYN_UID" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "dynaFormUid"),
|
||||
"METHOD" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array("WS", "HTML"), "fieldNameAux" => "method"),
|
||||
"INPUT_DOCUMENT_ACCESS" => array("type" => "int", "required" => true, "empty" => false, "defaultValues" => array(0, 1), "fieldNameAux" => "inputDocumentAccess")
|
||||
);
|
||||
|
||||
private $arrayUserFieldDefinition = array(
|
||||
"USR_USERNAME" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "userUsername"),
|
||||
"USR_PASSWORD" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "userPassword")
|
||||
);
|
||||
|
||||
private $formatFieldNameInUppercase = true;
|
||||
|
||||
private $arrayFieldNameForException = array(
|
||||
"processUid" => "PRO_UID"
|
||||
);
|
||||
|
||||
/**
|
||||
* Constructor of the class
|
||||
*
|
||||
* return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
try {
|
||||
foreach ($this->arrayFieldDefinition as $key => $value) {
|
||||
$this->arrayFieldNameForException[$value["fieldNameAux"]] = $key;
|
||||
}
|
||||
|
||||
foreach ($this->arrayUserFieldDefinition 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($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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitizes a filename
|
||||
*
|
||||
* @param string $name Filename
|
||||
*
|
||||
* return string Return the filename sanitizes
|
||||
*/
|
||||
public function sanitizeFilename($name)
|
||||
{
|
||||
$name = trim($name);
|
||||
|
||||
$arraySpecialCharSearch = array(
|
||||
"ñ", "Ñ",
|
||||
"á", "é", "í", "ó", "ú", "Á", "É", "Í", "Ó", "Ú",
|
||||
"à", "è", "ì", "ò", "ù", "À", "È", "Ì", "Ò", "Ù",
|
||||
"â", "ê", "î", "ô", "û", "Â", "Ê", "Î", "Ô", "Û",
|
||||
"ä", "ë", "ï", "ö", "ü", "Ä", "Ë", "Ï", "Ö", "Ü",
|
||||
"/", "\\",
|
||||
" "
|
||||
);
|
||||
$arraySpecialCharReplace = array(
|
||||
"n", "N",
|
||||
"a", "e", "i", "o", "u", "A", "E", "I", "O", "U",
|
||||
"a", "e", "i", "o", "u", "A", "E", "I", "O", "U",
|
||||
"a", "e", "i", "o", "u", "A", "E", "I", "O", "U",
|
||||
"a", "e", "i", "o", "u", "A", "E", "I", "O", "U",
|
||||
"_", "_",
|
||||
"_"
|
||||
);
|
||||
|
||||
$newName = str_replace($arraySpecialCharSearch, $arraySpecialCharReplace, $name);
|
||||
|
||||
$arraySpecialCharSearch = array("/[^a-zA-Z0-9\_\-\.]/");
|
||||
$arraySpecialCharReplace = array("");
|
||||
|
||||
$newName = preg_replace($arraySpecialCharSearch, $arraySpecialCharReplace, $newName);
|
||||
|
||||
return $newName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all Web Entries data of a Process
|
||||
*
|
||||
* @param string $processUid Unique id of Process
|
||||
* @param string $option Option (ALL, UID, DYN_UID)
|
||||
* @param string $taskUid Unique id of Task
|
||||
* @param string $dynaFormUid Unique id of DynaForm
|
||||
*
|
||||
* return array Return an array with all Web Entries data of a Process
|
||||
*/
|
||||
public function getData($processUid, $option = "ALL", $taskUid = "", $dynaFormUid = "")
|
||||
{
|
||||
try {
|
||||
$arrayData = array();
|
||||
|
||||
//Verify data
|
||||
$process = new \ProcessMaker\BusinessModel\Process();
|
||||
|
||||
$process->throwExceptionIfNotExistsProcess($processUid, $this->arrayFieldNameForException["processUid"]);
|
||||
|
||||
if ($taskUid != "") {
|
||||
$process->throwExceptionIfNotExistsTask($processUid, $taskUid, $this->arrayFieldNameForException["taskUid"]);
|
||||
}
|
||||
|
||||
if ($dynaFormUid != "") {
|
||||
$dynaForm = new \ProcessMaker\BusinessModel\DynaForm();
|
||||
|
||||
$dynaForm->throwExceptionIfNotExistsDynaForm($dynaFormUid, $processUid, $this->arrayFieldNameForException["dynaFormUid"]);
|
||||
}
|
||||
|
||||
//Get data
|
||||
$webEntryPath = PATH_DATA . "sites" . PATH_SEP . SYS_SYS . PATH_SEP . "public" . PATH_SEP . $processUid;
|
||||
|
||||
if (is_dir($webEntryPath)) {
|
||||
$task = new \Task();
|
||||
$dynaForm = new \Dynaform();
|
||||
|
||||
$step = new \ProcessMaker\BusinessModel\Step();
|
||||
|
||||
$arrayDirFile = scandir($webEntryPath); //Ascending Order
|
||||
|
||||
$nrt = array("\n", "\r", "\t");
|
||||
$nrthtml = array("(n /)", "(r /)", "(t /)");
|
||||
|
||||
$http = (\G::is_https())? "https://" : "http://";
|
||||
$url = $http . $_SERVER["HTTP_HOST"] . "/sys" . SYS_SYS . "/" . SYS_LANG . "/" . SYS_SKIN . "/" . $processUid;
|
||||
|
||||
$flagNext = 1;
|
||||
|
||||
for ($i = 0; $i <= count($arrayDirFile) - 1 && $flagNext == 1; $i++) {
|
||||
$file = $arrayDirFile[$i];
|
||||
|
||||
if ($file != "" && $file != "." && $file != ".." && is_file($webEntryPath . PATH_SEP . $file)) {
|
||||
$one = 0;
|
||||
$two = 0;
|
||||
|
||||
$one = count(explode("wsClient.php", $file));
|
||||
$two = count(explode("Post.php", $file));
|
||||
|
||||
if ($one == 1 && $two == 1) {
|
||||
$arrayInfo = pathinfo($file);
|
||||
|
||||
$weTaskUid = "";
|
||||
$weDynaFormUid = "";
|
||||
$weFileName = $arrayInfo["filename"];
|
||||
|
||||
$strContent = str_replace($nrt, $nrthtml, file_get_contents($webEntryPath . PATH_SEP . $weFileName . ".php"));
|
||||
|
||||
if (preg_match("/^.*CURRENT_DYN_UID.*=.*[\"\'](\w{32})[\"\'].*$/", $strContent, $arrayMatch)) {
|
||||
$weDynaFormUid = $arrayMatch[1];
|
||||
}
|
||||
|
||||
if (file_exists($webEntryPath . PATH_SEP . $weFileName . "Post.php")) {
|
||||
$strContent = str_replace($nrt, $nrthtml, file_get_contents($webEntryPath . PATH_SEP . $weFileName . "Post.php"));
|
||||
|
||||
if (preg_match("/^.*ws_newCase\s*\(\s*[\"\']" . $processUid . "[\"\']\s*\,\s*[\"\'](\w{32})[\"\'].*\)\s*\;.*$/", $strContent, $arrayMatch)) {
|
||||
$weTaskUid = $arrayMatch[1];
|
||||
}
|
||||
}
|
||||
|
||||
if ($weTaskUid != "" && $weDynaFormUid != "") {
|
||||
$flagPush = 0;
|
||||
|
||||
switch ($option) {
|
||||
case "ALL":
|
||||
if ($step->existsRecord($weTaskUid, "DYNAFORM", $weDynaFormUid)) {
|
||||
$flagPush = 1;
|
||||
}
|
||||
break;
|
||||
case "UID":
|
||||
if ($taskUid != "" && $dynaFormUid != "" && $weTaskUid == $taskUid && $weDynaFormUid == $dynaFormUid && $step->existsRecord($weTaskUid, "DYNAFORM", $weDynaFormUid)) {
|
||||
$flagPush = 1;
|
||||
$flagNext = 0;
|
||||
}
|
||||
break;
|
||||
case "DYN_UID":
|
||||
if ($dynaFormUid != "" && $weDynaFormUid == $dynaFormUid && $step->existsRecord($weTaskUid, "DYNAFORM", $weDynaFormUid)) {
|
||||
$flagPush = 1;
|
||||
$flagNext = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if ($flagPush == 1) {
|
||||
$arrayTaskData = $task->load($weTaskUid);
|
||||
$arrayDynaFormData = $dynaForm->Load($weDynaFormUid);
|
||||
|
||||
$arrayData[$weTaskUid . "/" . $weDynaFormUid] = array(
|
||||
"processUid" => $processUid,
|
||||
"taskUid" => $weTaskUid,
|
||||
"taskTitle" => $arrayTaskData["TAS_TITLE"],
|
||||
"dynaFormUid" => $weDynaFormUid,
|
||||
"dynaFormTitle" => $arrayDynaFormData["DYN_TITLE"],
|
||||
"fileName" => $weFileName,
|
||||
"url" => $url . "/" . $weFileName . ".php"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Return
|
||||
return $arrayData;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Web Entry for a Process
|
||||
*
|
||||
* @param string $processUid Unique id of Process
|
||||
* @param array $arrayData Data
|
||||
*
|
||||
* return array Return data of the new Web Entry created
|
||||
*/
|
||||
public function create($processUid, $arrayData)
|
||||
{
|
||||
try {
|
||||
$arrayData = array_change_key_case($arrayData, CASE_UPPER);
|
||||
|
||||
//Verify data
|
||||
$process = new \ProcessMaker\BusinessModel\Process();
|
||||
|
||||
$process->throwExceptionIfNotExistsProcess($processUid, $this->arrayFieldNameForException["processUid"]);
|
||||
|
||||
$process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $this->arrayFieldDefinition, $this->arrayFieldNameForException, true);
|
||||
|
||||
$projectUser = new \ProcessMaker\BusinessModel\ProjectUser();
|
||||
|
||||
if ($arrayData["METHOD"] == "WS") {
|
||||
$process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $this->arrayUserFieldDefinition, $this->arrayFieldNameForException, true);
|
||||
|
||||
$loginData = $projectUser->userLogin($arrayData["USR_USERNAME"], $arrayData["USR_PASSWORD"]);
|
||||
|
||||
if ($loginData->status_code != 0) {
|
||||
throw (new \Exception($loginData->message));
|
||||
}
|
||||
}
|
||||
|
||||
$process->throwExceptionIfNotExistsTask($processUid, $arrayData["TAS_UID"], $this->arrayFieldNameForException["taskUid"]);
|
||||
|
||||
$dynaForm = new \ProcessMaker\BusinessModel\DynaForm();
|
||||
|
||||
$dynaForm->throwExceptionIfNotExistsDynaForm($arrayData["DYN_UID"], $processUid, $this->arrayFieldNameForException["dynaFormUid"]);
|
||||
|
||||
$task = new \Task();
|
||||
|
||||
$arrayTaskData = $task->load($arrayData["TAS_UID"]);
|
||||
|
||||
$weEventUid = $task->getStartingEvent($arrayData["TAS_UID"]);
|
||||
|
||||
if ($arrayTaskData["TAS_START"] == "FALSE") {
|
||||
throw (new \Exception(str_replace(array("{0}"), array($arrayTaskData["TAS_TITLE"]), "The task \"{0}\" is not initial task")));
|
||||
}
|
||||
|
||||
if ($arrayTaskData["TAS_ASSIGN_TYPE"] != "BALANCED") {
|
||||
throw (new \Exception(str_replace(array("{0}"), array($arrayTaskData["TAS_TITLE"]), "Web Entry only works with tasks which have \"Cyclical Assignment\", the task \"{0}\" does not have a valid assignment type. Please change the Assignment Rules")));
|
||||
}
|
||||
|
||||
if ($arrayData["METHOD"] == "WS") {
|
||||
$task = new \Tasks();
|
||||
|
||||
if ($task->assignUsertoTask($arrayData["TAS_UID"]) == 0) {
|
||||
throw (new \Exception(str_replace(array("{0}"), array($arrayTaskData["TAS_TITLE"]), "The task \"{0}\" does not have users")));
|
||||
}
|
||||
}
|
||||
|
||||
$dynaForm = new \Dynaform();
|
||||
|
||||
$arrayDynaFormData = $dynaForm->Load($arrayData["DYN_UID"]);
|
||||
|
||||
$step = new \ProcessMaker\BusinessModel\Step();
|
||||
|
||||
if (!$step->existsRecord($arrayData["TAS_UID"], "DYNAFORM", $arrayData["DYN_UID"])) {
|
||||
throw (new \Exception(str_replace(array("{0}", "{1}"), array($arrayDynaFormData["DYN_TITLE"], $arrayTaskData["TAS_TITLE"]), "The DynaForm \"{0}\" isn't assigned to the task \"{1}\"")));
|
||||
}
|
||||
|
||||
if ($arrayData["METHOD"] == "WS") {
|
||||
//Verify if the Web Entry exist
|
||||
$arrayWebEntryData = $this->getData($processUid, "UID", $arrayData["TAS_UID"], $arrayData["DYN_UID"]);
|
||||
|
||||
if (count($arrayWebEntryData) > 0) {
|
||||
throw (new \Exception("The Web Entry exist"));
|
||||
}
|
||||
|
||||
//Verify if User is assigned to Task
|
||||
$criteria = new \Criteria("workflow");
|
||||
|
||||
$criteria->addSelectColumn(\UsersPeer::USR_UID);
|
||||
$criteria->add(\UsersPeer::USR_USERNAME, $arrayData["USR_USERNAME"], \Criteria::EQUAL);
|
||||
|
||||
$rsCriteria = \UsersPeer::doSelectRS($criteria);
|
||||
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
|
||||
$rsCriteria->next();
|
||||
|
||||
$row = $rsCriteria->getRow();
|
||||
|
||||
if (!$projectUser->userIsAssignedToTask($row["USR_UID"], $arrayData["TAS_UID"])) {
|
||||
throw (new \Exception(str_replace(array("{0}", "{1}"), array($arrayData["USR_USERNAME"], $arrayTaskData["TAS_TITLE"]), "The user \"{0}\" does not have the task \"{1}\" assigned")));
|
||||
}
|
||||
}
|
||||
|
||||
//Create
|
||||
$taskUid = $arrayData["TAS_UID"];
|
||||
$dynaFormUid = $arrayData["DYN_UID"];
|
||||
$method = $arrayData["METHOD"];
|
||||
$inputDocumentAccess = $arrayData["INPUT_DOCUMENT_ACCESS"];
|
||||
$wsRoundRobin = 0; //0, 1 //0 - Cyclical Assignment
|
||||
|
||||
$pathProcess = PATH_DATA_SITE . "public" . PATH_SEP . $processUid;
|
||||
|
||||
\G::mk_dir($pathProcess, 0777);
|
||||
|
||||
$http = (\G::is_https())? "https://" : "http://";
|
||||
|
||||
$arrayDataAux = array();
|
||||
|
||||
switch ($method) {
|
||||
case "WS":
|
||||
$usrUsername = $arrayData["USR_USERNAME"];
|
||||
$usrPassword = $arrayData["USR_PASSWORD"];
|
||||
|
||||
//Creating sys.info;
|
||||
$site_public_path = "";
|
||||
|
||||
if (file_exists($site_public_path . "")) {
|
||||
}
|
||||
|
||||
//Creating the first file
|
||||
$dynTitle = $this->sanitizeFilename($arrayDynaFormData["DYN_TITLE"]);
|
||||
$fileName = $dynTitle;
|
||||
|
||||
$fileContent = "<?php\n";
|
||||
$fileContent .= "global \$_DBArray;\n";
|
||||
$fileContent .= "if (!isset(\$_DBArray)) {\n";
|
||||
$fileContent .= " \$_DBArray = array();\n";
|
||||
$fileContent .= "}\n";
|
||||
$fileContent .= "\$_SESSION['PROCESS'] = '" . $processUid . "';\n";
|
||||
$fileContent .= "\$_SESSION['CURRENT_DYN_UID'] = '" . $dynaFormUid . "';\n";
|
||||
$fileContent .= "\$G_PUBLISH = new Publisher;\n";
|
||||
$fileContent .= "\$G_PUBLISH->AddContent('dynaform', 'xmlform', '" . $processUid . '/' . $dynaFormUid . "', '', array(), '" . $fileName . 'Post.php' . "');\n";
|
||||
$fileContent .= "G::RenderPage('publish', 'blank');";
|
||||
|
||||
file_put_contents($pathProcess . PATH_SEP . $fileName . ".php", $fileContent);
|
||||
|
||||
//Creating the second file, the post file who receive the post form.
|
||||
$pluginTpl = PATH_CORE . "templates" . PATH_SEP . "processes" . PATH_SEP . "webentryPost.tpl";
|
||||
|
||||
$template = new \TemplatePower($pluginTpl);
|
||||
$template->prepare();
|
||||
|
||||
$template->assign("wsdlUrl", $http . $_SERVER["HTTP_HOST"] . "/sys" . SYS_SYS . "/" . SYS_LANG . "/" . SYS_SKIN . "/services/wsdl2");
|
||||
$template->assign("wsUploadUrl", $http . $_SERVER["HTTP_HOST"] . "/sys" . SYS_SYS . "/" . SYS_LANG . "/" . SYS_SKIN . "/services/upload");
|
||||
$template->assign("processUid", $processUid);
|
||||
$template->assign("dynaformUid", $dynaFormUid);
|
||||
$template->assign("taskUid", $taskUid);
|
||||
$template->assign("wsUser", $usrUsername);
|
||||
$template->assign("wsPass", "md5:" . md5($usrPassword));
|
||||
$template->assign("wsRoundRobin", $wsRoundRobin);
|
||||
|
||||
if ($inputDocumentAccess == 0) {
|
||||
//Restricted to process permissions
|
||||
$template->assign("USR_VAR", "\$cInfo = ws_getCaseInfo(\$caseId);\n\t \$USR_UID = \$cInfo->currentUsers->userId;");
|
||||
} else {
|
||||
//No Restriction
|
||||
$template->assign("USR_VAR", "\$USR_UID = -1;");
|
||||
}
|
||||
|
||||
$template->assign("dynaform", $dynTitle);
|
||||
$template->assign("timestamp", date("l jS \of F Y h:i:s A"));
|
||||
$template->assign("ws", SYS_SYS);
|
||||
$template->assign("version", \System::getVersion());
|
||||
|
||||
$fileName = $pathProcess . PATH_SEP . $dynTitle . "Post.php";
|
||||
|
||||
file_put_contents($fileName, $template->getOutputContent());
|
||||
|
||||
//Creating the third file, only if this wsClient.php file doesn't exist.
|
||||
$fileName = $pathProcess . PATH_SEP . "wsClient.php";
|
||||
$pluginTpl = PATH_CORE . "test" . PATH_SEP . "unit" . PATH_SEP . "ws" . PATH_SEP . "wsClient.php";
|
||||
|
||||
if (file_exists($fileName)) {
|
||||
if (filesize($fileName) != filesize($pluginTpl)) {
|
||||
@copy($fileName, $pathProcess . PATH_SEP . "wsClient.php.bck");
|
||||
@unlink($fileName);
|
||||
|
||||
$template = new \TemplatePower($pluginTpl);
|
||||
$template->prepare();
|
||||
|
||||
file_put_contents($fileName, $template->getOutputContent());
|
||||
}
|
||||
} else {
|
||||
$template = new \TemplatePower($pluginTpl);
|
||||
$template->prepare();
|
||||
|
||||
file_put_contents($fileName, $template->getOutputContent());
|
||||
}
|
||||
|
||||
//Event
|
||||
if ($weEventUid != "") {
|
||||
$event = new \Event();
|
||||
|
||||
$arrayEventData = array();
|
||||
|
||||
$arrayEventData["EVN_UID"] = $weEventUid;
|
||||
$arrayEventData["EVN_RELATED_TO"] = "MULTIPLE";
|
||||
$arrayEventData["EVN_ACTION"] = $dynaFormUid;
|
||||
$arrayEventData["EVN_CONDITIONS"] = $usrUsername;
|
||||
|
||||
$result = $event->update($arrayEventData);
|
||||
}
|
||||
|
||||
//Data
|
||||
$url = $http . $_SERVER["HTTP_HOST"] . "/sys" . SYS_SYS . "/" . SYS_LANG . "/" . SYS_SKIN . "/" . $processUid . "/" . $dynTitle . ".php";
|
||||
|
||||
$arrayDataAux = array("URL" => $url);
|
||||
break;
|
||||
case "HTML":
|
||||
global $G_FORM;
|
||||
|
||||
if (! class_exists("Smarty")) {
|
||||
$loader = \Maveriks\Util\ClassLoader::getInstance();
|
||||
$loader->addClass("Smarty", PATH_THIRDPARTY . "smarty".PATH_SEP."libs".PATH_SEP."Smarty.class.php");
|
||||
}
|
||||
|
||||
$G_FORM = new \Form($processUid . "/" . $dynaFormUid, PATH_DYNAFORM, SYS_LANG, false);
|
||||
$G_FORM->action = $http . $_SERVER["HTTP_HOST"] . "/sys" . SYS_SYS . "/" . SYS_LANG . "/" . SYS_SKIN . "/services/cases_StartExternal.php";
|
||||
|
||||
$scriptCode = "";
|
||||
$scriptCode = $G_FORM->render(PATH_CORE . "templates/" . "xmlform" . ".html", $scriptCode);
|
||||
$scriptCode = str_replace("/controls/", $http . $_SERVER["HTTP_HOST"] . "/controls/", $scriptCode);
|
||||
$scriptCode = str_replace("/js/maborak/core/images/", $http . $_SERVER["HTTP_HOST"] . "/js/maborak/core/images/", $scriptCode);
|
||||
|
||||
//Render the template
|
||||
$pluginTpl = PATH_CORE . "templates" . PATH_SEP . "processes" . PATH_SEP . "webentry.tpl";
|
||||
|
||||
$template = new \TemplatePower($pluginTpl);
|
||||
$template->prepare();
|
||||
|
||||
$step = new \Step();
|
||||
$sUidGrids = $step->lookingforUidGrids($processUid, $dynaFormUid);
|
||||
|
||||
$template->assign("URL_MABORAK_JS", \G::browserCacheFilesUrl("/js/maborak/core/maborak.js"));
|
||||
$template->assign("URL_TRANSLATION_ENV_JS", \G::browserCacheFilesUrl("/jscore/labels/" . SYS_LANG . ".js"));
|
||||
$template->assign("siteUrl", $http . $_SERVER["HTTP_HOST"]);
|
||||
$template->assign("sysSys", SYS_SYS);
|
||||
$template->assign("sysLang", SYS_LANG);
|
||||
$template->assign("sysSkin", SYS_SKIN);
|
||||
$template->assign("processUid", $processUid);
|
||||
$template->assign("dynaformUid", $dynaFormUid);
|
||||
$template->assign("taskUid", $taskUid);
|
||||
$template->assign("dynFileName", $processUid . "/" . $dynaFormUid);
|
||||
$template->assign("formId", $G_FORM->id);
|
||||
$template->assign("scriptCode", $scriptCode);
|
||||
|
||||
if (sizeof($sUidGrids) > 0) {
|
||||
foreach ($sUidGrids as $k => $v) {
|
||||
$template->newBlock("grid_uids");
|
||||
$template->assign("siteUrl", $http . $_SERVER["HTTP_HOST"]);
|
||||
$template->assign("gridFileName", $processUid . "/" . $v);
|
||||
}
|
||||
}
|
||||
|
||||
//Data
|
||||
$html = str_replace("</body>", "</form></body>", str_replace("</form>", "", $template->getOutputContent()));
|
||||
|
||||
$arrayDataAux = array("HTML" => $html);
|
||||
break;
|
||||
}
|
||||
|
||||
//Return
|
||||
$arrayData = array_merge($arrayData, $arrayDataAux);
|
||||
|
||||
if (!$this->formatFieldNameInUppercase) {
|
||||
$arrayData = array_change_key_case($arrayData, CASE_LOWER);
|
||||
}
|
||||
|
||||
return $arrayData;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete Web Entry
|
||||
*
|
||||
* @param string $processUid Unique id of Process
|
||||
* @param string $taskUid Unique id of Task
|
||||
* @param string $dynaFormUid Unique id of DynaForm
|
||||
*
|
||||
* return void
|
||||
*/
|
||||
public function delete($processUid, $taskUid, $dynaFormUid)
|
||||
{
|
||||
try {
|
||||
//Verify data
|
||||
//Get data
|
||||
$arrayWebEntryData = $this->getData($processUid, "UID", $taskUid, $dynaFormUid);
|
||||
|
||||
if (count($arrayWebEntryData) == 0) {
|
||||
throw (new \Exception("The Web Entry doesn't exist"));
|
||||
}
|
||||
|
||||
//Delete
|
||||
$webEntryPath = PATH_DATA . "sites" . PATH_SEP . SYS_SYS . PATH_SEP . "public" . PATH_SEP . $processUid;
|
||||
|
||||
unlink($webEntryPath . PATH_SEP . $arrayWebEntryData[$taskUid . "/" . $dynaFormUid]["fileName"] . ".php");
|
||||
unlink($webEntryPath . PATH_SEP . $arrayWebEntryData[$taskUid . "/" . $dynaFormUid]["fileName"] . "Post.php");
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data of a Web Entry from a record
|
||||
*
|
||||
* @param array $record Record
|
||||
*
|
||||
* return array Return an array with data of a Web Entry
|
||||
*/
|
||||
public function getWebEntryDataFromRecord($record)
|
||||
{
|
||||
try {
|
||||
return array(
|
||||
$this->getFieldNameByFormatFieldName("TAS_UID") => $record["taskUid"],
|
||||
$this->getFieldNameByFormatFieldName("TAS_TITLE") => $record["taskTitle"],
|
||||
$this->getFieldNameByFormatFieldName("DYN_UID") => $record["dynaFormUid"],
|
||||
$this->getFieldNameByFormatFieldName("DYN_TITLE") => $record["dynaFormTitle"],
|
||||
$this->getFieldNameByFormatFieldName("URL") => $record["url"]
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data of a Web Entry
|
||||
*
|
||||
* @param string $processUid Unique id of Process
|
||||
* @param string $taskUid Unique id of Task
|
||||
* @param string $dynaFormUid Unique id of DynaForm
|
||||
*
|
||||
* return array Return an array with data of a Web Entry
|
||||
*/
|
||||
public function getWebEntry($processUid, $taskUid, $dynaFormUid)
|
||||
{
|
||||
try {
|
||||
//Verify data
|
||||
//Get data
|
||||
$arrayWebEntryData = $this->getData($processUid, "UID", $taskUid, $dynaFormUid);
|
||||
|
||||
if (count($arrayWebEntryData) == 0) {
|
||||
throw (new \Exception("The Web Entry doesn't exist"));
|
||||
}
|
||||
|
||||
//Return
|
||||
return $this->getWebEntryDataFromRecord($arrayWebEntryData[$taskUid . "/" . $dynaFormUid]);
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user