Пример #1
0
 /**
  * Constructor
  *
  * @access public
  * @return object
  */
 public function __construct()
 {
     $this->_loadPrimaryKeyName(LibEntity::getPrimaryKeyName($this));
     $this->_loadPrimaryKeyNameWithoutMapping(LibEntity::getPrimaryKeyNameWithoutMapping($this));
     /**
      * Trigger on a model to initialize it. You could fill entity with it.
      */
     if (method_exists(get_called_class(), 'initialize')) {
         if (!isset(self::$_aInitialize[get_called_class()])) {
             static::initialize();
             self::$_aInitialize[get_called_class()] = true;
         }
     }
     /**
      * Trigger on a model to initialize it every time you construct it
      */
     if (method_exists(get_called_class(), 'onConstruct')) {
         static::onConstruct();
     }
 }
Пример #2
0
 /**
  * get global object form
  *
  * @access public
  * @return \stdClass
  */
 public function getFormInObject()
 {
     $sExKey = null;
     if ($this->_iIdEntity > 0 && $this->_sSynchronizeEntity !== null && count($_POST) < 1) {
         $sModelName = str_replace('Entity', 'Model', $this->_sSynchronizeEntity);
         $oModel = new $sModelName();
         $oEntity = new $this->_sSynchronizeEntity();
         $sPrimaryKey = LibEntity::getPrimaryKeyNameWithoutMapping($oEntity);
         $sMethodName = 'findOneBy' . $sPrimaryKey;
         $oCompleteEntity = call_user_func_array(array(&$oModel, $sMethodName), array($this->_iIdEntity));
         if (is_object($oCompleteEntity)) {
             foreach ($this->_aElement as $sKey => $sValue) {
                 if ($sValue instanceof \Venus\lib\Form\Radio) {
                     $sExKey = $sKey;
                     $sKey = substr($sKey, 0, -6);
                 }
                 if ($sValue instanceof Form) {
                 } else {
                     $sMethodNameInEntity = 'get_' . $sKey;
                     $mValue = $oCompleteEntity->{$sMethodNameInEntity}();
                     if ($sValue instanceof \Venus\lib\Form\Radio && method_exists($this->_aElement[$sExKey], 'setValueChecked')) {
                         $this->_aElement[$sExKey]->setValueChecked($mValue);
                     } else {
                         if (isset($mValue) && method_exists($this->_aElement[$sKey], 'setValue')) {
                             $this->_aElement[$sKey]->setValue($mValue);
                         }
                     }
                 }
             }
         }
     }
     $oForm = new \StdClass();
     $oForm->start = '<form name="form' . $this->_iFormNumber . '" method="post"><input type="hidden" value="1" name="validform' . $this->_iFormNumber . '">';
     $oForm->form = array();
     foreach ($this->_aElement as $sKey => $sValue) {
         if ($sValue instanceof Container) {
             $oForm->form[$sKey] = $sValue;
         } else {
             $oForm->form[$sKey] = $sValue->fetch();
         }
     }
     $oForm->end = '</form>';
     return $oForm;
 }
Пример #3
0
 /**
  * handle the request to do many actions on it
  *
  * @access public
  * @param  array $aRequest request like $_POST
  * @return bool
  */
 public function handleRequest(array $aRequest) : bool
 {
     if (!count($_POST)) {
         return true;
     }
     // Validation
     foreach ($this->_oForm->getElement() as $sKey => $sValue) {
         if (!$sValue instanceof self && !$this->_validate($sValue)) {
             return false;
         }
     }
     // Save
     if ($this->_oForm->getIdEntity() > 0 && $this->_oForm->getSynchronizeEntity() !== null && count($aRequest) > 0) {
         $sModelName = str_replace('Entity', 'Model', $this->_oForm->getSynchronizeEntity());
         $oModel = new $sModelName();
         $oEntity = new $this->_oForm->getSynchronizeEntity();
         $sPrimaryKey = LibEntity::getPrimaryKeyNameWithoutMapping($oEntity);
         $sMethodName = 'set_' . $sPrimaryKey;
         call_user_func_array(array(&$oEntity, $sMethodName), array($this->_oForm->getIdEntity()));
         foreach ($this->_oForm->getElement() as $sKey => $sValue) {
             $sMethodName = 'set_' . $sValue->getName() . '';
             call_user_func_array(array(&$oEntity, $sMethodName), array($aRequest[$sValue->getName()]));
         }
         $oEntity->save();
     } else {
         if ($this->_oForm->getSynchronizeEntity() !== null && isset($aRequest) && count($aRequest) > 0) {
             $oEntity = new $this->_oForm->_sSynchronizeEntity();
             foreach ($this->_oForm->getElement() as $sKey => $sValue) {
                 $sMethodName = 'set_' . $sValue->getName() . '';
                 call_user_func_array(array(&$oEntity, $sMethodName), array($aRequest[$sValue->getName()]));
             }
             $this->_oForm->setIdEntityCreated($oEntity->save());
         }
     }
     $this->_bHandleRequestActivate = true;
     $this->_aRequest = $aRequest;
     return true;
 }