Exemple #1
0
 /**
  * Returns box model found by the key.
  *
  * @param string $id
  * @param string $locale
  * @return BoxModel|null
  */
 public function getBoxByIdLocale($id, $locale = '')
 {
     $sql = 'SELECT * FROM [prefix]_boxes as b
             INNER JOIN [prefix]_boxes_content as bc ON b.id = bc.box_id
             WHERE b.`id` = "' . (int) $id . '" AND bc.locale = "' . $this->db()->escape($locale) . '"';
     $boxRow = $this->db()->queryRow($sql);
     if (empty($boxRow)) {
         return null;
     }
     $boxModel = new BoxModel();
     $boxModel->setId($boxRow['id']);
     $boxModel->setTitle($boxRow['title']);
     $boxModel->setContent($boxRow['content']);
     $boxModel->setLocale($boxRow['locale']);
     return $boxModel;
 }
Exemple #2
0
 public function treatAction()
 {
     if ($this->getRequest()->getParam('id') !== null) {
         $user = \Ilch\Registry::get('user');
         if (!$user->hasAccess('box_' . $this->getRequest()->getParam('id'))) {
             $this->redirect(array('action' => 'index'));
         }
     }
     $this->getView()->set('contentLanguage', $this->getConfig()->get('content_language'));
     $boxMapper = new BoxMapper();
     if ($this->getRequest()->getParam('id')) {
         if ($this->getRequest()->getParam('locale') == '') {
             $locale = '';
         } else {
             $locale = $this->getRequest()->getParam('locale');
         }
         $this->getView()->set('box', $boxMapper->getBoxByIdLocale($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 BoxModel();
         if ($this->getRequest()->getParam('id')) {
             $model->setId($this->getRequest()->getParam('id'));
         }
         $model->setTitle($this->getRequest()->getPost('boxTitle'));
         $model->setContent($this->getRequest()->getPost('boxContent'));
         if ($this->getRequest()->getPost('boxLanguage') != '') {
             $model->setLocale($this->getRequest()->getPost('boxLanguage'));
         } else {
             $model->setLocale('');
         }
         $boxMapper->save($model);
         $this->redirect(array('action' => 'index'));
     }
 }