<commit_before><?php
/**
 * Dynaform.php
 * @package    workflow.engine.classes.model
 * 
 * ProcessMaker Open Source Edition
 * Copyright (C) 2004 - 2011 Colosa Inc.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
 * Coral Gables, FL, 33134, USA, or email <EMAIL>.
 *
 */

require_once 'classes/model/om/BaseDynaform.php';
require_once 'classes/model/Content.php';
require_once('classes/model/AdditionalTables.php');
G::LoadClass('dynaFormField');

/**
 * Skeleton subclass for representing a row from the 'DYNAFORM' table.
 *
 *
 *
 * You should add additional methods to this class to meet the
 * application requirements.  This class will only be generated as
 * long as it does not already exist in the output directory.
 *
 * @package    workflow.engine.classes.model
 */
class Dynaform extends BaseDynaform {
  /**
   * This value goes in the content table
   * @var        string
   */
  protected $dyn_title = '';

  /**
   * Get the [Dyn_title] column value.
   * @return     string
   */
  public function getDynTitle()
  {
    if ( $this->getDynUid() == '' ) {
      throw ( new Exception( "Error in getDynTitle, the DYN_UID can't be blank") );
    }
    $lang = defined ( 'SYS_LANG') ? SYS_LANG : 'en';
    $this->dyn_title = Content::load ( 'DYN_TITLE', '', $this->getDynUid(), $lang );
    return $this->dyn_title;
  }

  /**
   * Set the [Dyn_title] column value.
   *
   * @param      string $v new value
   * @return     void
   */
  public function setDynTitle($v)
  {
    if ( $this->getDynUid() == '' ) {
      throw ( new Exception( "Error in setDynTitle, the DYN_UID can't be blank") );
    }
    // Since the native PHP type for this column is string,
    // we will cast the input to a string (if it is not).
    if ($v !== null && !is_string($v)) {
      $v = (string) $v;
    }

    if ($this->dyn_title !== $v || $v === '') {
      $this->dyn_title = $v;
      $lang = defined ( 'SYS_LANG') ? SYS_LANG : 'en';
 
      $res = Content::addContent( 'DYN_TITLE', '', $this->getDynUid(), $lang, $this->dyn_title );
    }

  } // set()

  /**
   * This value goes in the content table
   * @var        string
   */
  protected $dyn_description = '';

  /**
   * Get the [Dyn_description] column value.
   * @return     string
   */
  public function getDynDescription()
  {
    if ( $this->getDynUid() == '' ) {
      throw ( new Exception( "Error in getDynDescription, the DYN_UID can't be blank") );
    }
    $lang = defined ( 'SYS_LANG') ? SYS_LANG : 'en';
    $this->dyn_description = Content::load ( 'DYN_DESCRIPTION', '', $this->getDynUid(), $lang );
    return $this->dyn_description;
  }

  /**
   * Set the [Dyn_description] column value.
   *
   * @param      string $v new value
   * @return     void
   */
  public function setDynDescription($v)
  {
    if ( $this->getDynUid() == '' ) {
      throw ( new Exception( "Error in setDynDescription, the DYN_UID can't be blank") );
    }
    // Since the native PHP type for this column is string,
    // we will cast the input to a string (if it is not).
    if ($v !== null && !is_string($v)) {
      $v = (string) $v;
    }

    if ($this->dyn_description !== $v || $v === '') {
      $this->dyn_description = $v;
      $lang = defined ( 'SYS_LANG') ? SYS_LANG : 'en';
     
      $res = Content::addContent( 'DYN_DESCRIPTION', '', $this->getDynUid(), $lang, $this->dyn_description );
    }

  } // set()

  /**
   * Creates the Dynaform
   *
   * @param      array $aData  Fields with :
   *                   $aData['DYN_UID'] the dynaform id
   *                   $aData['USR_UID'] the userid
   * @return     void
   */

  function create ($aData ) {
    if ( !isset ( $aData['PRO_UID'] ) ) {
       throw ( new PropelException ( 'The dynaform cannot be created. The PRO_UID is empty.' ) );
    }
    $con = Propel::getConnection( DynaformPeer::DATABASE_NAME );
    try {
      if ( isset ( $aData['DYN_UID'] ) && $aData['DYN_UID']== '' )
        unset ( $aData['DYN_UID'] );
      if ( !isset ( $aData['DYN_UID'] ) )
        $dynUid  = ( G::generateUniqueID() );
      else
        $dynUid  = $aData['DYN_UID'];
      $this->setDynUid          ( $dynUid );
      $this->setProUid          ( $aData['PRO_UID'] );
      $this->setDynType         ( isset($aData['DYN_TYPE'])?$aData['DYN_TYPE']:'xmlform' );
      $this->setDynFilename     ( $aData['PRO_UID'] . PATH_SEP . $dynUid );

      if ( $this->validate() ) {
        $con->begin();
        $res = $this->save();

        if (isset ( $aData['DYN_TITLE'] ) )
          $this->setDynTitle (  $aData['DYN_TITLE'] );
        else
          $this->setDynTitle (  'Default Dynaform Title' );

        if (isset ( $aData['DYN_DESCRIPTION'] ) )
          $this->setDynDescription (  $aData['DYN_DESCRIPTION'] );
        else
          $this->setDynDescription (  'Default Dynaform Description' );

        $con->commit();
        $sXml  = '<?xml version="1.0" encoding="UTF-8"?>'."\n";
        $sXml .= '<dynaForm type="' . $this->getDynType() . '" name="' . $this->getProUid() . '/' . $this->getDynUid() . '" width="500" enabletemplate="0" mode="edit">'."\n";
        $sXml .= '</dynaForm>';
        G::verifyPath(PATH_DYNAFORM . $this->getProUid(), true);
        $oFile = fopen(PATH_DYNAFORM . $this->getProUid() . '/' . $this->getDynUid() . '.xml', 'w');
        fwrite($oFile, $sXml);
        fclose($oFile);
        return $this->getDynUid();
      }
      else {
       $msg = '';
       foreach($this->getValidationFailures() as $objValidationFailure)
         $msg .= $objValidationFailure->getMessage() . "<br/>";
       throw ( new PropelException ( 'The row cannot be created!', new PropelException ( $msg ) ) );
      }

    }
    catch (Exception $e) {
      $con->rollback();
      throw ($e);
    }
  }

  /**
   *
   * Creates a Dynaform based on a PMTable
   * 
   * @name       createFromPMTable
   * @author     <NAME> gustavo[at]colosa[dot]com
   * @param      array $aData  Fields with :
   *                   $aData['DYN_UID'] the dynaform id
   *                   $aData['USR_UID'] the userid<commit_msg>BUG 9214 Los campos que son creados en modo vista no estan en modo vista solved<commit_after><?php
/**
 * Dynaform.php
 * @package    workflow.engine.classes.model
 * 
 * ProcessMaker Open Source Edition
 * Copyright (C) 2004 - 2011 Colosa Inc.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
 * Coral Gables, FL, 33134, USA, or email <EMAIL>.
 *
 */

require_once 'classes/model/om/BaseDynaform.php';
require_once 'classes/model/Content.php';
require_once('classes/model/AdditionalTables.php');
G::LoadClass('dynaFormField');

/**
 * Skeleton subclass for representing a row from the 'DYNAFORM' table.
 *
 *
 *
 * You should add additional methods to this class to meet the
 * application requirements.  This class will only be generated as
 * long as it does not already exist in the output directory.
 *
 * @package    workflow.engine.classes.model
 */
class Dynaform extends BaseDynaform {
  /**
   * This value goes in the content table
   * @var        string
   */
  protected $dyn_title = '';

  /**
   * Get the [Dyn_title] column value.
   * @return     string
   */
  public function getDynTitle()
  {
    if ( $this->getDynUid() == '' ) {
      throw ( new Exception( "Error in getDynTitle, the DYN_UID can't be blank") );
    }
    $lang = defined ( 'SYS_LANG') ? SYS_LANG : 'en';
    $this->dyn_title = Content::load ( 'DYN_TITLE', '', $this->getDynUid(), $lang );
    return $this->dyn_title;
  }

  /**
   * Set the [Dyn_title] column value.
   *
   * @param      string $v new value
   * @return     void
   */
  public function setDynTitle($v)
  {
    if ( $this->getDynUid() == '' ) {
      throw ( new Exception( "Error in setDynTitle, the DYN_UID can't be blank") );
    }
    // Since the native PHP type for this column is string,
    // we will cast the input to a string (if it is not).
    if ($v !== null && !is_string($v)) {
      $v = (string) $v;
    }

    if ($this->dyn_title !== $v || $v === '') {
      $this->dyn_title = $v;
      $lang = defined ( 'SYS_LANG') ? SYS_LANG : 'en';
 
      $res = Content::addContent( 'DYN_TITLE', '', $this->getDynUid(), $lang, $this->dyn_title );
    }

  } // set()

  /**
   * This value goes in the content table
   * @var        string
   */
  protected $dyn_description = '';

  /**
   * Get the [Dyn_description] column value.
   * @return     string
   */
  public function getDynDescription()
  {
    if ( $this->getDynUid() == '' ) {
      throw ( new Exception( "Error in getDynDescription, the DYN_UID can't be blank") );
    }
    $lang = defined ( 'SYS_LANG') ? SYS_LANG : 'en';
    $this->dyn_description = Content::load ( 'DYN_DESCRIPTION', '', $this->getDynUid(), $lang );
    return $this->dyn_description;
  }

  /**
   * Set the [Dyn_description] column value.
   *
   * @param      string $v new value
   * @return     void
   */
  public function setDynDescription($v)
  {
    if ( $this->getDynUid() == '' ) {
      throw ( new Exception( "Error in setDynDescription, the DYN_UID can't be blank") );
    }
    // Since the native PHP type for this column is string,
    // we will cast the input to a string (if it is not).
    if ($v !== null && !is_string($v)) {
      $v = (string) $v;
    }

    if ($this->dyn_description !== $v || $v === '') {
      $this->dyn_description = $v;
      $lang = defined ( 'SYS_LANG') ? SYS_LANG : 'en';
     
      $res = Content::addContent( 'DYN_DESCRIPTION', '', $this->getDynUid(), $lang, $this->dyn_description );
    }

  } // set()

  /**
   * Creates the Dynaform
   *
   * @param      array $aData  Fields with :
   *                   $aData['DYN_UID'] the dynaform id
   *                   $aData['USR_UID'] the userid
   * @return     void
   */

  function create ($aData ) {
    if ( !isset ( $aData['PRO_UID'] ) ) {
       throw ( new PropelException ( 'The dynaform cannot be created. The PRO_UID is empty.' ) );
    }
    $con = Propel::getConnection( DynaformPeer::DATABASE_NAME );
    try {
      if ( isset ( $aData['DYN_UID'] ) && $aData['DYN_UID']== '' )
        unset ( $aData['DYN_UID'] );
      if ( !isset ( $aData['DYN_UID'] ) )
        $dynUid  = ( G::generateUniqueID() );
      else
        $dynUid  = $aData['DYN_UID'];
      $this->setDynUid          ( $dynUid );
      $this->setProUid          ( $aData['PRO_UID'] );
      $this->setDynType         ( isset($aData['DYN_TYPE'])?$aData['DYN_TYPE']:'xmlform' );
      $this->setDynFilename     ( $aData['PRO_UID'] . PATH_SEP . $dynUid );

      if ( $this->validate() ) {
        $con->begin();
        $res = $this->save();

        if (isset ( $aData['DYN_TITLE'] ) )
          $this->setDynTitle (  $aData['DYN_TITLE'] );
        else
          $this->setDynTitle (  'Default Dynaform Title' );

        if (isset ( $aData['DYN_DESCRIPTION'] ) )
          $this->setDynDescription (  $aData['DYN_DESCRIPTION'] );
        else
          $this->setDynDescription (  'Default Dynaform Description' );

        $con->commit();
        $sXml  = '<?xml version="1.0" encoding="UTF-8"?>'."\n";
        $sXml .= '<dynaForm type="' . $this->getDynType() . '" name="' . $this->getProUid() . '/' . $this->getDynUid() . '" width="500" enabletemplate="0" mode="">'."\n";
        $sXml .= '</dynaForm>';
        G::verifyPath(PATH_DYNAFORM . $this->getProUid(), true);
        $oFile = fopen(PATH_DYNAFORM . $this->getProUid() . '/' . $this->getDynUid() . '.xml', 'w');
        fwrite($oFile, $sXml);
        fclose($oFile);
        return $this->getDynUid();
      }
      else {
       $msg = '';
       foreach($this->getValidationFailures() as $objValidationFailure)
         $msg .= $objValidationFailure->getMessage() . "<br/>";
       throw ( new PropelException ( 'The row cannot be created!', new PropelException ( $msg ) ) );
      }

    }
    catch (Exception $e) {
      $con->rollback();
      throw ($e);
    }
  }

  /**
   *
   * Creates a Dynaform based on a PMTable
   * 
   * @name       createFromPMTable
   * @author     <NAME> gustavo[at]colosa[dot]com
   * @param      array $aData  Fields with :
   *                   $aData['DYN_UID'] the dynaform id
   *                   $aData['USR_UID'] the userid
{'fraction_non_alphanumeric': 0.15546713822575892, 'fraction_numerical': 0.003978779840848806, 'mean_word_length': 2.5018059855521155, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 2, '>': 97, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6260338', 'n_tokens_mistral': 4595, 'n_tokens_neox': 4470, 'n_words': 1212}