Merged in victorsl/processmaker (pull request #156)

ProcessMaker-MA "Dynaforms Resources (Fixes)"
This commit is contained in:
erik ao
2014-02-06 15:58:55 -04:00
7 changed files with 467 additions and 341 deletions

View File

@@ -91,14 +91,6 @@ Feature: Dynaform Main Tests
{ {
"fld_name": "<fld_name_01>", "fld_name": "<fld_name_01>",
"pro_variable": "<pro_variable_01>" "pro_variable": "<pro_variable_01>"
},
{
"fld_name": "<fld_name_02>",
"pro_variable": "<pro_variable_02>"
},
{
"fld_name": "<fld_name_03",
"pro_variable": "<pro_variable_03>"
} }
] ]
} }
@@ -113,9 +105,9 @@ Feature: Dynaform Main Tests
Examples: Examples:
| test_description | project | dyn_title | dyn_description | dyn_type | dyn_uid_number | tab_uid | fld_name_01 | pro_variable_01 | fld_name_02 | pro_variable_02 | fld_name_03 | pro_variable_03 | | test_description | project | dyn_title | dyn_description | dyn_type | dyn_uid_number | tab_uid | fld_name_01 | pro_variable_01 |
| create dynaform pmtable 1 | 14414793652a5d718b65590036026581 | Dynaform - pmtable 1 | dyn from pmtable1 | xmlform | 7 | 65193158852cc1a93a5a535084878044 | DYN_UID | @#APPLICATION | DYN_TITLE | @#TITLE | DYN_DESCRIPTION | @#DESCRIPTION | | create dynaform pmtable 1 | 14414793652a5d718b65590036026581 | Dynaform - pmtable 1 | dyn from pmtable1 | xmlform | 7 | 65193158852cc1a93a5a535084878044 | DYN_UID | @#APPLICATION |
| create dynaform pmtable 2 | 42445320652cd534acb3824056962285 | Dynaform - pmtable2 | dyn from pmtable2 | xmlform | 8 | 65193158852cc1a93a5a535084878044 | DYN_UID | @#APPLICATION | DYN_TITLE | @#TITLE | DYN_DESCRIPTION | @#DESCRIPTION | | create dynaform pmtable 2 | 42445320652cd534acb3824056962285 | Dynaform - pmtable2 | dyn from pmtable2 | xmlform | 8 | 65193158852cc1a93a5a535084878044 | DYN_UID | @#APPLICATION |
Scenario Outline: Get a List DynaForms of a Project list when there are 9 records, total in both projects Scenario Outline: Get a List DynaForms of a Project list when there are 9 records, total in both projects

View File

@@ -48,8 +48,8 @@ Scenario Outline: Normal Dynaform creation for a project with bad parameters (ne
Examples: Examples:
| test_description | project | dyn_title | dyn_description | dyn_type | copy_prj_uid | copy_dyn_uid | error_code | error_message | | test_description | project | dyn_title | dyn_description | dyn_type | copy_prj_uid | copy_dyn_uid | error_code | error_message |
| invalid copy_prj_uid | 14414793652a5d718b65590036026581 | Dynaform - Copy 1 | dyn copy | xmlform | 42445320652cd0000000000000000085 | 70070685552cd53605650f7062918505 | 400 | copy_prj_uid | | invalid copy_prj_uid | 14414793652a5d718b65590036026581 | Dynaform - Copy 1 | dyn copy | xmlform | 42445320652cd0000000000000000085 | 70070685552cd53605650f7062918505 | 400 | copy_import.prj_uid |
| invalid copy_dyn_uid | 42445320652cd534acb3824056962285 | Dynaform - Copy 2 | dyn copy | xmlform | 14414793652a5d718b65590036026581 | 70070685500000000000000000000000 | 400 | copy_dyn_uid | | invalid copy_dyn_uid | 42445320652cd534acb3824056962285 | Dynaform - Copy 2 | dyn copy | xmlform | 14414793652a5d718b65590036026581 | 70070685500000000000000000000000 | 400 | copy_import.dyn_uid |
Scenario Outline: Create dynaform based on a PMTable for a project with bad parameters (negative tests) Scenario Outline: Create dynaform based on a PMTable for a project with bad parameters (negative tests)
@@ -87,4 +87,4 @@ Scenario Outline: Normal Dynaform creation for a project with bad parameters (ne
| test_description | project | dyn_title | dyn_description | dyn_type | tab_uid | fld_name_01 | pro_variable_01 | fld_name_02 | pro_variable_02 | fld_name_03 | pro_variable_03 | error_code | error_message | | test_description | project | dyn_title | dyn_description | dyn_type | tab_uid | fld_name_01 | pro_variable_01 | fld_name_02 | pro_variable_02 | fld_name_03 | pro_variable_03 | error_code | error_message |
| invalid tab_uid | 14414793652a5d718b65590036026581 | Dynaform - pmtable 1 | dyn from pmtable | xmlform | 65193158852cc1a00000000000000000 | DYN_UID | @#APPLICATION | DYN_TITLE | @#TITLE | DYN_DESCRIPTION | @#DESCRIPTION | 400 | tab_uid | | invalid tab_uid | 14414793652a5d718b65590036026581 | Dynaform - pmtable 1 | dyn from pmtable | xmlform | 65193158852cc1a00000000000000000 | DYN_UID | @#APPLICATION | DYN_TITLE | @#TITLE | DYN_DESCRIPTION | @#DESCRIPTION | 400 | tab_uid |
| invalid fld_name_01 | 42445320652cd534acb3824056962285 | Dynaform - pmtable 2 | dyn from pmtable | xmlform | 65193158852cc1a93a5a535084878044 | DYN_INPUT | @#APPLICATION | DYN_TITLE | @#TITLE | DYN_DESCRIPTION | @#DESCRIPTION | 400 | fld_name_01 | | invalid fld_name_01 | 42445320652cd534acb3824056962285 | Dynaform - pmtable 2 | dyn from pmtable | xmlform | 65193158852cc1a93a5a535084878044 | DYN_INPUT | @#APPLICATION | DYN_TITLE | @#TITLE | DYN_DESCRIPTION | @#DESCRIPTION | 400 | fld_name |

View File

@@ -374,7 +374,7 @@ class Step extends BaseStep
while ($oDataset->next()) { while ($oDataset->next()) {
$aRow1 = $oDataset->getRow(); $aRow1 = $oDataset->getRow();
//print_r($aRow1); //print_r($aRow1);
$dynHandler = new dynaFormHandler( PATH_DYNAFORM . $_POST['PRO_UID'] . "/" . $aRow1['DYN_UID'] . ".xml" ); $dynHandler = new dynaFormHandler(PATH_DYNAFORM . $sproUid . PATH_SEP . $aRow1["DYN_UID"] . ".xml");
$dynFields = $dynHandler->getFields(); $dynFields = $dynHandler->getFields();
$sxmlgrid = ''; $sxmlgrid = '';
$sType = ''; $sType = '';

View File

@@ -3,28 +3,30 @@ namespace BusinessModel;
class DynaForm class DynaForm
{ {
private $arrayFieldDefinition = array(
"DYN_UID" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "dynaFormUid"),
"DYN_TITLE" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "dynaFormTitle"),
"DYN_DESCRIPTION" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "dynaFormDescription"),
"DYN_TYPE" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array("xmlform", "grid"), "fieldNameAux" => "dynaFormType")
);
private $formatFieldNameInUppercase = true;
private $arrayFieldNameForException = array(
"processUid" => "PRO_UID"
);
/** /**
* Get data of unique ids of a DynaForm (Unique id of Process) * Constructor of the class
* *
* @param string $dynaFormUid Unique id of DynaForm * return void
*
* return array
*/ */
public function getDataUids($dynaFormUid) public function __construct()
{ {
try { try {
$criteria = new \Criteria("workflow"); foreach ($this->arrayFieldDefinition as $key => $value) {
$this->arrayFieldNameForException[$value["fieldNameAux"]] = $key;
$criteria->addSelectColumn(\DynaformPeer::PRO_UID);
$criteria->add(\DynaformPeer::DYN_UID, $dynaFormUid, \Criteria::EQUAL);
$rsCriteria = \DynaformPeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
if ($rsCriteria->next()) {
return $rsCriteria->getRow();
} else {
throw (new \Exception(str_replace(array("{0}", "{1}"), array($dynaFormUid, "DYNAFORM"), "The UID \"{0}\" doesn't exist in table {1}")));
} }
} catch (\Exception $e) { } catch (\Exception $e) {
throw $e; throw $e;
@@ -32,15 +34,67 @@ class DynaForm
} }
/** /**
* Verify if the title exists in the DynaForms of Process * 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 DynaForm
* *
* @param string $processUid Unique id of Process * @param string $processUid Unique id of Process
* @param string $title Title * @param string $dynaFormTitle Title
* @param string $dynaFormUidExclude Unique id of DynaForm to exclude * @param string $dynaFormUidExclude Unique id of DynaForm to exclude
* *
* return bool Return true if the title exists in the DynaForms of Process, false otherwise * return bool Return true if exists the title of a DynaForm, false otherwise
*/ */
public function titleExists($processUid, $title, $dynaFormUidExclude = "") public function existsTitle($processUid, $dynaFormTitle, $dynaFormUidExclude = "")
{ {
try { try {
$delimiter = \DBAdapter::getStringDelimiter(); $delimiter = \DBAdapter::getStringDelimiter();
@@ -63,37 +117,7 @@ class DynaForm
$criteria->add(\DynaformPeer::DYN_UID, $dynaFormUidExclude, \Criteria::NOT_EQUAL); $criteria->add(\DynaformPeer::DYN_UID, $dynaFormUidExclude, \Criteria::NOT_EQUAL);
} }
$criteria->add("CT.CON_VALUE", $title, \Criteria::EQUAL); $criteria->add("CT.CON_VALUE", $dynaFormTitle, \Criteria::EQUAL);
$rsCriteria = \DynaformPeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
if ($rsCriteria->next()) {
return true;
} else {
return false;
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Verify if a DynaForm belongs to Process
*
* @param string $dynaFormUid Unique id of DynaForm
* @param string $processUid Unique id of Process
*
* return bool Return true if a DynaForm belongs to Process, false otherwise
*/
public function dynaFormBelongsProcess($dynaFormUid, $processUid)
{
try {
$criteria = new \Criteria("workflow");
$criteria->addSelectColumn(\DynaformPeer::DYN_UID);
$criteria->add(\DynaformPeer::DYN_UID, $dynaFormUid, \Criteria::EQUAL);
$criteria->add(\DynaformPeer::PRO_UID, $processUid, \Criteria::EQUAL);
$rsCriteria = \DynaformPeer::doSelectRS($criteria); $rsCriteria = \DynaformPeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC); $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
@@ -158,24 +182,23 @@ class DynaForm
} }
/** /**
* Get data from a request data * Verify if exists the title of a DynaForm
* *
* @param object $requestData Request data * @param string $processUid Unique id of Process
* @param string $dynaFormTitle Title
* @param string $fieldNameForException Field name for the exception
* @param string $dynaFormUidExclude Unique id of DynaForm to exclude
* *
* return array Return an array with data of request data * return void Throw exception if exists the title of a DynaForm
*/ */
public function getArrayDataFromRequestData($requestData) public function throwExceptionIfExistsTitle($processUid, $dynaFormTitle, $fieldNameForException, $dynaFormUidExclude = "")
{ {
try { try {
$arrayData = array(); if ($this->existsTitle($processUid, $dynaFormTitle, $dynaFormUidExclude)) {
$msg = str_replace(array("{0}", "{1}"), array($fieldNameForException, $dynaFormTitle), "The DynaForm title with {0}: \"{1}\", already exists");
$requestData = (array)($requestData); throw (new \Exception($msg));
foreach ($requestData as $key => $value) {
$arrayData[$key] = $value;
} }
return $arrayData;
} catch (\Exception $e) { } catch (\Exception $e) {
throw $e; throw $e;
} }
@@ -199,15 +222,13 @@ class DynaForm
unset($arrayData["PMTABLE"]); unset($arrayData["PMTABLE"]);
//Verify data //Verify data
$process = new \Process(); $process = new \BusinessModel\Process();
if (!$process->exists($processUid)) { $process->throwExceptionIfNoExistsProcess($processUid, $this->arrayFieldNameForException["processUid"]);
throw (new \Exception(str_replace(array("{0}", "{1}"), array($processUid, "PROCESS"), "The UID \"{0}\" doesn't exist in table {1}")));
}
if (isset($arrayData["DYN_TITLE"]) && $this->titleExists($processUid, $arrayData["DYN_TITLE"])) { $process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $this->arrayFieldDefinition, $this->arrayFieldNameForException, true);
throw (new \Exception(\G::LoadTranslation("ID_EXIST_DYNAFORM")));
} $this->throwExceptionIfExistsTitle($processUid, $arrayData["DYN_TITLE"], $this->arrayFieldNameForException["dynaFormTitle"]);
//Create //Create
$dynaForm = new \Dynaform(); $dynaForm = new \Dynaform();
@@ -219,11 +240,13 @@ class DynaForm
//Return //Return
unset($arrayData["PRO_UID"]); unset($arrayData["PRO_UID"]);
$arrayData = array_merge(array("DYN_UID" => $dynaFormUid), $arrayData);
if (!$this->formatFieldNameInUppercase) {
$arrayData = array_change_key_case($arrayData, CASE_LOWER); $arrayData = array_change_key_case($arrayData, CASE_LOWER);
}
unset($arrayData["dyn_uid"]); return $arrayData;
return array_merge(array("dyn_uid" => $dynaFormUid), $arrayData);
} catch (\Exception $e) { } catch (\Exception $e) {
throw $e; throw $e;
} }
@@ -242,20 +265,23 @@ class DynaForm
try { try {
$arrayData = array_change_key_case($arrayData, CASE_UPPER); $arrayData = array_change_key_case($arrayData, CASE_UPPER);
//Uids
$arrayDataUid = $this->getDataUids($dynaFormUid);
$processUid = $arrayDataUid["PRO_UID"];
//Verify data //Verify data
$process = new \BusinessModel\Process();
$process->throwExceptionIfNotExistsDynaForm("", $dynaFormUid, $this->arrayFieldNameForException["dynaFormUid"]);
//Load DynaForm
$dynaForm = new \Dynaform(); $dynaForm = new \Dynaform();
if (!$dynaForm->dynaformExists($dynaFormUid)) { $arrayDynaFormData = $dynaForm->Load($dynaFormUid);
throw (new \Exception(str_replace(array("{0}", "{1}"), array($dynaFormUid, "DYNAFORM"), "The UID \"{0}\" doesn't exist in table {1}")));
}
if (isset($arrayData["DYN_TITLE"]) && $this->titleExists($processUid, $arrayData["DYN_TITLE"], $dynaFormUid)) { $processUid = $arrayDynaFormData["PRO_UID"];
throw (new \Exception(\G::LoadTranslation("ID_EXIST_DYNAFORM")));
//Verify data
$process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $this->arrayFieldDefinition, $this->arrayFieldNameForException, false);
if (isset($arrayData["DYN_TITLE"])) {
$this->throwExceptionIfExistsTitle($processUid, $arrayData["DYN_TITLE"], $this->arrayFieldNameForException["dynaFormTitle"], $dynaFormUid);
} }
//Update //Update
@@ -266,7 +292,11 @@ class DynaForm
//Return //Return
unset($arrayData["DYN_UID"]); unset($arrayData["DYN_UID"]);
return array_change_key_case($arrayData, CASE_LOWER); if (!$this->formatFieldNameInUppercase) {
$arrayData = array_change_key_case($arrayData, CASE_LOWER);
}
return $arrayData;
} catch (\Exception $e) { } catch (\Exception $e) {
throw $e; throw $e;
} }
@@ -282,18 +312,19 @@ class DynaForm
public function delete($dynaFormUid) public function delete($dynaFormUid)
{ {
try { try {
//Uids
$arrayDataUid = $this->getDataUids($dynaFormUid);
$processUid = $arrayDataUid["PRO_UID"];
//Verify data //Verify data
$process = new \BusinessModel\Process();
$process->throwExceptionIfNotExistsDynaForm("", $dynaFormUid, $this->arrayFieldNameForException["dynaFormUid"]);
//Load DynaForm
$dynaForm = new \Dynaform(); $dynaForm = new \Dynaform();
if (!$dynaForm->dynaformExists($dynaFormUid)) { $arrayDynaFormData = $dynaForm->Load($dynaFormUid);
throw (new \Exception(str_replace(array("{0}", "{1}"), array($dynaFormUid, "DYNAFORM"), "The UID \"{0}\" doesn't exist in table {1}")));
}
$processUid = $arrayDynaFormData["PRO_UID"];
//Verify data
if ($this->dynaFormAssignedStep($dynaFormUid, $processUid)) { if ($this->dynaFormAssignedStep($dynaFormUid, $processUid)) {
throw (new \Exception("You cannot delete this Dynaform while it is assigned to a step")); throw (new \Exception("You cannot delete this Dynaform while it is assigned to a step"));
} }
@@ -335,47 +366,56 @@ class DynaForm
try { try {
$arrayData = \G::array_change_key_case2($arrayData, CASE_UPPER); $arrayData = \G::array_change_key_case2($arrayData, CASE_UPPER);
unset($arrayData["DYN_UID"]);
unset($arrayData["PMTABLE"]);
//Verify data //Verify data
$process = new \BusinessModel\Process();
$process->throwExceptionIfNoExistsProcess($processUid, $this->arrayFieldNameForException["processUid"]);
$process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $this->arrayFieldDefinition, $this->arrayFieldNameForException, true);
if (!isset($arrayData["COPY_IMPORT"])) {
throw (new \Exception(str_replace(array("{0}"), array($this->getFieldNameByFormatFieldName("COPY_IMPORT")), "The \"{0}\" attribute is not defined")));
}
if (!isset($arrayData["COPY_IMPORT"]["PRJ_UID"])) { if (!isset($arrayData["COPY_IMPORT"]["PRJ_UID"])) {
throw (new \Exception(str_replace(array("{0}"), array("PRJ_UID"), "For the creation the DynaForm, the attribute \"{0}\" doesn't exist"))); throw (new \Exception(str_replace(array("{0}"), array($this->getFieldNameByFormatFieldName("COPY_IMPORT.PRJ_UID")), "The \"{0}\" attribute is not defined")));
}
$arrayData["COPY_IMPORT"]["PRJ_UID"] = trim($arrayData["COPY_IMPORT"]["PRJ_UID"]);
if ($arrayData["COPY_IMPORT"]["PRJ_UID"] == "") {
throw (new \Exception(str_replace(array("{0}"), array($this->getFieldNameByFormatFieldName("COPY_IMPORT.PRJ_UID")), "The \"{0}\" attribute is empty")));
} }
if (!isset($arrayData["COPY_IMPORT"]["DYN_UID"])) { if (!isset($arrayData["COPY_IMPORT"]["DYN_UID"])) {
throw (new \Exception(str_replace(array("{0}"), array("DYN_UID"), "For the creation the DynaForm, the attribute \"{0}\" doesn't exist"))); throw (new \Exception(str_replace(array("{0}"), array($this->getFieldNameByFormatFieldName("COPY_IMPORT.DYN_UID")), "The \"{0}\" attribute is not defined")));
} }
$arrayData["COPY_IMPORT"]["DYN_UID"] = trim($arrayData["COPY_IMPORT"]["DYN_UID"]);
if ($arrayData["COPY_IMPORT"]["DYN_UID"] == "") {
throw (new \Exception(str_replace(array("{0}"), array($this->getFieldNameByFormatFieldName("COPY_IMPORT.DYN_UID")), "The \"{0}\" attribute is empty")));
}
$this->throwExceptionIfExistsTitle($processUid, $arrayData["DYN_TITLE"], $this->arrayFieldNameForException["dynaFormTitle"]);
//Copy/Import Uids //Copy/Import Uids
$processUidCopyImport = $arrayData["COPY_IMPORT"]["PRJ_UID"]; $processUidCopyImport = $arrayData["COPY_IMPORT"]["PRJ_UID"];
$dynaFormUidCopyImport = $arrayData["COPY_IMPORT"]["DYN_UID"]; $dynaFormUidCopyImport = $arrayData["COPY_IMPORT"]["DYN_UID"];
unset($arrayData["COPY_IMPORT"]);
//Verify data //Verify data
$process = new \Process(); $process->throwExceptionIfNoExistsProcess($processUidCopyImport, $this->getFieldNameByFormatFieldName("COPY_IMPORT.PRJ_UID"));
if (!$process->exists($processUid)) { $process->throwExceptionIfNotExistsDynaForm($processUidCopyImport, $dynaFormUidCopyImport, $this->getFieldNameByFormatFieldName("COPY_IMPORT.DYN_UID"));
throw (new \Exception(str_replace(array("{0}", "{1}"), array($processUid, "PROCESS"), "The UID \"{0}\" doesn't exist in table {1}")));
}
if (!$process->exists($processUidCopyImport)) {
throw (new \Exception(str_replace(array("{0}", "{1}"), array($processUidCopyImport, "PROCESS"), "The UID \"{0}\" doesn't exist in table {1}")));
}
$dynaForm = new \Dynaform();
if (!$dynaForm->dynaformExists($dynaFormUidCopyImport)) {
throw (new \Exception(str_replace(array("{0}", "{1}"), array($dynaFormUidCopyImport, "DYNAFORM"), "The UID \"{0}\" doesn't exist in table {1}")));
}
if (!$this->dynaFormBelongsProcess($dynaFormUidCopyImport, $processUidCopyImport)) {
throw (new \Exception("The DynaForm for Copy/Import doesn't belongs to the Process"));
}
//Copy/Import //Copy/Import
//Create //Create
$arrayData = $this->create($processUid, $arrayData); $arrayData = $this->create($processUid, $arrayData);
$dynaFormUid = $arrayData["dyn_uid"]; $dynaFormUid = $arrayData[$this->getFieldNameByFormatFieldName("DYN_UID")];
//Copy files of the DynaForm //Copy files of the DynaForm
$umaskOld = umask(0); $umaskOld = umask(0);
@@ -533,35 +573,100 @@ class DynaForm
unset($arrayData["COPY_IMPORT"]); unset($arrayData["COPY_IMPORT"]);
//Verify data //Verify data
$process = new \BusinessModel\Process();
$process->throwExceptionIfNoExistsProcess($processUid, $this->arrayFieldNameForException["processUid"]);
$process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $this->arrayFieldDefinition, $this->arrayFieldNameForException, true);
if ($arrayData["DYN_TYPE"] == "grid") {
throw (new \Exception(str_replace(array("{0}"), array($this->arrayFieldNameForException["dynaFormType"]), "Invalid value specified for \"{0}\"")));
}
if (!isset($arrayData["PMTABLE"])) {
throw (new \Exception(str_replace(array("{0}"), array($this->getFieldNameByFormatFieldName("PMTABLE")), "The \"{0}\" attribute is not defined")));
}
if (!isset($arrayData["PMTABLE"]["TAB_UID"])) { if (!isset($arrayData["PMTABLE"]["TAB_UID"])) {
throw (new \Exception(str_replace(array("{0}"), array("TAB_UID"), "For the creation the DynaForm, the attribute \"{0}\" doesn't exist"))); throw (new \Exception(str_replace(array("{0}"), array($this->getFieldNameByFormatFieldName("PMTABLE.TAB_UID")), "The \"{0}\" attribute is not defined")));
}
$arrayData["PMTABLE"]["TAB_UID"] = trim($arrayData["PMTABLE"]["TAB_UID"]);
if ($arrayData["PMTABLE"]["TAB_UID"] == "") {
throw (new \Exception(str_replace(array("{0}"), array($this->getFieldNameByFormatFieldName("PMTABLE.TAB_UID")), "The \"{0}\" attribute is empty")));
} }
if (!isset($arrayData["PMTABLE"]["FIELDS"])) { if (!isset($arrayData["PMTABLE"]["FIELDS"])) {
throw (new \Exception(str_replace(array("{0}"), array("FIELDS"), "For the creation the DynaForm, the attribute \"{0}\" doesn't exist"))); throw (new \Exception(str_replace(array("{0}"), array($this->getFieldNameByFormatFieldName("PMTABLE.FIELDS")), "The \"{0}\" attribute is not defined")));
} }
if (count($arrayData["PMTABLE"]["FIELDS"]) == 0) { if (count($arrayData["PMTABLE"]["FIELDS"]) == 0) {
throw (new \Exception(str_replace(array("{0}"), array("FIELDS"), "For the creation the DynaForm, the attribute \"{0}\" is empty"))); throw (new \Exception(str_replace(array("{0}"), array($this->getFieldNameByFormatFieldName("PMTABLE.FIELDS")), "The \"{0}\" attribute is empty")));
} }
//Verify data $this->throwExceptionIfExistsTitle($processUid, $arrayData["DYN_TITLE"], $this->arrayFieldNameForException["dynaFormTitle"]);
$process = new \Process();
if (!$process->exists($processUid)) { $process->throwExceptionIfNotExistsPmTable($arrayData["PMTABLE"]["TAB_UID"], $this->getFieldNameByFormatFieldName("PMTABLE.TAB_UID"));
throw (new \Exception(str_replace(array("{0}", "{1}"), array($processUid, "PROCESS"), "The UID \"{0}\" doesn't exist in table {1}")));
//Validate PMTABLE.FIELDS
//Valid Keys
$flagValidFieldKey = 1;
foreach ($arrayData["PMTABLE"]["FIELDS"] as $key => $value) {
if (!isset($value["FLD_NAME"]) || !isset($value["PRO_VARIABLE"])) {
$flagValidFieldKey = 0;
break;
}
} }
if (isset($arrayData["DYN_TITLE"]) && $this->titleExists($processUid, $arrayData["DYN_TITLE"])) { if ($flagValidFieldKey == 0) {
throw (new \Exception(\G::LoadTranslation("ID_EXIST_DYNAFORM"))); throw (new \Exception(str_replace(array("{0}"), array($this->getFieldNameByFormatFieldName("PMTABLE.FIELDS")), "The attribute {0}, has an element invalid (incorrect keys)")));
} }
if (isset($arrayData["DYN_TYPE"]) && $arrayData["DYN_TYPE"] == "grid") { //Is Primary Key
throw (new \Exception(str_replace(array("{0}"), array("DYN_TYPE"), "For the creation the DynaForm, the attribute \"{0}\" is invalid"))); $arrayFieldPk = $process->getPmTablePrimaryKeyFields($arrayData["PMTABLE"]["TAB_UID"], $this->getFieldNameByFormatFieldName("PMTABLE.TAB_UID"));
$flagValidFieldPk = 1;
$invalidFieldPk = "";
$arrayFieldPkAux = array();
foreach ($arrayData["PMTABLE"]["FIELDS"] as $key => $value) {
$arrayFieldPkAux[] = $value["FLD_NAME"];
if (!in_array($value["FLD_NAME"], $arrayFieldPk)) {
$flagValidFieldPk = 0;
$invalidFieldPk = $value["FLD_NAME"];
break;
}
} }
if (is_null(\AdditionalTablesPeer::retrieveByPK($arrayData["PMTABLE"]["TAB_UID"]))) { if ($flagValidFieldPk == 0) {
throw (new \Exception(str_replace(array("{0}", "{1}"), array($arrayData["PMTABLE"]["TAB_UID"], "ADDITIONAL_TABLES"), "The UID \"{0}\" doesn't exist in table {1}"))); throw (new \Exception(str_replace(array("{0}", "{1}"), array($this->getFieldNameByFormatFieldName("PMTABLE.FIELDS.FLD_NAME"), $invalidFieldPk), "The field {0}: {1}, is not an primary key field of the PM Table")));
}
//All Primary Keys
$flagAllFieldPk = 1;
$missingFieldPk = "";
foreach ($arrayFieldPk as $key => $value) {
if (!in_array($value, $arrayFieldPkAux)) {
$flagAllFieldPk = 0;
$missingFieldPk = $value;
break;
}
}
if ($flagAllFieldPk == 0) {
throw (new \Exception(str_replace(array("{0}", "{1}"), array($missingFieldPk, $this->getFieldNameByFormatFieldName("PMTABLE.FIELDS")), "The primary key field {0} of the PM Table, is missing in the attribute {1}")));
}
//Total of Primary Keys
$n1 = count($arrayFieldPk);
$n2 = count($arrayFieldPkAux);
if ($n1 != $n2) {
throw (new \Exception(str_replace(array("{0}", "{1}", "{2}"), array($n1, $this->getFieldNameByFormatFieldName("PMTABLE.FIELDS"), $n2), "The total primary key fields of the PM Table is {0}, the attribute {1} has {2} primary keys")));
} }
//Set data //Set data
@@ -585,11 +690,13 @@ class DynaForm
unset($arrayData["PRO_UID"]); unset($arrayData["PRO_UID"]);
unset($arrayData["FIELDS"]); unset($arrayData["FIELDS"]);
$arrayData = \G::array_change_key_case2($arrayData, CASE_LOWER); $arrayData = array_merge(array("DYN_UID" => $dynaFormUid), $arrayData);
unset($arrayData["dyn_uid"]); if (!$this->formatFieldNameInUppercase) {
$arrayData = array_change_key_case($arrayData, CASE_LOWER);
}
return array_merge(array("dyn_uid" => $dynaFormUid), $arrayData); return $arrayData;
} catch (\Exception $e) { } catch (\Exception $e) {
throw $e; throw $e;
} }
@@ -606,22 +713,24 @@ class DynaForm
public function defineCreate($processUid, $arrayData) public function defineCreate($processUid, $arrayData)
{ {
try { try {
$arrayData = array_change_key_case($arrayData, CASE_UPPER);
$option = "NORMAL"; $option = "NORMAL";
//Validate data //Validate data
$count = 0; $count = 0;
$msgMethod = ""; $msgMethod = "";
if (isset($arrayData["copy_import"])) { if (isset($arrayData["COPY_IMPORT"])) {
$count = $count + 1; $count = $count + 1;
$msgMethod = (($msgMethod != "")? ", " : "") . $msgMethod . "COPY_IMPORT"; $msgMethod = $msgMethod . (($msgMethod != "")? ", " : "") . "COPY_IMPORT";
$option = "COPY_IMPORT"; $option = "COPY_IMPORT";
} }
if (isset($arrayData["pmtable"])) { if (isset($arrayData["PMTABLE"])) {
$count = $count + 1; $count = $count + 1;
$msgMethod = (($msgMethod != "")? ", " : "") . $msgMethod . "PMTABLE"; $msgMethod = $msgMethod . (($msgMethod != "")? ", " : "") . "PMTABLE";
$option = "PMTABLE"; $option = "PMTABLE";
} }
@@ -645,7 +754,7 @@ class DynaForm
//Return //Return
return $arrayDataAux; return $arrayDataAux;
} else { } else {
throw (new \Exception(str_replace(array("{0}"), array($msgMethod), "It is trying to create a DynaForm by \"{0}\", please send only one attribute for creation"))); throw (new \Exception(str_replace(array("{0}"), array($this->getFieldNameByFormatFieldName($msgMethod)), "It is trying to create a DynaForm by \"{0}\", please send only one attribute for creation")));
} }
} catch (\Exception $e) { } catch (\Exception $e) {
throw $e; throw $e;
@@ -695,7 +804,7 @@ class DynaForm
* *
* @param array $record Record * @param array $record Record
* *
* return array Return an array with data of a DynaForm * return array Return an array with data DynaForm
*/ */
public function getDynaFormDataFromRecord($record) public function getDynaFormDataFromRecord($record)
{ {
@@ -711,10 +820,10 @@ class DynaForm
} }
return array( return array(
"dyn_uid" => $record["DYN_UID"], $this->getFieldNameByFormatFieldName("DYN_UID") => $record["DYN_UID"],
"dyn_title" => $record["DYN_TITLE"], $this->getFieldNameByFormatFieldName("DYN_TITLE") => $record["DYN_TITLE"],
"dyn_description" => $record["DYN_DESCRIPTION"] . "", $this->getFieldNameByFormatFieldName("DYN_DESCRIPTION") => $record["DYN_DESCRIPTION"] . "",
"dyn_type" => $record["DYN_TYPE"] . "" $this->getFieldNameByFormatFieldName("DYN_TYPE") => $record["DYN_TYPE"] . ""
); );
} catch (\Exception $e) { } catch (\Exception $e) {
throw $e; throw $e;
@@ -732,11 +841,9 @@ class DynaForm
{ {
try { try {
//Verify data //Verify data
$dynaForm = new \Dynaform(); $process = new \BusinessModel\Process();
if (!$dynaForm->dynaformExists($dynaFormUid)) { $process->throwExceptionIfNotExistsDynaForm("", $dynaFormUid, $this->arrayFieldNameForException["dynaFormUid"]);
throw (new \Exception(str_replace(array("{0}", "{1}"), array($dynaFormUid, "DYNAFORM"), "The UID \"{0}\" doesn't exist in table {1}")));
}
//Get data //Get data
$criteria = $this->getDynaFormCriteria(); $criteria = $this->getDynaFormCriteria();
@@ -750,6 +857,7 @@ class DynaForm
$row = $rsCriteria->getRow(); $row = $rsCriteria->getRow();
//Return
return $this->getDynaFormDataFromRecord($row); return $this->getDynaFormDataFromRecord($row);
} catch (\Exception $e) { } catch (\Exception $e) {
throw $e; throw $e;

View File

@@ -4,40 +4,58 @@ namespace BusinessModel;
class Process class Process
{ {
private $arrayFieldDefinition = array( private $arrayFieldDefinition = array(
"processUid" => array("fieldName" => "PRO_UID", "type" => "string", "required" => false, "empty" => false, "defaultValues" => array()), "PRO_UID" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "processUid"),
"processTitle" => array("fieldName" => "PRO_TITLE", "type" => "string", "required" => true, "empty" => false, "defaultValues" => array()), "PRO_TITLE" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "processTitle"),
"processDescription" => array("fieldName" => "PRO_DESCRIPTION", "type" => "string", "required" => false, "empty" => true, "defaultValues" => array()), "PRO_DESCRIPTION" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "processDescription"),
"processParent" => array("fieldName" => "PRO_PARENT", "type" => "string", "required" => true, "empty" => false, "defaultValues" => array()), "PRO_PARENT" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "processParent"),
"processTime" => array("fieldName" => "PRO_TIME", "type" => "int", "required" => false, "empty" => false, "defaultValues" => array(1)), "PRO_TIME" => array("type" => "int", "required" => false, "empty" => false, "defaultValues" => array(1), "fieldNameAux" => "processTime"),
"processTimeunit" => array("fieldName" => "PRO_TIMEUNIT", "type" => "string", "required" => false, "empty" => false, "defaultValues" => array("DAYS")), "PRO_TIMEUNIT" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array("DAYS"), "fieldNameAux" => "processTimeunit"),
"processStatus" => array("fieldName" => "PRO_STATUS", "type" => "string", "required" => true, "empty" => false, "defaultValues" => array("ACTIVE", "INACTIVE")), "PRO_STATUS" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array("ACTIVE", "INACTIVE"), "fieldNameAux" => "processStatus"),
"processTypeDay" => array("fieldName" => "PRO_TYPE_DAY", "type" => "string", "required" => false, "empty" => true, "defaultValues" => array()), "PRO_TYPE_DAY" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "processTypeDay"),
"processType" => array("fieldName" => "PRO_TYPE", "type" => "string", "required" => false, "empty" => false, "defaultValues" => array("NORMAL")), "PRO_TYPE" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array("NORMAL"), "fieldNameAux" => "processType"),
"processAssignment" => array("fieldName" => "PRO_ASSIGNMENT", "type" => "int", "required" => false, "empty" => false, "defaultValues" => array(0, 1)), "PRO_ASSIGNMENT" => array("type" => "int", "required" => false, "empty" => false, "defaultValues" => array(0, 1), "fieldNameAux" => "processAssignment"),
"processShowMap" => array("fieldName" => "PRO_SHOW_MAP", "type" => "int", "required" => false, "empty" => false, "defaultValues" => array(0, 1)), "PRO_SHOW_MAP" => array("type" => "int", "required" => false, "empty" => false, "defaultValues" => array(0, 1), "fieldNameAux" => "processShowMap"),
"processShowMessage" => array("fieldName" => "PRO_SHOW_MESSAGE", "type" => "int", "required" => false, "empty" => false, "defaultValues" => array(0, 1)), "PRO_SHOW_MESSAGE" => array("type" => "int", "required" => false, "empty" => false, "defaultValues" => array(0, 1), "fieldNameAux" => "processShowMessage"),
"processSubprocess" => array("fieldName" => "PRO_SUBPROCESS", "type" => "int", "required" => false, "empty" => false, "defaultValues" => array(0, 1)), "PRO_SUBPROCESS" => array("type" => "int", "required" => false, "empty" => false, "defaultValues" => array(0, 1), "fieldNameAux" => "processSubprocess"),
"processTriDeleted" => array("fieldName" => "PRO_TRI_DELETED", "type" => "string", "required" => false, "empty" => true, "defaultValues" => array()), "PRO_TRI_DELETED" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "processTriDeleted"),
"processTriCanceled" => array("fieldName" => "PRO_TRI_CANCELED", "type" => "string", "required" => false, "empty" => true, "defaultValues" => array()), "PRO_TRI_CANCELED" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "processTriCanceled"),
"processTriPaused" => array("fieldName" => "PRO_TRI_PAUSED", "type" => "string", "required" => false, "empty" => true, "defaultValues" => array()), "PRO_TRI_PAUSED" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "processTriPaused"),
"processTriReassigned" => array("fieldName" => "PRO_TRI_REASSIGNED", "type" => "string", "required" => false, "empty" => true, "defaultValues" => array()), "PRO_TRI_REASSIGNED" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "processTriReassigned"),
"processShowDelegate" => array("fieldName" => "PRO_SHOW_DELEGATE", "type" => "int", "required" => false, "empty" => false, "defaultValues" => array(0, 1)), "PRO_SHOW_DELEGATE" => array("type" => "int", "required" => false, "empty" => false, "defaultValues" => array(0, 1), "fieldNameAux" => "processShowDelegate"),
"processShowDynaform" => array("fieldName" => "PRO_SHOW_DYNAFORM", "type" => "int", "required" => false, "empty" => false, "defaultValues" => array(0, 1)), "PRO_SHOW_DYNAFORM" => array("type" => "int", "required" => false, "empty" => false, "defaultValues" => array(0, 1), "fieldNameAux" => "processShowDynaform"),
"processCategory" => array("fieldName" => "PRO_CATEGORY", "type" => "string", "required" => false, "empty" => true, "defaultValues" => array()), "PRO_CATEGORY" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "processCategory"),
"processSubCategory" => array("fieldName" => "PRO_SUB_CATEGORY", "type" => "string", "required" => false, "empty" => true, "defaultValues" => array()), "PRO_SUB_CATEGORY" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "processSubCategory"),
"processIndustry" => array("fieldName" => "PRO_INDUSTRY", "type" => "int", "required" => false, "empty" => false, "defaultValues" => array(0)), "PRO_INDUSTRY" => array("type" => "int", "required" => false, "empty" => false, "defaultValues" => array(0), "fieldNameAux" => "processIndustry"),
"processUpdateDate" => array("fieldName" => "PRO_UPDATE_DATE", "type" => "datetime", "required" => false, "empty" => true, "defaultValues" => array()), "PRO_UPDATE_DATE" => array("type" => "datetime", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "processUpdateDate"),
"processCreateDate" => array("fieldName" => "PRO_CREATE_DATE", "type" => "datetime", "required" => false, "empty" => true, "defaultValues" => array()), "PRO_CREATE_DATE" => array("type" => "datetime", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "processCreateDate"),
"processCreateUser" => array("fieldName" => "PRO_CREATE_USER", "type" => "string", "required" => true, "empty" => true, "defaultValues" => array()), "PRO_CREATE_USER" => array("type" => "string", "required" => true, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "processCreateUser"),
"processDebug" => array("fieldName" => "PRO_DEBUG", "type" => "int", "required" => false, "empty" => false, "defaultValues" => array(0, 1)), "PRO_DEBUG" => array("type" => "int", "required" => false, "empty" => false, "defaultValues" => array(0, 1), "fieldNameAux" => "processDebug"),
"processDerivationScreenTpl" => array("fieldName" => "PRO_DERIVATION_SCREEN_TPL", "type" => "string", "required" => false, "empty" => true, "defaultValues" => array()), "PRO_DERIVATION_SCREEN_TPL" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "processDerivationScreenTpl"),
"processSummaryDynaform" => array("fieldName" => "PRO_SUMMARY_DYNAFORM", "type" => "string", "required" => false, "empty" => true, "defaultValues" => array()), "PRO_SUMMARY_DYNAFORM" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "processSummaryDynaform"),
"processCalendar" => array("fieldName" => "PRO_CALENDAR", "type" => "string", "required" => false, "empty" => true, "defaultValues" => array()) "PRO_CALENDAR" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "processCalendar")
); );
private $formatFieldNameInUppercase = true; private $formatFieldNameInUppercase = true;
private $arrayFieldNameForException = array(); 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) * Set the format of the fields name (uppercase, lowercase)
* *
@@ -50,9 +68,7 @@ class Process
try { try {
$this->formatFieldNameInUppercase = $flag; $this->formatFieldNameInUppercase = $flag;
foreach ($this->arrayFieldDefinition as $key => $value) { $this->setArrayFieldNameForException($this->arrayFieldNameForException);
$this->arrayFieldNameForException[$key] = $this->getFieldNameByFormatFieldName($value["fieldName"]);
}
} catch (\Exception $e) { } catch (\Exception $e) {
throw $e; throw $e;
} }
@@ -68,10 +84,6 @@ class Process
public function setArrayFieldNameForException($arrayData) public function setArrayFieldNameForException($arrayData)
{ {
try { try {
foreach ($this->arrayFieldDefinition as $key => $value) {
$this->arrayFieldNameForException[$key] = $this->getFieldNameByFormatFieldName($value["fieldName"]);
}
foreach ($arrayData as $key => $value) { foreach ($arrayData as $key => $value) {
$this->arrayFieldNameForException[$key] = $this->getFieldNameByFormatFieldName($value); $this->arrayFieldNameForException[$key] = $this->getFieldNameByFormatFieldName($value);
} }
@@ -155,76 +167,59 @@ class Process
try { try {
if ($flagValidateRequired) { if ($flagValidateRequired) {
foreach ($arrayFieldDefinition as $key => $value) { foreach ($arrayFieldDefinition as $key => $value) {
$fldAlias = $key; $fieldName = $key;
$arrayFldDefinition = $value;
if ($arrayFldDefinition["required"]) { $fieldNameAux = (isset($arrayFieldNameForException[$arrayFieldDefinition[$fieldName]["fieldNameAux"]]))? $arrayFieldNameForException[$arrayFieldDefinition[$fieldName]["fieldNameAux"]] : "";
if (!isset($arrayData[$arrayFldDefinition["fieldName"]])) {
$field = (isset($arrayFieldNameForException[$fldAlias]))? $arrayFieldNameForException[$fldAlias] : "";
throw (new \Exception(str_replace(array("{0}"), array($field), "The \"{0}\" attribute is not defined"))); if ($arrayFieldDefinition[$fieldName]["required"] && !isset($arrayData[$fieldName])) {
} throw (new \Exception(str_replace(array("{0}"), array($fieldNameAux), "The \"{0}\" attribute is not defined")));
} }
} }
} }
foreach ($arrayData as $key1 => $value1) { foreach ($arrayData as $key => $value) {
$fieldName = $key1; $fieldName = $key;
$fieldValue = $value1; $fieldValue = $value;
foreach ($arrayFieldDefinition as $key2 => $value2) { if (isset($arrayFieldDefinition[$fieldName])) {
$fldAlias = $key2; $fieldNameAux = (isset($arrayFieldNameForException[$arrayFieldDefinition[$fieldName]["fieldNameAux"]]))? $arrayFieldNameForException[$arrayFieldDefinition[$fieldName]["fieldNameAux"]] : "";
$arrayFldDefinition = $value2;
if ($arrayFldDefinition["fieldName"] == $fieldName) {
//empty //empty
if (!$arrayFldDefinition["empty"] && trim($fieldValue) . "" == "") { if (!$arrayFieldDefinition[$fieldName]["empty"] && trim($fieldValue) . "" == "") {
$field = (isset($arrayFieldNameForException[$fldAlias]))? $arrayFieldNameForException[$fldAlias] : ""; throw (new \Exception(str_replace(array("{0}"), array($fieldNameAux), "The \"{0}\" attribute is empty")));
throw (new \Exception(str_replace(array("{0}"), array($field), "The \"{0}\" attribute is empty")));
} }
//defaultValues //defaultValues
if (count($arrayFldDefinition["defaultValues"]) > 0 && !in_array($fieldValue, $arrayFldDefinition["defaultValues"])) { if (count($arrayFieldDefinition[$fieldName]["defaultValues"]) > 0 && !in_array($fieldValue, $arrayFieldDefinition[$fieldName]["defaultValues"])) {
$field = (isset($arrayFieldNameForException[$fldAlias]))? $arrayFieldNameForException[$fldAlias] : ""; throw (new \Exception(str_replace(array("{0}"), array($fieldNameAux), "Invalid value specified for \"{0}\"")));
throw (new \Exception(str_replace(array("{0}"), array($field), "Invalid value specified for \"{0}\"")));
} }
//type //type
if ($arrayFldDefinition["empty"] && $fieldValue . "" == "") { if ($arrayFieldDefinition[$fieldName]["empty"] && $fieldValue . "" == "") {
// //
} else { } else {
$eregDate = "[1-9]\d{3}\-(?:0[1-9]|1[012])\-(?:[0][1-9]|[12][0-9]|3[01])"; $eregDate = "[1-9]\d{3}\-(?:0[1-9]|1[012])\-(?:[0][1-9]|[12][0-9]|3[01])";
$eregHour = "(?:[0-1]\d|2[0-3])\:(?:[0-5]\d)\:(?:[0-5]\d)"; $eregHour = "(?:[0-1]\d|2[0-3])\:(?:[0-5]\d)\:(?:[0-5]\d)";
$eregDatetime = $eregDate . "\s" . $eregHour; $eregDatetime = $eregDate . "\s" . $eregHour;
switch ($arrayFldDefinition["type"]) { switch ($arrayFieldDefinition[$fieldName]["type"]) {
case "date": case "date":
if (!preg_match("/^" . $eregDate . "$/", $fieldValue)) { if (!preg_match("/^" . $eregDate . "$/", $fieldValue)) {
$field = (isset($arrayFieldNameForException[$fldAlias]))? $arrayFieldNameForException[$fldAlias] : ""; throw (new \Exception(str_replace(array("{0}"), array($fieldNameAux), "Invalid value specified for \"{0}\"")));
throw (new \Exception(str_replace(array("{0}"), array($field), "Invalid value specified for \"{0}\"")));
} }
break; break;
case "hour": case "hour":
if (!preg_match("/^" . $eregHour . "$/", $fieldValue)) { if (!preg_match("/^" . $eregHour . "$/", $fieldValue)) {
$field = (isset($arrayFieldNameForException[$fldAlias]))? $arrayFieldNameForException[$fldAlias] : ""; throw (new \Exception(str_replace(array("{0}"), array($fieldNameAux), "Invalid value specified for \"{0}\"")));
throw (new \Exception(str_replace(array("{0}"), array($field), "Invalid value specified for \"{0}\"")));
} }
break; break;
case "datetime": case "datetime":
if (!preg_match("/^" . $eregDatetime . "$/", $fieldValue)) { if (!preg_match("/^" . $eregDatetime . "$/", $fieldValue)) {
$field = (isset($arrayFieldNameForException[$fldAlias]))? $arrayFieldNameForException[$fldAlias] : ""; throw (new \Exception(str_replace(array("{0}"), array($fieldNameAux), "Invalid value specified for \"{0}\"")));
throw (new \Exception(str_replace(array("{0}"), array($field), "Invalid value specified for \"{0}\"")));
} }
break; break;
} }
} }
break;
}
} }
} }
} catch (\Exception $e) { } catch (\Exception $e) {
@@ -346,6 +341,29 @@ class Process
} }
} }
/**
* Verify if doesn't exist the PM Table in table ADDITIONAL_TABLES
*
* @param string $additionalTableUid Unique id of PM Table
* @param string $fieldNameForException Field name for the exception
*
* return void Throw exception if doesn't exist the PM Table in table ADDITIONAL_TABLES
*/
public function throwExceptionIfNotExistsPmTable($additionalTableUid, $fieldNameForException)
{
try {
$obj = \AdditionalTablesPeer::retrieveByPK($additionalTableUid);
if (!(is_object($obj) && get_class($obj) == "AdditionalTables")) {
$msg = str_replace(array("{0}", "{1}"), array($fieldNameForException, $additionalTableUid), "The PM Table with {0}: {1}, does not exist");
throw (new \Exception($msg));
}
} catch (\Exception $e) {
throw $e;
}
}
/** /**
* Verify if doesn't exist the DynaForm in table DYNAFORM * Verify if doesn't exist the DynaForm in table DYNAFORM
* *
@@ -361,7 +379,11 @@ class Process
$criteria = new \Criteria("workflow"); $criteria = new \Criteria("workflow");
$criteria->addSelectColumn(\DynaformPeer::DYN_UID); $criteria->addSelectColumn(\DynaformPeer::DYN_UID);
if ($processUid != "") {
$criteria->add(\DynaformPeer::PRO_UID, $processUid, \Criteria::EQUAL); $criteria->add(\DynaformPeer::PRO_UID, $processUid, \Criteria::EQUAL);
}
$criteria->add(\DynaformPeer::DYN_UID, $dynaFormUid, \Criteria::EQUAL); $criteria->add(\DynaformPeer::DYN_UID, $dynaFormUid, \Criteria::EQUAL);
$rsCriteria = \DynaformPeer::doSelectRS($criteria); $rsCriteria = \DynaformPeer::doSelectRS($criteria);
@@ -425,7 +447,11 @@ class Process
$criteria = new \Criteria("workflow"); $criteria = new \Criteria("workflow");
$criteria->addSelectColumn(\TriggersPeer::TRI_UID); $criteria->addSelectColumn(\TriggersPeer::TRI_UID);
if ($processUid != "") {
$criteria->add(\TriggersPeer::PRO_UID, $processUid, \Criteria::EQUAL); $criteria->add(\TriggersPeer::PRO_UID, $processUid, \Criteria::EQUAL);
}
$criteria->add(\TriggersPeer::TRI_UID, $triggerUid, \Criteria::EQUAL); $criteria->add(\TriggersPeer::TRI_UID, $triggerUid, \Criteria::EQUAL);
$rsCriteria = \TriggersPeer::doSelectRS($criteria); $rsCriteria = \TriggersPeer::doSelectRS($criteria);
@@ -1321,17 +1347,15 @@ class Process
public function getDynaForms($processUid) public function getDynaForms($processUid)
{ {
try { try {
//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}")));
}
//Get data
$arrayDynaForm = array(); $arrayDynaForm = array();
//Verify data
$this->throwExceptionIfNoExistsProcess($processUid, $this->arrayFieldNameForException["processUid"]);
//Get data
$dynaForm = new \BusinessModel\DynaForm(); $dynaForm = new \BusinessModel\DynaForm();
$dynaForm->setFormatFieldNameInUppercase($this->formatFieldNameInUppercase);
$dynaForm->setArrayFieldNameForException($this->arrayFieldNameForException);
$criteria = $dynaForm->getDynaFormCriteria(); $criteria = $dynaForm->getDynaFormCriteria();
@@ -1347,6 +1371,7 @@ class Process
$arrayDynaForm[] = $dynaForm->getDynaFormDataFromRecord($row); $arrayDynaForm[] = $dynaForm->getDynaFormDataFromRecord($row);
} }
//Return
return $arrayDynaForm; return $arrayDynaForm;
} catch (\Exception $e) { } catch (\Exception $e) {
throw $e; throw $e;
@@ -1431,5 +1456,41 @@ class Process
throw $e; throw $e;
} }
} }
/**
* Get field names which are primary key in a PM Table
*
* @param string $additionalTableUid Unique id of PM Table
* @param string $fieldNameForException Field name for the exception
*
* return array Return data with the primary keys
*/
public function getPmTablePrimaryKeyFields($additionalTableUid, $fieldNameForException)
{
try {
$arrayFieldPk = array();
//Verify data
$this->throwExceptionIfNotExistsPmTable($additionalTableUid, $fieldNameForException);
//Get data
//Load AdditionalTable
$additionalTable = new \AdditionalTables();
$arrayAdditionalTableData = $additionalTable->load($additionalTableUid, true);
foreach ($arrayAdditionalTableData["FIELDS"] as $key => $value) {
if ($value["FLD_KEY"] == 1) {
//Primary Key
$arrayFieldPk[] = $value["FLD_NAME"];
}
}
//Return
return $arrayFieldPk;
} catch (\Exception $e) {
throw $e;
}
}
} }

View File

@@ -204,14 +204,18 @@ class Project extends Api
} }
/** /**
* @url GET /:projectUid/dynaforms * @url GET /:prj_uid/dynaforms
*
* @param string $prj_uid {@min 32}{@max 32}
*/ */
public function doGetDynaForms($projectUid) public function doGetDynaForms($prj_uid)
{ {
try { try {
$process = new \BusinessModel\Process(); $process = new \BusinessModel\Process();
$process->setFormatFieldNameInUppercase(false);
$process->setArrayFieldNameForException(array("processUid" => "prj_uid"));
$response = $process->getDynaForms($projectUid); $response = $process->getDynaForms($prj_uid);
return $response; return $response;
} catch (\Exception $e) { } catch (\Exception $e) {
@@ -220,16 +224,16 @@ class Project extends Api
} }
/** /**
* @url GET /:projectUid/input-documents * @url GET /:prj_uid/input-documents
* *
* @param string $projectUid {@min 32}{@max 32} * @param string $prj_uid {@min 32}{@max 32}
*/ */
public function doGetInputDocuments($projectUid) public function doGetInputDocuments($prj_uid)
{ {
try { try {
$process = new \BusinessModel\Process(); $process = new \BusinessModel\Process();
$response = $process->getInputDocuments($projectUid); $response = $process->getInputDocuments($prj_uid);
return $response; return $response;
} catch (\Exception $e) { } catch (\Exception $e) {

View File

@@ -12,14 +12,18 @@ use \Luracast\Restler\RestException;
class DynaForm extends Api class DynaForm extends Api
{ {
/** /**
* @url GET /:projectUid/dynaform/:dynaFormUid * @url GET /:prj_uid/dynaform/:dyn_uid
*
* @param string $dyn_uid {@min 32}{@max 32}
* @param string $prj_uid {@min 32}{@max 32}
*/ */
public function doGetDynaForm($dynaFormUid, $projectUid) public function doGetDynaForm($dyn_uid, $prj_uid)
{ {
try { try {
$dynaForm = new \BusinessModel\DynaForm(); $dynaForm = new \BusinessModel\DynaForm();
$dynaForm->setFormatFieldNameInUppercase(false);
$response = $dynaForm->getDynaForm($dynaFormUid); $response = $dynaForm->getDynaForm($dyn_uid);
return $response; return $response;
} catch (\Exception $e) { } catch (\Exception $e) {
@@ -28,21 +32,21 @@ class DynaForm extends Api
} }
/** /**
* @url POST /:projectUid/dynaform * @url POST /:prj_uid/dynaform
* *
* @param string $projectUid * @param string $prj_uid {@min 32}{@max 32}
* @param DynaFormPostStructure $request_data * @param array $request_data
* *
* @status 201 * @status 201
*/ */
public function doPostDynaForm($projectUid, DynaFormPostStructure $request_data = null) public function doPostDynaForm($prj_uid, $request_data)
{ {
try { try {
$dynaForm = new \BusinessModel\DynaForm(); $dynaForm = new \BusinessModel\DynaForm();
$dynaForm->setFormatFieldNameInUppercase(false);
$dynaForm->setArrayFieldNameForException(array("processUid" => "prj_uid"));
$arrayData = $dynaForm->getArrayDataFromRequestData($request_data); $arrayData = $dynaForm->defineCreate($prj_uid, $request_data);
$arrayData = $dynaForm->defineCreate($projectUid, $arrayData);
$response = $arrayData; $response = $arrayData;
@@ -53,83 +57,40 @@ class DynaForm extends Api
} }
/** /**
* @url PUT /:projectUid/dynaform/:dynaFormUid * @url PUT /:prj_uid/dynaform/:dyn_uid
* *
* @param string $dynaFormUid * @param string $dyn_uid {@min 32}{@max 32}
* @param string $projectUid * @param string $prj_uid {@min 32}{@max 32}
* @param DynaFormPutStructure $request_data * @param array $request_data
*/ */
public function doPutDynaForm($dynaFormUid, $projectUid, DynaFormPutStructure $request_data = null) public function doPutDynaForm($dyn_uid, $prj_uid, $request_data)
{ {
try { try {
$dynaForm = new \BusinessModel\DynaForm(); $dynaForm = new \BusinessModel\DynaForm();
$dynaForm->setFormatFieldNameInUppercase(false);
$arrayData = $dynaForm->getArrayDataFromRequestData($request_data); $arrayData = $dynaForm->update($dyn_uid, $request_data);
$arrayData = $dynaForm->update($dynaFormUid, $arrayData);
} catch (\Exception $e) { } catch (\Exception $e) {
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
} }
} }
/** /**
* @url DELETE /:projectUid/dynaform/:dynaFormUid * @url DELETE /:prj_uid/dynaform/:dyn_uid
*
* @param string $dyn_uid {@min 32}{@max 32}
* @param string $prj_uid {@min 32}{@max 32}
*/ */
public function doDeleteDynaForm($dynaFormUid, $projectUid) public function doDeleteDynaForm($dyn_uid, $prj_uid)
{ {
try { try {
$dynaForm = new \BusinessModel\DynaForm(); $dynaForm = new \BusinessModel\DynaForm();
$dynaForm->setFormatFieldNameInUppercase(false);
$dynaForm->delete($dynaFormUid); $dynaForm->delete($dyn_uid);
} catch (\Exception $e) { } catch (\Exception $e) {
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
} }
} }
} }
class DynaFormPostStructure
{
/**
* @var string {@from body}{@required true}
*/
public $dyn_title;
/**
* @var string {@from body}
*/
public $dyn_description;
/**
* @var string {@from body}{@choice xmlform,grid}{@required true}
*/
public $dyn_type;
/**
* @var array {@from body}{@type associative}
*/
public $copy_import;
/**
* @var array {@from body}{@type associative}
*/
public $pmtable;
}
class DynaFormPutStructure
{
/**
* @var string {@from body}
*/
public $dyn_title;
/**
* @var string {@from body}
*/
public $dyn_description;
/**
* @var string {@from body}{@choice xmlform,grid}{@required true}
*/
public $dyn_type;
}