コード例 #1
0
ファイル: event.php プロジェクト: mined-gatech/hubzero-cms
 /**
  * Returns calendar for event
  *
  * @return object
  */
 public function calendar()
 {
     return Calendar::getInstance($this->get('calendar_id'));
 }
コード例 #2
0
ファイル: calendar.php プロジェクト: mined-gatech/hubzero-cms
 /**
  * Method to refresh Group Calendar
  */
 private function refreshCalendar()
 {
     //get the passed in event id
     $calendarId = Request::getVar('calendar_id', '');
     // get the calendar
     $calendar = \Components\Events\Models\Calendar::getInstance($calendarId);
     // refresh Calendar (force refresh even if we dont need to yet)
     if (!$calendar->refresh(true)) {
         $this->setError(Lang::txt('Unable to sync the group calendar "%s". Please verify the calendar subscription URL is valid.', $calendar->getError()));
         return $this->calendars();
     }
     //inform and redirect
     App::redirect(Route::url('index.php?option=' . $this->option . '&cn=' . $this->group->get('cn') . '&active=calendar&action=calendars'), Lang::txt('You have successfully refreshed the calendar.'), 'passed');
 }
コード例 #3
0
ファイル: archive.php プロジェクト: mined-gatech/hubzero-cms
 /**
  * Subscribe to group calendars
  *
  * @return void
  */
 public function subscribe($name = 'Calendar Subscription', $scope = 'event', $scope_id = null)
 {
     // get request varse
     $calendarIds = Request::getVar('calendar_id', '', 'get');
     $calendarIds = array_map("intval", explode(',', $calendarIds));
     // array to hold events
     $events = new ItemList();
     // loop through and get each calendar
     foreach ($calendarIds as $k => $calendarId) {
         // load calendar model
         $eventsCalendar = new Calendar($calendarId);
         // make sure calendar is published
         if (!$eventsCalendar->get('published') && $calendarId != 0) {
             continue;
         }
         // get calendar events
         $rawEvents = $eventsCalendar->events('list', array('scope' => $scope, 'scope_id' => $scope_id, 'calendar_id' => $calendarId, 'state' => array(1)));
         // merge with full events list
         $events = $events->merge($rawEvents);
     }
     //create output
     $output = "BEGIN:VCALENDAR\r\n";
     $output .= "VERSION:2.0\r\n";
     $output .= "PRODID:PHP\r\n";
     $output .= "METHOD:PUBLISH\r\n";
     $output .= "X-WR-CALNAME;VALUE=TEXT:" . $name . "\r\n";
     $output .= "X-PUBLISHED-TTL:PT15M\r\n";
     $output .= "X-ORIGINAL-URL:https://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . "\r\n";
     $output .= "CALSCALE:GREGORIAN\r\n";
     // get daylight start and end
     $ttz = new DateTimezone(timezone_name_from_abbr('EST'));
     $first = Date::of(date('Y') . '-01-02 00:00:00')->toUnix();
     $last = Date::of(date('Y') . '-12-30 00:00:00')->toUnix();
     $transitions = $ttz->getTransitions($first, $last);
     $daylightStart = Date::of($transitions[1]['ts']);
     $daylightEnd = Date::of($transitions[2]['ts']);
     // output timezone block
     $output .= "BEGIN:VTIMEZONE\r\n";
     $output .= "TZID:America/New_York\r\n";
     $output .= "X-LIC-LOCATION:America/New_York\r\n";
     $output .= "BEGIN:DAYLIGHT\r\n";
     $output .= "TZNAME:Daylight\r\n";
     $output .= "RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=2SU;BYMONTH=3\r\n";
     $output .= "TZOFFSETFROM:-0500\r\n";
     $output .= "TZOFFSETTO:-0400\r\n";
     $output .= "DTSTART:" . $daylightStart->format('Ymd\\THis') . "\r\n";
     $output .= "END:DAYLIGHT\r\n";
     $output .= "BEGIN:STANDARD\r\n";
     $output .= "TZNAME:Standard\r\n";
     $output .= "RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=1SU;BYMONTH=11\r\n";
     $output .= "TZOFFSETFROM:-0400\r\n";
     $output .= "TZOFFSETTO:-0500\r\n";
     $output .= "DTSTART:" . $daylightEnd->format('Ymd\\THis') . "\r\n";
     $output .= "END:STANDARD\r\n";
     $output .= "END:VTIMEZONE\r\n";
     // loop through events
     foreach ($events as $event) {
         $sequence = 0;
         $uid = $event->get('id') . '@' . $_SERVER['HTTP_HOST'];
         $title = $event->get('title');
         $content = str_replace("\r\n", '\\n', $event->get('content'));
         $location = $event->get('adresse_info');
         $url = $event->get('extra_info');
         // get event timezone setting
         // use this in "DTSTART;TZID="
         $tzInfo = \plgGroupsCalendarHelper::getTimezoneNameAndAbbreviation($event->get('time_zone'));
         $tzName = timezone_name_from_abbr($tzInfo['abbreviation']);
         // get publish up/down dates in UTC
         $publishUp = new DateTime($event->get('publish_up'), new DateTimezone('UTC'));
         $publishDown = new DateTime($event->get('publish_down'), new DateTimezone('UTC'));
         // Set eastern timezone as publish up/down date timezones
         // since all event date/times are stores relative to eastern
         // ----------------------------------------------------------------------------------
         // The timezone param "DTSTART;TZID=" defined above will allow a users calendar app to
         // adjust date/time display according to that timezone and their systems timezone setting
         $publishUp->setTimezone(new DateTimezone(timezone_name_from_abbr('EST')));
         $publishDown->setTimezone(new DateTimezone(timezone_name_from_abbr('EST')));
         // create now, created, and modified vars
         $now = gmdate('Ymd') . 'T' . gmdate('His') . 'Z';
         $created = gmdate('Ymd', strtotime($event->get('created'))) . 'T' . gmdate('His', strtotime($event->get('created'))) . 'Z';
         $modified = gmdate('Ymd', strtotime($event->get('modified'))) . 'T' . gmdate('His', strtotime($event->get('modified'))) . 'Z';
         // start output
         $output .= "BEGIN:VEVENT\r\n";
         $output .= "UID:{$uid}\r\n";
         $output .= "SEQUENCE:{$sequence}\r\n";
         $output .= "DTSTAMP:{$now}\r\n";
         $output .= "DTSTART;TZID={$tzName}:" . $publishUp->format('Ymd\\THis') . "\r\n";
         if ($event->get('publish_down') != '' && $event->get('publish_down') != '0000-00-00 00:00:00') {
             $output .= "DTEND;TZID={$tzName}:" . $publishDown->format('Ymd\\THis') . "\r\n";
         } else {
             $output .= "DTEND;TZID={$tzName}:" . $publishUp->format('Ymd\\THis') . "\r\n";
         }
         // repeating rule
         if ($event->get('repeating_rule') != '') {
             $output .= "RRULE:" . $event->get('repeating_rule') . "\r\n";
         }
         $output .= "CREATED:{$created}\r\n";
         $output .= "LAST-MODIFIED:{$modified}\r\n";
         $output .= "SUMMARY:{$title}\r\n";
         $output .= "DESCRIPTION:{$content}\r\n";
         // do we have extra info
         if ($url != '' && filter_var($url, FILTER_VALIDATE_URL)) {
             $output .= "URL;VALUE=URI:{$url}\r\n";
         }
         // do we have a location
         if ($location != '') {
             $output .= "LOCATION:{$location}\r\n";
         }
         $output .= "END:VEVENT\r\n";
     }
     // close calendar
     $output .= "END:VCALENDAR";
     // set headers and output
     header('Content-type: text/calendar; charset=utf-8');
     header('Content-Disposition: attachment; filename="' . $name . '.ics"');
     header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
     echo $output;
     exit;
 }