protected function beforeSubmit(&$response, &$model, &$params) { if (isset($params['freq'])) { if (!empty($params['freq'])) { $rRule = new \GO\Base\Util\Icalendar\Rrule(); $rRule->readJsonArray($params); $model->rrule = $rRule->createRrule(); } else { $model->rrule = ''; } } if (!empty($params['remind'])) { // Check for a setted reminder $model->reminder = \GO\Base\Util\Date::to_unixtime($params['remind_date'] . ' ' . $params['remind_time']); } else { $model->reminder = 0; } if ($model->isNew && empty($params['remind']) && !isset($params['priority'])) { //This checks if it is called from the quickadd bar $model->reminder = $model->getDefaultReminder(\GO\Base\Util\Date::to_unixtime($params['start_time'])); } return parent::beforeSubmit($response, $model, $params); }
/** * Import a task from a VObject * * @param Sabre\VObject\Component $vobject * @param array $attributes Extra attributes to apply to the task. Raw values should be past. No input formatting is applied. * @return Task */ public function importVObject(Sabre\VObject\Component $vobject, $attributes = array()) { //$event = new \GO\Calendar\Model\Event(); $this->uuid = (string) $vobject->uid; $this->name = (string) $vobject->summary; $this->description = (string) $vobject->description; if (!empty($vobject->dtstart)) { $this->start_time = $vobject->dtstart->getDateTime()->format('U'); } if (!empty($vobject->dtend)) { $this->due_time = $vobject->dtend->getDateTime()->format('U'); if (empty($vobject->dtstart)) { $this->start_time = $this->due_time; } } if (!empty($vobject->due)) { $this->due_time = $vobject->due->getDateTime()->format('U'); } if (empty($vobject->dtstart)) { $this->start_time = 0; } if ($vobject->dtstamp) { $this->mtime = $vobject->dtstamp->getDateTime()->format('U'); } if (empty($this->due_time)) { $this->due_time = time(); } if ($vobject->rrule) { $rrule = new \GO\Base\Util\Icalendar\Rrule(); $rrule->readIcalendarRruleString($this->start_time, (string) $vobject->rrule); $rrule->shiftDays(false); $this->rrule = $rrule->createRrule(); if (isset($rrule->until)) { $this->repeat_end_time = $rrule->until; } } //var_dump($vobject->status); if ($vobject->status) { $this->status = (string) $vobject->status; } if ($vobject->duration) { $duration = \GO\Base\VObject\Reader::parseDuration($vobject->duration); $this->end_time = $this->start_time + $duration; } if (!empty($vobject->priority)) { if ((string) $vobject->priority > 5) { $this->priority = self::PRIORITY_LOW; } elseif ((string) $vobject->priority < 3) { $this->priority = self::PRIORITY_HIGH; } else { $this->priority = self::PRIORITY_NORMAL; } } if ((string) $vobject->completed != '') { $this->completion_time = $vobject->completed->getDateTime()->format('U'); $this->status = 'COMPLETED'; } else { $this->completion_time = 0; } if (!empty($vobject->{"percent-complete"})) { $this->percentage_complete = (string) $vobject->{"percent-complete"}; } if ($this->status == 'COMPLETED' && empty($this->completion_time)) { $this->completion_time = time(); } $this->reminder = 0; if ($vobject->valarm && $vobject->valarm->trigger) { $date = $vobject->valarm->getEffectiveTriggerTime(); if ($date) { $this->reminder = $date->format('U'); } } $this->setAttributes($attributes, false); $this->cutAttributeLengths(); if ($this->due_time < $this->start_time) { $this->due_time = $this->start_time; } $this->save(); return $this; }
/** * Converts an icalendar 2.0 to a vcalendar 1.0 component. * * @param Sabre_VObject_Component $vobject */ public static function convertICalendarToVCalendar(Sabre\VObject\Component $vobject) { $qpProperies = array('location', 'summary', 'description'); if ($vobject->version == '2.0') { $vobject->version = '1.0'; foreach ($vobject->children() as $child) { if ($child instanceof Sabre\VObject\Component) { foreach ($qpProperies as $propName) { self::_quotedPrintableEncode($child, $propName); } if (isset($child->rrule) && (string) $child->rrule != '') { $rrule = new \GO\Base\Util\Icalendar\Rrule(); $rrule->readIcalendarRruleString($child->dtstart->getDateTime()->format('U'), (string) $child->rrule); $child->rrule = str_replace('RRULE:', '', $rrule->createVCalendarRrule()); } if (isset($child->{"X-GO-REMINDER-TIME"})) { unset($child->valarm); $prop = new Sabre\VObject\Property\Text($vobject, 'AALARM', array((string) $child->{"X-GO-REMINDER-TIME"}, '', '0')); $prop->delimiter = ';'; $child->add($prop); //$child->{"X-GO-REMINDER-TIME"}.";;0;"; } } } } }
public function afterLoad(&$response, &$model, &$params) { // if (isset($response['data']['name'])) // $response['data']['subject'] = $response['data']['name']; $response = self::reminderSecondsToForm($response); $response['data']['start_time'] = date(\GO::user()->time_format, $model->start_time); $response['data']['end_time'] = date(\GO::user()->time_format, $model->end_time); if (isset($response['data']['rrule']) && !empty($response['data']['rrule'])) { $rRule = new \GO\Base\Util\Icalendar\Rrule(); $rRule->readIcalendarRruleString($model->start_time, $model->rrule); $createdRule = $rRule->createJSONOutput(); $response['data'] = array_merge($response['data'], $createdRule); } $response['data']['start_date'] = \GO\Base\Util\Date::get_timestamp($model->start_time, false); $response['data']['end_date'] = \GO\Base\Util\Date::get_timestamp($model->end_time, false); if (\GO::modules()->customfields) { $response['customfields'] = \GO\Customfields\Controller\CategoryController::getEnabledCategoryData("GO\\Calendar\\Model\\Event", $model->calendar->group_id); } $response['group_id'] = $model->calendar->group_id; if (!$model->id) { $days = array('SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA'); $response['data'][$days[date('w', $model->start_time)]] = 1; } if (!$model->isResource() && $model->id > 0) { $this->_loadResourceEvents($model, $response); } // $response['data']['has_other_participants']=$model->hasOtherParticipants(\GO::user()->id); $response['data']['user_name'] = $model->user ? $model->user->name : "Unknown"; if (empty($params['id'])) { $participantModel = $model->getDefaultOrganizerParticipant(); $response['participants'] = array('results' => array($participantModel->toJsonArray($model->start_time, $model->end_time)), 'total' => 1, 'success' => true); if (!empty($params['linkModelNameAndId'])) { $arr = explode(':', $params['linkModelNameAndId']); if ($arr[0] == 'GO\\Addressbook\\Model\\Contact') { $contact = \GO\Addressbook\Model\Contact::model()->findByPk($arr[1]); if ($contact) { $participantModel = new \GO\Calendar\Model\Participant(); $participantModel->setContact($contact); $response['participants']['results'][] = $participantModel->toJsonArray($model->start_time, $model->end_time); $response['participants']['total'] = 2; } } } } else { $particsStmt = \GO\Calendar\Model\Participant::model()->findByAttribute('event_id', $params['id']); $response['participants'] = array('results' => array(), 'total' => 0, 'success' => true); while ($participantModel = $particsStmt->fetch()) { $record = $participantModel->toJsonArray($model->start_time, $model->end_time); if (!empty($params['exception_date'])) { unset($record['id']); } $response['participants']['results'][] = $record; $response['participants']['total'] += 1; } if ($response['participants']['total'] == 0) { $participantModel = $model->getDefaultOrganizerParticipant(); $response['participants'] = array('results' => array($participantModel->toJsonArray($model->start_time, $model->end_time)), 'total' => 1, 'success' => true); } } return parent::afterLoad($response, $model, $params); }