예제 #1
0
 /**
  * Inserts Calendar term model.
  *
  * @param CalendarModel $term
  */
 public function save(CalendarModel $term)
 {
     $fields = array('title' => $term->getTitle(), 'place' => $term->getPlace(), 'start' => $term->getStart(), 'end' => $term->getEnd(), 'text' => $term->getText(), 'color' => $term->getColor());
     if ($term->getId()) {
         $this->db()->update('calendar')->values($fields)->where(array('id' => $term->getId()))->execute();
     } else {
         $this->db()->insert('calendar')->values($fields)->execute();
     }
 }
예제 #2
0
 public function treatAction()
 {
     $calendarMapper = new CalendarMapper();
     $calendarModel = new CalendarModel();
     if ($this->getRequest()->getParam('id')) {
         $this->getLayout()->getAdminHmenu()->add($this->getTranslator()->trans('menuCalendar'), array('action' => 'index'))->add($this->getTranslator()->trans('edit'), array('action' => 'treat'));
         $this->getView()->set('calendar', $calendarMapper->getCalendarById($this->getRequest()->getParam('id')));
     } else {
         $this->getLayout()->getAdminHmenu()->add($this->getTranslator()->trans('menuCalendar'), array('action' => 'index'))->add($this->getTranslator()->trans('add'), array('action' => 'treat'));
     }
     if ($this->getRequest()->isPost()) {
         if ($this->getRequest()->getParam('id')) {
             $calendarModel->setId($this->getRequest()->getParam('id'));
         }
         $title = trim($this->getRequest()->getPost('title'));
         $place = trim($this->getRequest()->getPost('place'));
         $start = new \Ilch\Date(trim($this->getRequest()->getPost('start')));
         $end = new \Ilch\Date(trim($this->getRequest()->getPost('end')));
         $text = trim($this->getRequest()->getPost('text'));
         $color = trim($this->getRequest()->getPost('color'));
         if (empty($start)) {
             $this->addMessage('missingDate', 'danger');
         } elseif (empty($title)) {
             $this->addMessage('missingTitle', 'danger');
         } else {
             $calendarModel->setTitle($title);
             $calendarModel->setPlace($place);
             $calendarModel->setStart($start);
             $calendarModel->setEnd($end);
             $calendarModel->setText($text);
             $calendarModel->setColor($color);
             $calendarMapper->save($calendarModel);
             $this->addMessage('saveSuccess');
             $this->redirect(array('action' => 'index'));
         }
     }
 }