public function update($id, Application_Model_Encyclopedie_Article_Writer_Data $data) { try { $this->_encyclopedieArticleTable->getAdapter()->beginTransaction(); $this->_encyclopedieArticleTable->update(array("active" => $data->getActive()), 'id = ' . intval($id)); foreach ($data->getLocales() as $locale => $content) { if (!$this->_localeLanguageTable->exists($locale)) { throw new Application_Model_Exception("{$locale} is not in DB"); } $this->_encyclopedieArticleTranslateTable->updateRow($locale, $id, $content['title'], $content['text']); } $this->_encyclopedieArticleTable->getAdapter()->commit(); } catch (Zend_Exception $e) { $this->_encyclopedieArticleTable->getAdapter()->rollBack(); throw new Application_Model_Exception("Can't update article", null, $e); } }
public function modifArticleAction() { $params = $this->getRequest()->getParams(); try { $form = new Form_Unlog_Backend_Encyclopedie_Article_Modif(); if (empty($params['Form_Unlog_Backend_Encyclopedie_Article_Modif_Submit'])) { $source = new Application_Model_DbTable_Encyclopedie_Article_Translate(); $rows = $source->getByArticleId($params['id']); foreach ($rows as $row) { $params['Form_Unlog_Backend_Encyclopedie_Article_Modif_Titre_' . $row['locale']] = $row['titre']; $params['Form_Unlog_Backend_Encyclopedie_Article_Modif_Text_' . $row['locale']] = $row['text']; } } $form->populate($params); if (!empty($params['Form_Unlog_Backend_Encyclopedie_Article_Modif_Submit']) && $form->isValid($params)) { $data = new Application_Model_Encyclopedie_Article_Writer_Data("01/01/2000 10:10", 0); foreach ($params as $key => $param) { if (preg_match("#^Form_Unlog_Backend_Encyclopedie_Article_Modif_Titre_#", $key)) { $localeCode = substr($key, strlen("Form_Unlog_Backend_Encyclopedie_Article_Modif_Titre_")); $data->addLocale($localeCode, $param, $params['Form_Unlog_Backend_Encyclopedie_Article_Modif_Text_' . $localeCode]); } } $model = new Application_Model_Encyclopedie_Article_Writer(); $model->update($params['id'], $data); $this->_forward("index", "encyclopedie", "unlog-backend"); } $this->view->form = $form; } catch (Zend_Exception $e) { throw new Zend_Controller_Action_Exception("Error in Action : unlog-backend | encyclopedie | modifArticle", null, $e); } }