2013-12-23 17:14:04 -04:00
< ? php
namespace BusinessModel ;
class DynaForm
{
2014-02-06 15:35:49 -04:00
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 "
);
2013-12-23 17:14:04 -04:00
/**
2014-02-06 15:35:49 -04:00
* Constructor of the class
2013-12-23 17:14:04 -04:00
*
2014-02-06 15:35:49 -04:00
* return void
2013-12-23 17:14:04 -04:00
*/
2014-02-06 15:35:49 -04:00
public function __construct ()
2013-12-23 17:14:04 -04:00
{
try {
2014-02-06 15:35:49 -04:00
foreach ( $this -> arrayFieldDefinition as $key => $value ) {
$this -> arrayFieldNameForException [ $value [ " fieldNameAux " ]] = $key ;
}
} catch ( \Exception $e ) {
throw $e ;
}
}
2013-12-23 17:14:04 -04:00
2014-02-06 15:35:49 -04:00
/**
* 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 ;
2013-12-23 17:14:04 -04:00
2014-02-06 15:35:49 -04:00
$this -> setArrayFieldNameForException ( $this -> arrayFieldNameForException );
} catch ( \Exception $e ) {
throw $e ;
}
}
2013-12-23 17:14:04 -04:00
2014-02-06 15:35:49 -04:00
/**
* 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 );
2013-12-23 17:14:04 -04:00
}
} catch ( \Exception $e ) {
throw $e ;
}
}
/**
2014-02-06 15:35:49 -04:00
* Get the name of the field according to the format
2013-12-23 17:14:04 -04:00
*
2014-02-06 15:35:49 -04:00
* @ 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 $dynaFormTitle Title
2013-12-23 17:14:04 -04:00
* @ param string $dynaFormUidExclude Unique id of DynaForm to exclude
*
2014-02-06 15:35:49 -04:00
* return bool Return true if exists the title of a DynaForm , false otherwise
2013-12-23 17:14:04 -04:00
*/
2014-02-06 15:35:49 -04:00
public function existsTitle ( $processUid , $dynaFormTitle , $dynaFormUidExclude = " " )
2013-12-23 17:14:04 -04:00
{
try {
$delimiter = \DBAdapter :: getStringDelimiter ();
$criteria = new \Criteria ( " workflow " );
$criteria -> addSelectColumn ( \DynaformPeer :: DYN_UID );
$criteria -> addAlias ( " CT " , \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 );
$criteria -> add ( \DynaformPeer :: PRO_UID , $processUid , \Criteria :: EQUAL );
if ( $dynaFormUidExclude != " " ) {
$criteria -> add ( \DynaformPeer :: DYN_UID , $dynaFormUidExclude , \Criteria :: NOT_EQUAL );
}
2014-02-06 15:35:49 -04:00
$criteria -> add ( " CT.CON_VALUE " , $dynaFormTitle , \Criteria :: EQUAL );
2013-12-23 17:14:04 -04:00
$rsCriteria = \DynaformPeer :: doSelectRS ( $criteria );
if ( $rsCriteria -> next ()) {
return true ;
} else {
return false ;
}
} catch ( \Exception $e ) {
throw $e ;
}
}
/**
* Verify if a DynaForm is assigned some Steps
*
* @ param string $dynaFormUid Unique id of DynaForm
* @ param string $processUid Unique id of Process
*
* return bool Return true if a DynaForm is assigned some Steps , false otherwise
*/
public function dynaFormAssignedStep ( $dynaFormUid , $processUid )
{
try {
$step = new \Step ();
$arrayData = $step -> loadInfoAssigDynaform ( $processUid , $dynaFormUid );
if ( is_array ( $arrayData )) {
return true ;
} else {
return false ;
}
} catch ( \Exception $e ) {
throw $e ;
}
}
/**
* Verify if a DynaForm has relation with a Step Supervisor
*
* @ param string $dynaFormUid Unique id of DynaForm
*
* return bool Return true if a DynaForm has relation with a Step Supervisor , false otherwise
*/
public function dynaFormRelationStepSupervisor ( $dynaFormUid )
{
try {
$stepSupervisor = new \StepSupervisor ();
$arrayData = $stepSupervisor -> loadInfo ( $dynaFormUid );
if ( is_array ( $arrayData )) {
return true ;
} else {
return false ;
}
} catch ( \Exception $e ) {
throw $e ;
}
}
2014-02-12 12:32:04 -04:00
/**
* Verify if doesn ' t exist the DynaForm in table DYNAFORM
*
* @ param string $dynaFormUid Unique id of DynaForm
* @ param string $processUid Unique id of Process
* @ param string $fieldNameForException Field name for the exception
*
* return void Throw exception if doesn ' t exist the DynaForm in table DYNAFORM
*/
public function throwExceptionIfNotExistsDynaForm ( $dynaFormUid , $processUid , $fieldNameForException )
{
try {
$criteria = new \Criteria ( " workflow " );
$criteria -> addSelectColumn ( \DynaformPeer :: DYN_UID );
if ( $processUid != " " ) {
$criteria -> add ( \DynaformPeer :: PRO_UID , $processUid , \Criteria :: EQUAL );
}
$criteria -> add ( \DynaformPeer :: DYN_UID , $dynaFormUid , \Criteria :: EQUAL );
$rsCriteria = \DynaformPeer :: doSelectRS ( $criteria );
if ( ! $rsCriteria -> next ()) {
$msg = str_replace ( array ( " { 0} " , " { 1} " ), array ( $fieldNameForException , $dynaFormUid ), " The DynaForm with { 0}: { 1}, does not exist " );
throw ( new \Exception ( $msg ));
}
} catch ( \Exception $e ) {
throw $e ;
}
}
2013-12-23 17:14:04 -04:00
/**
2014-02-06 15:35:49 -04:00
* Verify if exists the title of a DynaForm
2013-12-23 17:14:04 -04:00
*
2014-02-06 15:35:49 -04:00
* @ 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
2013-12-23 17:14:04 -04:00
*
2014-02-06 15:35:49 -04:00
* return void Throw exception if exists the title of a DynaForm
2013-12-23 17:14:04 -04:00
*/
2014-02-06 15:35:49 -04:00
public function throwExceptionIfExistsTitle ( $processUid , $dynaFormTitle , $fieldNameForException , $dynaFormUidExclude = " " )
2013-12-23 17:14:04 -04:00
{
try {
2014-02-06 15:35:49 -04:00
if ( $this -> existsTitle ( $processUid , $dynaFormTitle , $dynaFormUidExclude )) {
$msg = str_replace ( array ( " { 0} " , " { 1} " ), array ( $fieldNameForException , $dynaFormTitle ), " The DynaForm title with { 0}: \" { 1} \" , already exists " );
2013-12-23 17:14:04 -04:00
2014-02-06 15:35:49 -04:00
throw ( new \Exception ( $msg ));
2013-12-23 17:14:04 -04:00
}
} catch ( \Exception $e ) {
throw $e ;
2014-02-14 11:53:49 -04:00
}
}
/**
* Verify if not is grid DynaForm
*
* @ param string $dynaFormUid Unique id of DynaForm
* @ param string $fieldNameForException Field name for the exception
*
* return void Throw exception if not is grid DynaForm
*/
public function throwExceptionIfNotIsGridDynaForm ( $dynaFormUid , $fieldNameForException )
{
try {
//Load DynaForm
$dynaForm = new \Dynaform ();
$arrayDynaFormData = $dynaForm -> Load ( $dynaFormUid );
if ( $arrayDynaFormData [ " DYN_TYPE " ] != " grid " ) {
$msg = str_replace ( array ( " { 0} " , " { 1} " ), array ( $fieldNameForException , $dynaFormUid ), " The DynaForm with { 0}: { 1}, not is grid " );
throw ( new \Exception ( $msg ));
}
} catch ( \Exception $e ) {
throw $e ;
2013-12-23 17:14:04 -04:00
}
}
/**
* Create DynaForm for a Process
*
* @ param string $processUid Unique id of Process
* @ param array $arrayData Data
*
* return array Return data of the new DynaForm created
*/
public function create ( $processUid , $arrayData )
{
try {
$arrayData = array_change_key_case ( $arrayData , CASE_UPPER );
unset ( $arrayData [ " DYN_UID " ]);
unset ( $arrayData [ " COPY_IMPORT " ]);
unset ( $arrayData [ " PMTABLE " ]);
//Verify data
2014-02-06 15:35:49 -04:00
$process = new \BusinessModel\Process ();
2013-12-23 17:14:04 -04:00
2014-02-06 15:35:49 -04:00
$process -> throwExceptionIfNoExistsProcess ( $processUid , $this -> arrayFieldNameForException [ " processUid " ]);
2013-12-23 17:14:04 -04:00
2014-02-06 15:35:49 -04:00
$process -> throwExceptionIfDataNotMetFieldDefinition ( $arrayData , $this -> arrayFieldDefinition , $this -> arrayFieldNameForException , true );
$this -> throwExceptionIfExistsTitle ( $processUid , $arrayData [ " DYN_TITLE " ], $this -> arrayFieldNameForException [ " dynaFormTitle " ]);
2013-12-23 17:14:04 -04:00
//Create
$dynaForm = new \Dynaform ();
$arrayData [ " PRO_UID " ] = $processUid ;
$dynaFormUid = $dynaForm -> create ( $arrayData );
//Return
unset ( $arrayData [ " PRO_UID " ]);
2014-02-06 15:35:49 -04:00
$arrayData = array_merge ( array ( " DYN_UID " => $dynaFormUid ), $arrayData );
2013-12-23 17:14:04 -04:00
2014-02-06 15:35:49 -04:00
if ( ! $this -> formatFieldNameInUppercase ) {
$arrayData = array_change_key_case ( $arrayData , CASE_LOWER );
}
2013-12-23 17:14:04 -04:00
2014-02-06 15:35:49 -04:00
return $arrayData ;
2013-12-23 17:14:04 -04:00
} catch ( \Exception $e ) {
throw $e ;
}
}
/**
* Update DynaForm
*
* @ param string $dynaFormUid Unique id of DynaForm
* @ param array $arrayData Data
*
* return array Return data of the DynaForm updated
*/
public function update ( $dynaFormUid , $arrayData )
{
try {
$arrayData = array_change_key_case ( $arrayData , CASE_UPPER );
2014-02-06 15:35:49 -04:00
//Verify data
2014-02-12 12:32:04 -04:00
$this -> throwExceptionIfNotExistsDynaForm ( $dynaFormUid , " " , $this -> arrayFieldNameForException [ " dynaFormUid " ]);
2014-01-15 17:09:37 -04:00
2014-02-06 15:35:49 -04:00
//Load DynaForm
2013-12-23 17:14:04 -04:00
$dynaForm = new \Dynaform ();
2014-02-06 15:35:49 -04:00
$arrayDynaFormData = $dynaForm -> Load ( $dynaFormUid );
$processUid = $arrayDynaFormData [ " PRO_UID " ];
//Verify data
2014-02-12 12:32:04 -04:00
$process = new \BusinessModel\Process ();
2014-02-06 15:35:49 -04:00
$process -> throwExceptionIfDataNotMetFieldDefinition ( $arrayData , $this -> arrayFieldDefinition , $this -> arrayFieldNameForException , false );
2013-12-23 17:14:04 -04:00
2014-02-06 15:35:49 -04:00
if ( isset ( $arrayData [ " DYN_TITLE " ])) {
$this -> throwExceptionIfExistsTitle ( $processUid , $arrayData [ " DYN_TITLE " ], $this -> arrayFieldNameForException [ " dynaFormTitle " ], $dynaFormUid );
2013-12-23 17:14:04 -04:00
}
//Update
$arrayData [ " DYN_UID " ] = $dynaFormUid ;
$result = $dynaForm -> update ( $arrayData );
//Return
unset ( $arrayData [ " DYN_UID " ]);
2014-02-06 15:35:49 -04:00
if ( ! $this -> formatFieldNameInUppercase ) {
$arrayData = array_change_key_case ( $arrayData , CASE_LOWER );
}
return $arrayData ;
2013-12-23 17:14:04 -04:00
} catch ( \Exception $e ) {
throw $e ;
}
}
/**
* Delete DynaForm
*
* @ param string $dynaFormUid Unique id of DynaForm
*
* return void
*/
public function delete ( $dynaFormUid )
{
try {
2014-02-06 15:35:49 -04:00
//Verify data
2014-02-12 12:32:04 -04:00
$this -> throwExceptionIfNotExistsDynaForm ( $dynaFormUid , " " , $this -> arrayFieldNameForException [ " dynaFormUid " ]);
2014-01-15 17:09:37 -04:00
2014-02-06 15:35:49 -04:00
//Load DynaForm
2013-12-23 17:14:04 -04:00
$dynaForm = new \Dynaform ();
2014-02-06 15:35:49 -04:00
$arrayDynaFormData = $dynaForm -> Load ( $dynaFormUid );
$processUid = $arrayDynaFormData [ " PRO_UID " ];
2013-12-23 17:14:04 -04:00
2014-02-06 15:35:49 -04:00
//Verify data
2014-01-06 16:07:22 -04:00
if ( $this -> dynaFormAssignedStep ( $dynaFormUid , $processUid )) {
2013-12-23 17:14:04 -04:00
throw ( new \Exception ( " You cannot delete this Dynaform while it is assigned to a step " ));
}
//Delete
//In table DYNAFORM
$result = $dynaForm -> remove ( $dynaFormUid );
//In table STEP
$step = new \Step ();
$step -> removeStep ( " DYNAFORM " , $dynaFormUid );
//In table OBJECT_PERMISSION
$objPermission = new \ObjectPermission ();
$objPermission -> removeByObject ( " DYNAFORM " , $dynaFormUid );
//In table STEP_SUPERVISOR
$stepSupervisor = new \StepSupervisor ();
$stepSupervisor -> removeByObject ( " DYNAFORM " , $dynaFormUid );
//In table CASE_TRACKER_OBJECT
$caseTrackerObject = new \CaseTrackerObject ();
$caseTrackerObject -> removeByObject ( " DYNAFORM " , $dynaFormUid );
} catch ( \Exception $e ) {
throw $e ;
}
}
/**
* Copy / Import a DynaForm
*
* @ param string $processUid Unique id of Process
* @ param array $arrayData Data
*
* return array Return data of the new DynaForm created
*/
public function copyImport ( $processUid , $arrayData )
{
try {
$arrayData = \G :: array_change_key_case2 ( $arrayData , CASE_UPPER );
2014-02-06 15:35:49 -04:00
unset ( $arrayData [ " DYN_UID " ]);
unset ( $arrayData [ " PMTABLE " ]);
2013-12-23 17:14:04 -04:00
//Verify data
2014-02-06 15:35:49 -04:00
$process = new \BusinessModel\Process ();
2013-12-23 17:14:04 -04:00
2014-02-06 15:35:49 -04:00
$process -> throwExceptionIfNoExistsProcess ( $processUid , $this -> arrayFieldNameForException [ " processUid " ]);
2013-12-23 17:14:04 -04:00
2014-02-06 15:35:49 -04:00
$process -> throwExceptionIfDataNotMetFieldDefinition ( $arrayData , $this -> arrayFieldDefinition , $this -> arrayFieldNameForException , true );
2013-12-23 17:14:04 -04:00
2014-02-06 15:35:49 -04:00
if ( ! isset ( $arrayData [ " COPY_IMPORT " ])) {
throw ( new \Exception ( str_replace ( array ( " { 0} " ), array ( $this -> getFieldNameByFormatFieldName ( " COPY_IMPORT " )), " The \" { 0} \" attribute is not defined " )));
}
2013-12-23 17:14:04 -04:00
2014-02-06 15:35:49 -04:00
if ( ! isset ( $arrayData [ " COPY_IMPORT " ][ " PRJ_UID " ])) {
throw ( new \Exception ( str_replace ( array ( " { 0} " ), array ( $this -> getFieldNameByFormatFieldName ( " COPY_IMPORT.PRJ_UID " )), " The \" { 0} \" attribute is not defined " )));
}
2013-12-23 17:14:04 -04:00
2014-02-06 15:35:49 -04:00
$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 " )));
2013-12-23 17:14:04 -04:00
}
2014-02-06 15:35:49 -04:00
if ( ! isset ( $arrayData [ " COPY_IMPORT " ][ " DYN_UID " ])) {
throw ( new \Exception ( str_replace ( array ( " { 0} " ), array ( $this -> getFieldNameByFormatFieldName ( " COPY_IMPORT.DYN_UID " )), " The \" { 0} \" attribute is not defined " )));
2013-12-23 17:14:04 -04:00
}
2014-02-06 15:35:49 -04:00
$arrayData [ " COPY_IMPORT " ][ " DYN_UID " ] = trim ( $arrayData [ " COPY_IMPORT " ][ " DYN_UID " ]);
2013-12-23 17:14:04 -04:00
2014-02-06 15:35:49 -04:00
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 " )));
2013-12-23 17:14:04 -04:00
}
2014-02-06 15:35:49 -04:00
$this -> throwExceptionIfExistsTitle ( $processUid , $arrayData [ " DYN_TITLE " ], $this -> arrayFieldNameForException [ " dynaFormTitle " ]);
//Copy/Import Uids
$processUidCopyImport = $arrayData [ " COPY_IMPORT " ][ " PRJ_UID " ];
$dynaFormUidCopyImport = $arrayData [ " COPY_IMPORT " ][ " DYN_UID " ];
//Verify data
$process -> throwExceptionIfNoExistsProcess ( $processUidCopyImport , $this -> getFieldNameByFormatFieldName ( " COPY_IMPORT.PRJ_UID " ));
2014-02-12 12:32:04 -04:00
$this -> throwExceptionIfNotExistsDynaForm ( $dynaFormUidCopyImport , $processUidCopyImport , $this -> getFieldNameByFormatFieldName ( " COPY_IMPORT.DYN_UID " ));
2013-12-23 17:14:04 -04:00
//Copy/Import
//Create
$arrayData = $this -> create ( $processUid , $arrayData );
2014-02-06 15:35:49 -04:00
$dynaFormUid = $arrayData [ $this -> getFieldNameByFormatFieldName ( " DYN_UID " )];
2013-12-23 17:14:04 -04:00
//Copy files of the DynaForm
$umaskOld = umask ( 0 );
$fileXml = PATH_DYNAFORM . $processUidCopyImport . PATH_SEP . $dynaFormUidCopyImport . " .xml " ;
if ( file_exists ( $fileXml )) {
$fileXmlCopy = PATH_DYNAFORM . $processUid . PATH_SEP . $dynaFormUid . " .xml " ;
$fhXml = fopen ( $fileXml , " r " );
$fhXmlCopy = fopen ( $fileXmlCopy , " w " );
while ( ! feof ( $fhXml )) {
$strLine = fgets ( $fhXml , 4096 );
$strLine = str_replace ( $processUidCopyImport . " / " . $dynaFormUidCopyImport , $processUid . " / " . $dynaFormUid , $strLine );
//DynaForm Grid
preg_match_all ( " /<.*type \ s*= \ s*[ \" \ ']grid[ \" \ '].*xmlgrid \ s*= \ s*[ \" \ '] \ w { 32} \ /( \ w { 32})[ \" \ '].* \ />/ " , $strLine , $arrayMatch , PREG_SET_ORDER );
foreach ( $arrayMatch as $value ) {
$dynaFormGridUidCopyImport = $value [ 1 ];
//Get data
$criteria = new \Criteria ();
$criteria -> addSelectColumn ( \ContentPeer :: CON_VALUE );
$criteria -> add ( \ContentPeer :: CON_ID , $dynaFormGridUidCopyImport );
$criteria -> add ( \ContentPeer :: CON_CATEGORY , " DYN_TITLE " );
$criteria -> add ( \ContentPeer :: CON_LANG , SYS_LANG );
$rsCriteria = \ContentPeer :: doSelectRS ( $criteria );
$rsCriteria -> setFetchmode ( \ResultSet :: FETCHMODE_ASSOC );
$rsCriteria -> next ();
$row = $rsCriteria -> getRow ();
$dynGrdTitleCopyImport = $row [ " CON_VALUE " ];
$criteria = new \Criteria ();
$criteria -> addSelectColumn ( \ContentPeer :: CON_VALUE );
$criteria -> add ( \ContentPeer :: CON_ID , $dynaFormGridUidCopyImport );
$criteria -> add ( \ContentPeer :: CON_CATEGORY , " DYN_DESCRIPTION " );
$criteria -> add ( \ContentPeer :: CON_LANG , SYS_LANG );
$rsCriteria = \ContentPeer :: doSelectRS ( $criteria );
$rsCriteria -> setFetchmode ( \ResultSet :: FETCHMODE_ASSOC );
$rsCriteria -> next ();
$row = $rsCriteria -> getRow ();
$dynGrdDescriptionCopyImport = $row [ " CON_VALUE " ];
//Create Grid
$arrayDataAux = array (
" PRO_UID " => $processUid ,
" DYN_TITLE " => $dynGrdTitleCopyImport ,
" DYN_DESCRIPTION " => $dynGrdDescriptionCopyImport ,
" DYN_TYPE " => " grid "
);
$dynaFormGrid = new \Dynaform ();
$dynaFormGridUid = $dynaFormGrid -> create ( $arrayDataAux );
//Copy files of the DynaForm Grid
$fileGridXml = PATH_DYNAFORM . $processUidCopyImport . PATH_SEP . $dynaFormGridUidCopyImport . " .xml " ;
if ( file_exists ( $fileGridXml )) {
$fileGridXmlCopy = PATH_DYNAFORM . $processUid . PATH_SEP . $dynaFormGridUid . " .xml " ;
$fhGridXml = fopen ( $fileGridXml , " r " );
$fhGridXmlCopy = fopen ( $fileGridXmlCopy , " w " );
while ( ! feof ( $fhGridXml )) {
$strLineAux = fgets ( $fhGridXml , 4096 );
$strLineAux = str_replace ( $processUidCopyImport . " / " . $dynaFormGridUidCopyImport , $processUid . " / " . $dynaFormGridUid , $strLineAux );
fwrite ( $fhGridXmlCopy , $strLineAux );
}
fclose ( $fhGridXmlCopy );
fclose ( $fhGridXml );
chmod ( $fileGridXmlCopy , 0777 );
}
$fileGridHtml = PATH_DYNAFORM . $processUidCopyImport . PATH_SEP . $dynaFormGridUidCopyImport . " .html " ;
if ( file_exists ( $fileGridHtml )) {
$fileGridHtmlCopy = PATH_DYNAFORM . $processUid . PATH_SEP . $dynaFormGridUid . " .html " ;
copy ( $fileGridHtml , $fileGridHtmlCopy );
chmod ( $fileGridHtmlCopy , 0777 );
}
$strLine = str_replace ( $processUidCopyImport . " / " . $dynaFormGridUidCopyImport , $processUid . " / " . $dynaFormGridUid , $strLine );
}
fwrite ( $fhXmlCopy , $strLine );
}
fclose ( $fhXmlCopy );
fclose ( $fhXml );
chmod ( $fileXmlCopy , 0777 );
}
$fileHtml = PATH_DYNAFORM . $processUidCopyImport . PATH_SEP . $dynaFormUidCopyImport . " .html " ;
if ( file_exists ( $fileHtml )) {
$fileHtmlCopy = PATH_DYNAFORM . $processUid . PATH_SEP . $dynaFormUid . " .html " ;
copy ( $fileHtml , $fileHtmlCopy );
chmod ( $fileHtmlCopy , 0777 );
}
//Copy if there are conditions attached to the DynaForm
$fieldCondition = new \FieldCondition ();
$arrayCondition = $fieldCondition -> getAllByDynUid ( $dynaFormUidCopyImport );
foreach ( $arrayCondition as $condition ) {
$condition [ " FCD_UID " ] = " " ;
$condition [ " FCD_DYN_UID " ] = $dynaFormUid ;
$fieldCondition -> quickSave ( $condition );
}
umask ( $umaskOld );
//Return
return $arrayData ;
} catch ( \Exception $e ) {
throw $e ;
}
}
/**
* Create a Dynaform based on a PMTable
*
* @ param string $processUid Unique id of Process
* @ param array $arrayData Data
*
* return array Return data of the new DynaForm created
*/
public function createBasedPmTable ( $processUid , $arrayData )
{
try {
$arrayData = \G :: array_change_key_case2 ( $arrayData , CASE_UPPER );
unset ( $arrayData [ " DYN_UID " ]);
unset ( $arrayData [ " COPY_IMPORT " ]);
//Verify data
2014-02-06 15:35:49 -04:00
$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 " )));
}
2013-12-23 17:14:04 -04:00
if ( ! isset ( $arrayData [ " PMTABLE " ][ " TAB_UID " ])) {
2014-02-06 15:35:49 -04:00
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 " )));
2013-12-23 17:14:04 -04:00
}
if ( ! isset ( $arrayData [ " PMTABLE " ][ " FIELDS " ])) {
2014-02-06 15:35:49 -04:00
throw ( new \Exception ( str_replace ( array ( " { 0} " ), array ( $this -> getFieldNameByFormatFieldName ( " PMTABLE.FIELDS " )), " The \" { 0} \" attribute is not defined " )));
2013-12-23 17:14:04 -04:00
}
if ( count ( $arrayData [ " PMTABLE " ][ " FIELDS " ]) == 0 ) {
2014-02-06 15:35:49 -04:00
throw ( new \Exception ( str_replace ( array ( " { 0} " ), array ( $this -> getFieldNameByFormatFieldName ( " PMTABLE.FIELDS " )), " The \" { 0} \" attribute is empty " )));
2013-12-23 17:14:04 -04:00
}
2014-02-06 15:35:49 -04:00
$this -> throwExceptionIfExistsTitle ( $processUid , $arrayData [ " DYN_TITLE " ], $this -> arrayFieldNameForException [ " dynaFormTitle " ]);
2013-12-23 17:14:04 -04:00
2014-02-06 15:35:49 -04:00
$process -> throwExceptionIfNotExistsPmTable ( $arrayData [ " PMTABLE " ][ " TAB_UID " ], $this -> getFieldNameByFormatFieldName ( " PMTABLE.TAB_UID " ));
//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 ;
}
2013-12-23 17:14:04 -04:00
}
2014-02-06 15:35:49 -04:00
if ( $flagValidFieldKey == 0 ) {
throw ( new \Exception ( str_replace ( array ( " { 0} " ), array ( $this -> getFieldNameByFormatFieldName ( " PMTABLE.FIELDS " )), " The attribute { 0}, has an element invalid (incorrect keys) " )));
2013-12-23 17:14:04 -04:00
}
2014-02-06 15:35:49 -04:00
//Is Primary Key
$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 ( $flagValidFieldPk == 0 ) {
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 ;
}
2013-12-23 17:14:04 -04:00
}
2014-02-06 15:35:49 -04:00
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 " )));
2013-12-23 17:14:04 -04:00
}
//Set data
$tableUid = $arrayData [ " PMTABLE " ][ " TAB_UID " ];
$arrayFields = $arrayData [ " PMTABLE " ][ " FIELDS " ];
unset ( $arrayData [ " PMTABLE " ]);
//Create
$dynaForm = new \Dynaform ();
$arrayData [ " PRO_UID " ] = $processUid ;
$arrayData [ " DYN_TYPE " ] = " xmlform " ;
$arrayData [ " FIELDS " ] = $arrayFields ;
$dynaForm -> createFromPMTable ( $arrayData , $tableUid );
$dynaFormUid = $dynaForm -> getDynUid ();
//Return
unset ( $arrayData [ " PRO_UID " ]);
unset ( $arrayData [ " FIELDS " ]);
2014-02-06 15:35:49 -04:00
$arrayData = array_merge ( array ( " DYN_UID " => $dynaFormUid ), $arrayData );
2013-12-23 17:14:04 -04:00
2014-02-06 15:35:49 -04:00
if ( ! $this -> formatFieldNameInUppercase ) {
$arrayData = array_change_key_case ( $arrayData , CASE_LOWER );
}
2013-12-23 17:14:04 -04:00
2014-02-06 15:35:49 -04:00
return $arrayData ;
2013-12-23 17:14:04 -04:00
} catch ( \Exception $e ) {
throw $e ;
}
}
/**
* Defines the method for create a DynaForm
*
* @ param string $processUid Unique id of Process
* @ param array $arrayData Data
*
* return array Return data of the new DynaForm created
*/
2014-02-10 17:16:44 -04:00
public function executeCreate ( $processUid , $arrayData )
2013-12-23 17:14:04 -04:00
{
try {
2014-02-06 15:35:49 -04:00
$arrayData = array_change_key_case ( $arrayData , CASE_UPPER );
2013-12-23 17:14:04 -04:00
$option = " NORMAL " ;
//Validate data
$count = 0 ;
$msgMethod = " " ;
2014-02-06 15:35:49 -04:00
if ( isset ( $arrayData [ " COPY_IMPORT " ])) {
2013-12-23 17:14:04 -04:00
$count = $count + 1 ;
2014-02-06 15:35:49 -04:00
$msgMethod = $msgMethod . (( $msgMethod != " " ) ? " , " : " " ) . " COPY_IMPORT " ;
2013-12-23 17:14:04 -04:00
$option = " COPY_IMPORT " ;
}
2014-02-06 15:35:49 -04:00
if ( isset ( $arrayData [ " PMTABLE " ])) {
2013-12-23 17:14:04 -04:00
$count = $count + 1 ;
2014-02-06 15:35:49 -04:00
$msgMethod = $msgMethod . (( $msgMethod != " " ) ? " , " : " " ) . " PMTABLE " ;
2013-12-23 17:14:04 -04:00
$option = " PMTABLE " ;
}
if ( $count <= 1 ) {
$arrayDataAux = array ();
switch ( $option ) {
case " COPY_IMPORT " :
$arrayDataAux = $this -> copyImport ( $processUid , $arrayData );
break ;
case " PMTABLE " :
$arrayDataAux = $this -> createBasedPmTable ( $processUid , $arrayData );
break ;
default :
//NORMAL
$arrayDataAux = $this -> create ( $processUid , $arrayData );
break ;
}
//Return
return $arrayDataAux ;
} else {
2014-02-06 15:35:49 -04:00
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 " )));
2013-12-23 17:14:04 -04:00
}
} catch ( \Exception $e ) {
throw $e ;
}
}
/**
* Get criteria for DynaForm
*
* return object
*/
public function getDynaFormCriteria ()
{
try {
$delimiter = \DBAdapter :: getStringDelimiter ();
$criteria = new \Criteria ( " workflow " );
$criteria -> addSelectColumn ( \DynaformPeer :: DYN_UID );
$criteria -> addAsColumn ( " DYN_TITLE " , " CT.CON_VALUE " );
$criteria -> addAsColumn ( " DYN_DESCRIPTION " , " CD.CON_VALUE " );
$criteria -> addSelectColumn ( \DynaformPeer :: DYN_TYPE );
$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 );
return $criteria ;
} catch ( \Exception $e ) {
throw $e ;
}
}
/**
* Get data of a DynaForm from a record
*
* @ param array $record Record
*
2014-02-06 15:35:49 -04:00
* return array Return an array with data DynaForm
2013-12-23 17:14:04 -04:00
*/
public function getDynaFormDataFromRecord ( $record )
{
try {
if ( $record [ " DYN_TITLE " ] . " " == " " ) {
//There is no transaltion for this Document name, try to get/regenerate the label
$record [ " DYN_TITLE " ] = \Content :: load ( " DYN_TITLE " , " " , $record [ " DYN_UID " ], SYS_LANG );
}
if ( $record [ " DYN_DESCRIPTION " ] . " " == " " ) {
//There is no transaltion for this Document name, try to get/regenerate the label
$record [ " DYN_DESCRIPTION " ] = \Content :: load ( " DYN_DESCRIPTION " , " " , $record [ " DYN_UID " ], SYS_LANG );
}
return array (
2014-02-06 15:35:49 -04:00
$this -> getFieldNameByFormatFieldName ( " DYN_UID " ) => $record [ " DYN_UID " ],
$this -> getFieldNameByFormatFieldName ( " DYN_TITLE " ) => $record [ " DYN_TITLE " ],
$this -> getFieldNameByFormatFieldName ( " DYN_DESCRIPTION " ) => $record [ " DYN_DESCRIPTION " ] . " " ,
$this -> getFieldNameByFormatFieldName ( " DYN_TYPE " ) => $record [ " DYN_TYPE " ] . " "
2013-12-23 17:14:04 -04:00
);
} catch ( \Exception $e ) {
throw $e ;
}
}
/**
* Get data of a DynaForm
*
* @ param string $dynaFormUid Unique id of DynaForm
*
* return array Return an array with data of a DynaForm
*/
public function getDynaForm ( $dynaFormUid )
{
try {
//Verify data
2014-02-12 12:32:04 -04:00
$this -> throwExceptionIfNotExistsDynaForm ( $dynaFormUid , " " , $this -> arrayFieldNameForException [ " dynaFormUid " ]);
2013-12-23 17:14:04 -04:00
//Get data
$criteria = $this -> getDynaFormCriteria ();
$criteria -> add ( \DynaformPeer :: DYN_UID , $dynaFormUid , \Criteria :: EQUAL );
$rsCriteria = \DynaformPeer :: doSelectRS ( $criteria );
$rsCriteria -> setFetchmode ( \ResultSet :: FETCHMODE_ASSOC );
$rsCriteria -> next ();
$row = $rsCriteria -> getRow ();
2014-02-06 15:35:49 -04:00
//Return
2013-12-23 17:14:04 -04:00
return $this -> getDynaFormDataFromRecord ( $row );
} catch ( \Exception $e ) {
throw $e ;
}
}
}