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')); } }
/** * Inserts or updates a box model in the database. * * @param BoxModel $box */ public function save(BoxModel $box) { if ($box->getId()) { if ($this->getBoxByIdLocale($box->getId(), $box->getLocale())) { $this->db()->update('boxes_content')->values(array('title' => $box->getTitle(), 'content' => $box->getContent()))->where(array('box_id' => $box->getId(), 'locale' => $box->getLocale()))->execute(); } else { $this->db()->insert('boxes_content')->values(array('box_id' => $box->getId(), 'title' => $box->getTitle(), 'content' => $box->getContent(), 'locale' => $box->getLocale()))->execute(); } } else { $date = new \Ilch\Date(); $boxId = $this->db()->insert('boxes')->values(array('date_created' => $date->toDb()))->execute(); $this->db()->insert('boxes_content')->values(array('box_id' => $boxId, 'title' => $box->getTitle(), 'content' => $box->getContent(), 'locale' => $box->getLocale()))->execute(); } }