public function createEvent($className, $params = null, $owner = null)
 {
     if (!is_subclass_of($className, Event::className())) {
         throw new \CException(sprintf('Class event `%s` must instanceof `%s`', $className, Event::className()));
     }
     /** @var $className Event */
     return new $className($params, $owner);
 }
Example #2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getEvents()
 {
     return $this->hasMany(Event::className(), ['user_id' => 'id']);
 }
Example #3
0
 public function getResponseData()
 {
     $dayString = \GO::t('full_days');
     $response = $this->_event->getAttributes('html');
     if ($this->isAllDay()) {
         $response['time'] = $this->getFormattedTime();
     } else {
         if (date(\GO::user()->date_format, $this->getAlternateStartTime()) != date(\GO::user()->date_format, $this->getAlternateEndTime())) {
             $response['time'] = $this->getFormattedTime();
         } else {
             $response['time'] = $this->getFormattedTime();
         }
     }
     //		$response['time_of_day'] = $this->getTimeOfDay();
     $response['status'] = $this->_event->status;
     $response['username'] = $this->_event->user ? $this->_event->user->getName() : \GO::t('unknown') . ' ' . \GO::t('user');
     $response['musername'] = !empty($this->_event->mUser) ? $this->_event->mUser->getName() : '';
     //		if($this->_event->status==Event::STATUS_CANCELLED){
     //			$response['name'] .= ' ('.$this->_event->localizedStatus.')';
     //		}
     //
     if ($this->_isMerged) {
         $response['name'] = $response['name'] . ' (' . implode(',', $this->_initials) . ')';
         $response['calendar_name'] = implode('; ', $this->_calendarNames);
         unset($response['status']);
         // unset this, it is not relevant to show this in merge view
         unset($response['username']);
         // unset this, it is not relevant to show this in merge view.
     } else {
         $response['calendar_name'] = $this->_calendarNames[0];
     }
     $response['id'] = $this->_event->id . ':' . $this->getAlternateStartTime();
     // a unique id for the data store. Is not really used.
     $response['background'] = $this->_backgroundColor;
     $response['start_time'] = date('Y-m-d H:i', $this->getAlternateStartTime());
     $response['end_time'] = date('Y-m-d H:i', $this->getAlternateEndTime());
     $response['ctime'] = date('Y-m-d H:i', $this->_event->ctime);
     $response['mtime'] = date('Y-m-d H:i', $this->_event->mtime);
     $response['event_id'] = $this->_event->id;
     $response['description'] = nl2br(htmlspecialchars(\GO\Base\Util\String::cut_string($this->_event->description, 800), ENT_COMPAT, 'UTF-8'));
     $response['private'] = $this->isPrivate();
     $response['private_enabled'] = $this->_event->private;
     $response['resources'] = array();
     if ($response['private']) {
         $response['name'] = \GO::t('private', 'calendar');
         $response['description'] = "";
         $response['location'] = "";
         $response['repeats'] = false;
         $response['has_reminder'] = false;
         $response['link_count'] = false;
         $response['status_color'] = false;
         $response['status'] = false;
     } else {
         $response['repeats'] = $this->isRepeating();
         $response['has_reminder'] = $response['reminder'] > 0 ? 1 : 0;
         $response['link_count'] = $this->getLinkCount();
         $response['status_color'] = $this->_event->getStatusColor();
         if ($this->_event->resources) {
             foreach ($this->_event->resources as $resourceModel) {
                 $response['resources'][$resourceModel->id] = $resourceModel->calendar->name;
             }
         }
     }
     $response['permission_level'] = $this->_event->permissionLevel;
     $response['all_day_event'] = $this->isAllDay();
     $response['day'] = $dayString[date('w', $this->getAlternateStartTime())] . ' ' . \GO\Base\Util\Date::get_timestamp($this->getAlternateStartTime(), false);
     // date(implode(\GO::user()->date_separator,str_split(\GO::user()->date_format,1)), ($eventModel->start_time));
     $response['read_only'] = $this->isReadOnly();
     $response['model_name'] = $this->_event->className();
     $response['partstatus'] = "none";
     if (isset($response['status']) && $response['status'] == Event::STATUS_CANCELLED) {
         //hack to make it transparent on cancelled status too in the view.
         $response['partstatus'] = Participant::STATUS_DECLINED;
     } else {
         if ($participant = $this->_event->getParticipantOfCalendar()) {
             $response['partstatus'] = $participant->status;
         }
     }
     $duration = $this->getDurationInMinutes();
     if ($duration >= 60) {
         $durationHours = floor($duration / 60);
         $durationRestMinutes = $duration % 60;
         $response['duration'] = $durationHours . ' ' . \GO::t('hours') . ', ' . $durationRestMinutes . ' ' . \GO::t('mins');
     } else {
         $response['duration'] = $duration . 'm';
     }
     return $response;
 }