/** * Valide la clé est retourne le roster associé. * @return \Commun\Model\Roster */ protected function valideKey() { $rosterKey = $this->params()->fromRoute('key', 1); $cacheKey = $this->getCacheKey('APIRtK-roster', array($rosterKey)); // recherche dans le cache if ($this->_getCacheService()->hasItem($cacheKey) === true) { $oRoster = new \Commun\Model\Roster(); $aCache = (array) $this->_getCacheService()->getItem($cacheKey); $oRoster->exchangeArray($aCache); return $oRoster; } $oRoster = $this->getTableRoster()->selectBy(array("key" => $rosterKey)); if (!$oRoster) { $msg = $this->_getServTranslator()->translate("La clé fournit est invalide."); $this->_getLogService()->log(LogService::ERR, $msg, LogService::USER, $this->getRequest()->getPost()); $this->flashMessenger()->addMessage($msg, 'error'); $this->getResponse()->setStatusCode(500); return null; } else { // Ajoute au cache $aRoster = $oRoster->getArrayCopy(); $this->_getCacheService()->addItem($cacheKey, $aRoster); return $oRoster; } }
/** * Action pour la création. * * @return array */ public function createAction() { $oForm = new \Commun\Form\RosterForm(); //new \Commun\Form\RosterForm($this->getServiceLocator()); $oRequest = $this->getRequest(); $oFiltre = new \Commun\Filter\RosterFilter(); $oForm->setInputFilter($oFiltre->getInputFilter()); if ($oRequest->isPost()) { $oEntite = new \Commun\Model\Roster(); $oForm->setData($oRequest->getPost()); if ($oForm->isValid()) { $oEntite->exchangeArray($oForm->getData()); try { $this->getTableRoster()->beginTransaction(); $oEntite = $this->getTableRoster()->saveOrUpdateRoster($oEntite); $this->getTableRoster()->commit(); $this->flashMessenger()->addMessage($this->_getServTranslator()->translate("Le roster a été créé avec succès."), 'success'); return $this->redirect()->toRoute('backend-roster-update', array('id' => $oEntite->getIdRoster())); } catch (\Exception $ex) { // on rollback en cas d'erreur $this->getTableRoster()->rollback(); $aAjaxEx = \Core\Util\ParseException::tranformeExceptionToArray($ex); $this->flashMessenger()->addMessage($this->_getServTranslator()->translate("La création du roster a échoué."), 'error'); $this->flashMessenger()->addMessage($this->_getServTranslator()->translate($aAjaxEx['msg']), 'error'); } } } // Pour optimiser le rendu $oViewModel = new ViewModel(); $oViewModel->setTemplate('backend/roster/create'); return $oViewModel->setVariables(array('form' => $oForm)); }