public static function initListeners() { if (\GO::modules()->isInstalled('calendar')) { \GO\Calendar\Model\Event::model()->addListener("delete", "GO\\Caldav\\CaldavModule", "deleteEvent"); } if (\GO::modules()->isInstalled('tasks')) { \GO\Tasks\Model\Task::model()->addListener("delete", "GO\\Caldav\\CaldavModule", "deleteTask"); } }
public function actionReload($params) { $event = empty($params['event_id']) ? false : \GO\Calendar\Model\Event::model()->findByPk($params['event_id']); $participantAttrs = json_decode($params['participants']); $store = new \GO\Base\Data\ArrayStore(); foreach ($participantAttrs as $participantAttr) { $participant = new \GO\Calendar\Model\Participant(); $participant->setAttributes($participantAttr); if ($event) { $participant->event_id = $event->id; } $store->addRecord($participant->toJsonArray($params['start_time'], $params['end_time'])); } return $store->getData(); }
protected function actionSubmit($params) { $response = array("success" => true); $event = \GO\Calendar\Model\Event::model()->findByPk($params['id']); if (!$event) { throw new \GO\Base\Exception\NotFound(); } if (!empty($params['exception_date'])) { $event = $event->createExceptionEvent($params['exception_date']); } $participant = $event->getParticipantOfCalendar(); if ($params['status'] != $participant->status) { $participant->status = $params['status']; $participant->save(); if (!empty($params['notify_organizer'])) { $event->replyToOrganizer(); } } return $response; }
/** * Get the data for the grid that shows all the tasks from the selected calendars. * * @param Array $params * @return Array The array with the data for the grid. */ protected function actionPortletGrid($params) { $local_time = time(); $year = date("Y", $local_time); $month = date("m", $local_time); $day = date("j", $local_time); $periodStartTime = mktime(0, 0, 0, $month, $day, $year); $periodEndTime = mktime(0, 0, 0, $month, $day + 2, $year); $today_end = mktime(0, 0, 0, $month, $day + 1, $year); $joinCriteria = \GO\Base\Db\FindCriteria::newInstance()->addCondition('user_id', \GO::user()->id, '=', 'pt')->addCondition('calendar_id', 'pt.calendar_id', '=', 't', true, true); $calendarJoinCriteria = \GO\Base\Db\FindCriteria::newInstance()->addCondition('calendar_id', 'tl.id', '=', 't', true, true); $findParams = \GO\Base\Db\FindParams::newInstance()->select('t.*, tl.name AS calendar_name')->join(\GO\Calendar\Model\PortletCalendar::model()->tableName(), $joinCriteria, 'pt')->join(\GO\Calendar\Model\Calendar::model()->tableName(), $calendarJoinCriteria, 'tl'); $events = \GO\Calendar\Model\Event::model()->findCalculatedForPeriod($findParams, $periodStartTime, $periodEndTime); $store = new \GO\Base\Data\ArrayStore(); foreach ($events as $event) { $record = $event->getResponseData(); $record['day'] = $event->getAlternateStartTime() < $today_end ? \GO::t('today') : \GO::t('tomorrow'); $record['time'] = $event->getEvent()->all_day_event == 1 ? '-' : $record['time']; $store->addRecord($record); } return $store->getData(); }
private function _handleInvitations(\GO\Email\Model\ImapMessage $imapMessage, $params, $response) { if (!GO::modules()->isInstalled('calendar')) { return $response; } $vcalendar = $imapMessage->getInvitationVcalendar(); if ($vcalendar) { $vevent = $vcalendar->vevent[0]; //is this an update for a specific recurrence? $recurrenceDate = isset($vevent->{"recurrence-id"}) ? $vevent->{"recurrence-id"}->getDateTime()->format('U') : 0; //find existing event $event = \GO\Calendar\Model\Event::model()->findByUuid((string) $vevent->uid, $imapMessage->account->user_id, $recurrenceDate); // var_dump($event); $uuid = (string) $vevent->uid; $alreadyProcessed = false; if ($event) { //import to check if there are relevant updates $event->importVObject($vevent, array(), true); $alreadyProcessed = false; //!$event->isModified($event->getRelevantMeetingAttributes()); // throw new \Exception(\GO\Base\Util\Date::get_timestamp($vevent->{"last-modified"}->getDateTime()->format('U')).' < '.\GO\Base\Util\Date::get_timestamp($event->mtime)); // if($vevent->{"last-modified"}) { // $alreadyProcessed=$vevent->{"last-modified"}->getDateTime()->format('U')<=$event->mtime && $event->is_organizer; // }else // { // $alreadyProcessed=!$event->isModified($event->getRelevantMeetingAttributes()); // } } // if(!$event || $event->is_organizer){ switch ($vcalendar->method) { case 'CANCEL': $response['iCalendar']['feedback'] = GO::t('iCalendar_event_cancelled', 'email'); break; case 'REPLY': $response['iCalendar']['feedback'] = GO::t('iCalendar_update_available', 'email'); break; case 'REQUEST': $response['iCalendar']['feedback'] = GO::t('iCalendar_event_invitation', 'email'); break; } if ($vcalendar->method != 'REQUEST' && $vcalendar->method != 'PUBLISH' && !$event) { $response['iCalendar']['feedback'] = GO::t('iCalendar_event_not_found', 'email'); } $response['iCalendar']['invitation'] = array('uuid' => $uuid, 'email_sender' => $response['sender'], 'email' => $imapMessage->account->getDefaultAlias()->email, 'event_id' => $event ? $event->id : 0, 'is_organizer' => $event && $event->is_organizer, 'is_processed' => $alreadyProcessed, 'is_update' => !$alreadyProcessed && $vcalendar->method == 'REPLY', 'is_invitation' => !$alreadyProcessed && $vcalendar->method == 'REQUEST', 'is_cancellation' => $vcalendar->method == 'CANCEL'); // }elseif($event){ // if($event){ // $response['attendance_event_id']=$event->id; // } // $subject = (string) $vevent->summary; if (empty($uuid) || strpos($response['htmlbody'], $uuid) === false) { //if(!$event){ $event = new \GO\Calendar\Model\Event(); try { $event->importVObject($vevent, array(), true); //} $response['htmlbody'] .= '<div style="border: 1px solid black;margin-top:10px">' . '<div style="font-weight:bold;margin:2px;">' . GO::t('attachedAppointmentInfo', 'email') . '</div>' . $event->toHtml() . '</div>'; } catch (\Exception $e) { //$response['htmlbody'].= '<div style="border: 1px solid black;margin-top:10px">Could not render event</div>'; } } } return $response; }
public function getEventsForPeriod($start, $end) { return \GO\Calendar\Model\Event::model()->findCalculatedForPeriod(\GO\Base\Db\FindParams::newInstance()->criteria(\GO\Base\Db\FindCriteria::newInstance()->addCondition('calendar_id', $this->id))->select(), $start, $end); }
private function _processEventsDisplay($model, $response) { $startOfDay = \GO\Base\Util\Date::clear_time(time()); $findParams = \GO\Base\Db\FindParams::newInstance()->order('start_time', 'DESC'); $findParams->getCriteria()->addCondition('start_time', $startOfDay, '>='); $stmt = \GO\Calendar\Model\Event::model()->findLinks($model, $findParams); $store = \GO\Base\Data\Store::newInstance(\GO\Calendar\Model\Event::model()); $store->setStatement($stmt); $columnModel = $store->getColumnModel(); $columnModel->formatColumn('calendar_name', '$model->calendar->name'); $columnModel->formatColumn('link_count', '$model->countLinks()'); $columnModel->formatColumn('link_description', '$model->link_description'); $data = $store->getData(); $response['data']['events'] = $data['results']; return $response; }
$stmt = \GO\Calendar\Model\Category::model()->find(); while ($category = $stmt->fetch()) { if ($category->calendar_id != 0) { $oldCategories[] = $category->id; echo "Category {$category->name}\n"; $calStmt = \GO\Calendar\Model\Calendar::model()->findByAttribute('user_id', $category->calendar_id); while ($calendar = $calStmt->fetch()) { try { // Create the new categories for each calendar $newCategory = new \GO\Calendar\Model\Category(); $newCategory->name = $category->name; $newCategory->color = $category->color; $newCategory->calendar_id = $calendar->id; $newCategory->save(); // Get all events that have the old category and change the category to the new one. $eventStmt = \GO\Calendar\Model\Event::model()->findByAttributes(array('calendar_id' => $calendar->id, 'category_id' => $category->id)); while ($event = $eventStmt->fetch()) { //echo "Update event $event->name\n"; $event->category_id = $newCategory->id; $event->save(); } } catch (\Exception $e) { echo $e->getMessage() . "\n"; } } } } echo "Done creating new categories\n\n"; echo "Remove old categories\n\n"; foreach ($oldCategories as $oldCat) { // $cat = \GO\Calendar\Model\Category::model()->findByPk($oldCat);
/** * Initialize the listeners for the ActiveRecords */ public static function initListeners() { \GO\Calendar\Model\Event::model()->addListener('load', 'GO\\Freebusypermissions\\FreebusypermissionsModule', 'has_freebusy_access'); }
public function resourceGetEventCalendarName() { if ($this->isResource()) { $resourcedEventModel = Event::model()->findByPk($this->resource_event_id, false, true); $calendarModel = $resourcedEventModel ? $resourcedEventModel->calendar : false; return !empty($calendarModel) ? $calendarModel->name : ''; } else { return ''; } }
protected function actionExportEventAsIcs($event_id) { $eventModel = \GO\Calendar\Model\Event::model()->findByPk($event_id); if (!$eventModel) { throw new Exception('Could not find event with ID #' . $event_id . '.'); } if ($eventModel->exception_for_event_id > 0) { $eventModel = \GO\Calendar\Model\Event::model()->findByPk($eventModel->exception_for_event_id); } if (!$eventModel) { throw new Exception('Could not find main recurring event of event #' . $event_id . '.'); } \GO\Base\Util\Http::outputDownloadHeaders(new \GO\Base\FS\File($eventModel->calendar->name . ' - ' . \GO\Base\Util\Date::get_timestamp($eventModel->start_time) . ' ' . $eventModel->name . '.ics')); echo "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//Intermesh//NONSGML " . \GO::config()->product_name . " " . \GO::config()->version . "//EN\r\n"; $t = new \GO\Base\VObject\VTimezone(); echo $t->serialize(); $v = $eventModel->toVObject(); echo $v->serialize(); $exceptionsStmt = \GO\Calendar\Model\Event::model()->findByAttributes(array('calendar_id' => $eventModel->calendar_id, 'exception_for_event_id' => $eventModel->id)); foreach ($exceptionsStmt as $exceptionEventModel) { $vexc = $exceptionEventModel->toVObject(); echo $vexc->serialize(); } echo "END:VCALENDAR\r\n"; }
/** * Get all today's events from the database. * * @param \GO\base\Model\User $user * @return \GO\Calendar\Model\Event[] */ private function _getEvents($user) { $defaultCalendar = \GO\Calendar\Model\Calendar::model()->getDefault($user); $todayStart = strtotime('today') + 1; $todayEnd = strtotime('tomorrow'); if ($defaultCalendar) { $findParams = \GO\Base\Db\FindParams::newInstance()->select()->criteria(\GO\Base\Db\FindCriteria::newInstance()->addCondition('calendar_id', $defaultCalendar->id)); $events = \GO\Calendar\Model\Event::model()->findCalculatedForPeriod($findParams, $todayStart, $todayEnd); return $events; //->fetchAll(); } else { return array(); } }
public function actionExportIcs($params) { $calendar = \GO\Calendar\Model\Calendar::model()->findByPk($params["calendar_id"], false, true); if (!$calendar->public && !$calendar->checkPermissionLevel(\GO\Base\Model\Acl::READ_PERMISSION)) { throw new \GO\Base\Exception\AccessDenied(); } // $c = new \GO\Base\VObject\VCalendar(); // $c->add(new \GO\Base\VObject\VTimezone()); $months_in_past = isset($params['months_in_past']) ? intval($params['months_in_past']) : 0; $findParams = \GO\Base\Db\FindParams::newInstance()->select("t.*")->order('start_time', 'ASC'); $findParams->getCriteria()->addCondition("calendar_id", $params["calendar_id"]); if (!empty($params['months_in_past'])) { $stmt = Event::model()->findForPeriod($findParams, \GO\Base\Util\Date::date_add(time(), 0, -$months_in_past)); } else { $stmt = Event::model()->find($findParams); } \GO\Base\Util\Http::outputDownloadHeaders(new \GO\Base\FS\File($calendar->name . '.ics')); echo "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//Intermesh//NONSGML " . \GO::config()->product_name . " " . \GO::config()->version . "//EN\r\n"; $t = new \GO\Base\VObject\VTimezone(); echo $t->serialize(); while ($event = $stmt->fetch()) { $v = $event->toVObject(); echo $v->serialize(); } echo "END:VCALENDAR\r\n"; }