/** * Returns page model found by the key. * * @param string $id * @param string $locale * @return PageModel|null */ public function getPageByIdLocale($id, $locale = '') { $sql = 'SELECT * FROM [prefix]_pages as p INNER JOIN [prefix]_pages_content as pc ON p.id = pc.page_id WHERE p.`id` = "' . (int) $id . '" AND pc.locale = "' . $this->db()->escape($locale) . '"'; $pageRow = $this->db()->queryRow($sql); if (empty($pageRow)) { return null; } $pageModel = new PageModel(); $pageModel->setId($pageRow['id']); $pageModel->setDescription($pageRow['description']); $pageModel->setTitle($pageRow['title']); $pageModel->setContent($pageRow['content']); $pageModel->setLocale($pageRow['locale']); $pageModel->setPerma($pageRow['perma']); return $pageModel; }
public function treatAction() { if ($this->getRequest()->getParam('id')) { $this->getLayout()->getAdminHmenu()->add($this->getTranslator()->trans('menuSite'), array('action' => 'index'))->add($this->getTranslator()->trans('editPage'), array('action' => 'treat', 'id' => $this->getRequest()->getParam('id'))); } else { $this->getLayout()->getAdminHmenu()->add($this->getTranslator()->trans('menuSite'), array('action' => 'index'))->add($this->getTranslator()->trans('menuActionNewSite'), array('action' => 'treat')); } $this->getView()->set('contentLanguage', $this->getConfig()->get('content_language')); $pageMapper = new PageMapper(); if ($this->getRequest()->getParam('id')) { if ($this->getRequest()->getParam('locale') == '') { $locale = ''; } else { $locale = $this->getRequest()->getParam('locale'); } $this->getView()->set('page', $pageMapper->getPageByIdLocale($this->getRequest()->getParam('id'), $locale)); } $this->getView()->set('languages', $this->getTranslator()->getLocaleList()); $this->getView()->set('multilingual', (bool) $this->getConfig()->get('multilingual_acp')); if ($this->getRequest()->isPost()) { $model = new PageModel(); if ($this->getRequest()->getParam('id')) { $model->setId($this->getRequest()->getParam('id')); } $model->setDescription($this->getRequest()->getPost('description')); $model->setTitle($this->getRequest()->getPost('pageTitle')); $model->setContent($this->getRequest()->getPost('pageContent')); if ($this->getRequest()->getPost('pageLanguage') != '') { $model->setLocale($this->getRequest()->getPost('pageLanguage')); } else { $model->setLocale(''); } $model->setPerma($this->getRequest()->getPost('pagePerma')); $pageMapper->save($model); $this->redirect(array('action' => 'index')); } }