/** * 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; }