Example #1
0
    /**

     * Create Dynaform Rows for a Process form an array

     *

     * @param array $aDynaform

     * @return void

     */

    public function createDynaformRows ($aDynaform)

    {

        foreach ($aDynaform as $key => $row) {

            $oDynaform = new Dynaform();

            //unset ($row['TAS_UID']);

            if ($oDynaform->exists( $row['DYN_UID'] )) {

                $oDynaform->remove( $row['DYN_UID'] );

            }

            $res = $oDynaform->create( $row );

        }

        return;

    }
Example #2
0
 /**
  * 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);
         unset($arrayData["DYN_UID"]);
         unset($arrayData["PMTABLE"]);
         //Verify data
         $process = new \ProcessMaker\BusinessModel\Process();
         $process->throwExceptionIfNotExistsProcess($processUid, $this->arrayFieldNameForException["processUid"]);
         $process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $this->arrayFieldDefinition, $this->arrayFieldNameForException, true);
         if (!isset($arrayData["COPY_IMPORT"])) {
             throw new \Exception(\G::LoadTranslation("ID_UNDEFINED_VALUE_IS_REQUIRED", array($this->getFieldNameByFormatFieldName("COPY_IMPORT"))));
         }
         if (!isset($arrayData["COPY_IMPORT"]["PRJ_UID"])) {
             throw new \Exception(\G::LoadTranslation("ID_UNDEFINED_VALUE_IS_REQUIRED", array($this->getFieldNameByFormatFieldName("COPY_IMPORT.PRJ_UID"))));
         }
         $arrayData["COPY_IMPORT"]["PRJ_UID"] = trim($arrayData["COPY_IMPORT"]["PRJ_UID"]);
         if ($arrayData["COPY_IMPORT"]["PRJ_UID"] == "") {
             throw new \Exception(\G::LoadTranslation("ID_INVALID_VALUE_CAN_NOT_BE_EMPTY", array($this->getFieldNameByFormatFieldName("COPY_IMPORT.PRJ_UID"))));
         }
         if (!isset($arrayData["COPY_IMPORT"]["DYN_UID"])) {
             throw new \Exception(\G::LoadTranslation("ID_UNDEFINED_VALUE_IS_REQUIRED", array($this->getFieldNameByFormatFieldName("COPY_IMPORT.DYN_UID"))));
         }
         $arrayData["COPY_IMPORT"]["DYN_UID"] = trim($arrayData["COPY_IMPORT"]["DYN_UID"]);
         if ($arrayData["COPY_IMPORT"]["DYN_UID"] == "") {
             throw new \Exception(\G::LoadTranslation("ID_INVALID_VALUE_CAN_NOT_BE_EMPTY", array($this->getFieldNameByFormatFieldName("COPY_IMPORT.DYN_UID"))));
         }
         $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->throwExceptionIfNotExistsProcess($processUidCopyImport, $this->getFieldNameByFormatFieldName("COPY_IMPORT.PRJ_UID"));
         $this->throwExceptionIfNotExistsDynaForm($dynaFormUidCopyImport, $processUidCopyImport, $this->getFieldNameByFormatFieldName("COPY_IMPORT.DYN_UID"));
         //Copy/Import
         //Copy content if version is 2
         if ($arrayData["DYN_VERSION"] === 2) {
             $dynaFormOld = new \Dynaform();
             $arrayDynaFormData = $dynaFormOld->Load($dynaFormUidCopyImport);
             $arrayData["DYN_CONTENT"] = $arrayDynaFormData["DYN_CONTENT"];
         }
         //Create
         $arrayData = $this->create($processUid, $arrayData);
         $dynaFormUid = $arrayData[$this->getFieldNameByFormatFieldName("DYN_UID")];
         //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
                     $dynaFormGrid = new \Dynaform();
                     $arrayDataAux = array("PRO_UID" => $processUid, "DYN_TITLE" => $dynGrdTitleCopyImport . ($this->existsTitle($processUid, $dynGrdTitleCopyImport) ? " (" . $arrayData["DYN_TITLE"] . ")" : ""), "DYN_DESCRIPTION" => $dynGrdDescriptionCopyImport, "DYN_TYPE" => "grid");
                     $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;
     }
 }