Ejemplo n.º 1
0
 function save()
 {
     $flash = Flash::Instance();
     $calendar = new Calendar();
     if (isset($this->_data['Calendar']['id']) && !$calendar->isOwner($this->_data['Calendar']['id'])) {
         $flash->addError("You cannot save a calendar that belongs to someone else");
         sendTo('calendars', 'index', 'calendar');
     }
     // if we dont specify any shared users, pass an empty array
     if (isset($this->_data['CalendarShareCollection'])) {
         if (!$this->checkParams(array('Calendar', 'CalendarShareCollection'))) {
             sendBack();
         }
     }
     if ($this->_data['Calendar']['type'] == 'gcal' && (!isset($this->_data['Calendar']['gcal_url']) || empty($this->_data['Calendar']['gcal_url']))) {
         $flash->addError("You haven't specified a feed URL");
         sendBack();
     }
     if (!isset($this->_data['Calendar']['colour'])) {
         $colours = $calendar->getEnumOptions('colour');
         $this->_data['Calendar']['colour'] = $colours[array_rand($colours)];
     }
     if (isset($this->_data['Calendar']['id'])) {
         $calendarshare = new CalendarShareCollection(new CalendarShare());
         $sh = new SearchHandler($calendarshare, false);
         $sh->addConstraint(new Constraint('calendar_id', '=', $this->_data['Calendar']['id']));
         $calendarshare->delete($sh);
     }
     // apply calendar_id to CalendarShareCollection
     if (isset($this->_data['CalendarShareCollection']) && !empty($this->_data['CalendarShareCollection']['username'])) {
         foreach ($this->_data['CalendarShareCollection']['username'] as $key => $value) {
             $this->_data['CalendarShareCollection']['calendar_id'][$key] = '';
         }
     }
     $errors = array();
     if (parent::save('Calendar', '', $errors)) {
         sendTo('index', 'index', 'calendar');
     } else {
         sendBack();
     }
 }