Пример #1
0
function calendar_to_ical($calendar)
{
    $vCalendar = new \Eluceo\iCal\Component\Calendar('Calendar API V1');
    $vCalendar->setName($calendar->summary);
    $vCalendar->setDescription($calendar->description);
    $vCalendar->setTimezone($calendar->timezone);
    return $vCalendar;
}
Пример #2
0
 /**
  * Renders an ical file for a specific group
  */
 public function group(Group $group)
 {
     // 1. Create new calendar
     $vCalendar = new \Eluceo\iCal\Component\Calendar(config('app.url'));
     $vCalendar->setName(config('mobilizator.name') . ' : ' . $group->name);
     $vCalendar->setDescription(summary($group->body, 500));
     // returns actions started the last 60 days
     $actions = $group->actions()->where('start', '>=', Carbon::now()->subDays(60))->get();
     foreach ($actions as $action) {
         // 2. Create an event
         $vEvent = new \Eluceo\iCal\Component\Event();
         $vEvent->setDtStart($action->start);
         $vEvent->setDtEnd($action->stop);
         $vEvent->setSummary($action->name);
         $vEvent->setDescription(summary($action->body), 1000);
         $vEvent->setLocation($action->location);
         $vEvent->setUrl(action('ActionController@show', [$action->group->id, $action->id]));
         $vEvent->setUseUtc(false);
         //TODO fixme
         $vCalendar->addComponent($vEvent);
     }
     return response($vCalendar->render())->header('Content-Type', 'text/calendar; charset=utf-8')->header('Content-Disposition', 'attachment; filename="cal.ics"');
 }
Пример #3
0
 public function ical($key)
 {
     switch ($key) {
         case 'public':
             $items = BookingItem::where('start_at', '>=', date('Y-m-d'))->where('booking.is_private', '=', false)->with('booking', 'ressource')->get();
             $description = '';
             break;
         default:
             $filter = true;
             if (preg_match('/^(.+)_(.+)$/', $key, $tokens)) {
                 $key = $tokens[1];
                 if ($tokens[2] != 'all') {
                     App::abort(404);
                     return false;
                 }
                 $filter = false;
             }
             $owner = User::where('booking_key', '=', $key)->first();
             if (!$owner) {
                 App::abort(404);
                 return false;
             }
             $description = $owner->fullname;
             $items = BookingItem::where('start_at', '>=', date('Y-m-d'))->join('booking', 'booking_item.booking_id', '=', 'booking.id')->join('users', 'booking.user_id', '=', 'users.id');
             if ($filter) {
                 $items = $items->where('users.booking_key', '=', $key);
             }
             $items = $items->with('booking', 'ressource')->get();
             break;
     }
     $vCalendar = new \Eluceo\iCal\Component\Calendar(Request::server('SERVER_NAME'));
     $vCalendar->setDescription($description);
     $tz = new DateTimeZone(date_default_timezone_get());
     foreach ($items as $booking_item) {
         $start = new \DateTime($booking_item->start_at);
         $start->setTimezone($tz);
         $end = new \DateTime($booking_item->start_at);
         $start->setTimezone($tz);
         $end->modify(sprintf('+%d minutes', $booking_item->duration));
         $vEvent = new \Eluceo\iCal\Component\Event();
         $vEvent->setDtStart($start)->setDtEnd($end)->setUseTimezone(true)->setSummary(sprintf('%s (%s)', $booking_item->booking->title, $booking_item->ressource->name));
         $vCalendar->addComponent($vEvent);
     }
     $response = Response::make($vCalendar->render());
     $response->header('Content-Type', 'text/calendar; charset=utf-8');
     $response->header('Content-Disposition', 'attachment; filename="cal.ics"');
     return $response;
 }
Пример #4
0
//obtain the course record
$course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
//require that a user is logged in an has access to this course
require_login($course);
//determine access levels
$isteacher = has_capability('block/snap:viewstudentprogress', context_course::instance($COURSE->id));
//------------------------------------------------------------
// ICAL DOWNLOAD OPTION
//------------------------------------------------------------
if ($download == 'ical' && $course->startdate && $course->enablecompletion) {
    //load the iCalendar class
    require_once __DIR__ . '/classes/iCal/autoload.php';
    //create new calendar
    $ical = new \Eluceo\iCal\Component\Calendar('Moodle Snap - Course Schedule (' . $_SERVER['HTTP_HOST'] . ')');
    $ical->setName($course->shortname);
    $ical->setDescription($course->fullname);
    //pull the information for all the modules
    $modinfo = get_fast_modinfo($course);
    foreach ($modinfo->cms as $mod) {
        //if completion is not enabled, then skip it
        if (!$mod->completion || !$mod->completionexpected) {
            continue;
        }
        //if hidden then skip it
        if (!$mod->visible) {
            continue;
        }
        $dt = new DateTime();
        $dt->setTimestamp($mod->completionexpected);
        //create an event
        $ievent = new \Eluceo\iCal\Component\Event();
Пример #5
0
 public function generateIcal()
 {
     // set default timezone (PHP 5.4)
     date_default_timezone_set('Europe/Berlin');
     $ical_name = 'HSG Wesel - Gesamtspielplan';
     $ical_calid = 'hsg_wesel_1516_total';
     $ics_file_name = 'hsg_wesel_1516_total.ics';
     $team_info = $this->getTeamInfo();
     if (is_array($team_info)) {
         $ical_name = 'HSG Wesel - Saison 2015/16 - ' . $team_info['team'];
         $ical_calid = 'hsg_wesel_1516_' . $team_info['liga_id'];
         $ics_file_name = 'hsg_wesel_1516_' . $this->getTeam() . '.ics';
     } else {
         switch ($this->art) {
             case '188':
                 $ical_name = 'HSG Wesel - Saison 2015/16 - Spielplan Heim';
                 $ical_calid = 'hsg_wesel_1516_1330105011_heim';
                 $ics_file_name = 'hsg_wesel_1516_spielplan_heim' . '.ics';
                 break;
             case '199':
                 $ical_name = 'HSG Wesel - Saison 2015/16 - Spielplan Auswärts';
                 $ical_calid = 'hsg_wesel_1516_1330105011_auswaerts';
                 $ics_file_name = 'hsg_wesel_1516_auswaerts' . '.ics';
                 break;
         }
     }
     // 1. Create new calendar
     $vCalendar = new \Eluceo\iCal\Component\Calendar('HSG Wesel SIS-Handball ICS-Generator');
     $vCalendar->setName($ical_name);
     $vCalendar->setDescription('HSG Wesel / photominister.de');
     $vCalendar->setCalId($ical_calid);
     $vCalendar->setMethod('PUBLISH');
     // 2. Create an event
     // $this->framework->dump($this->art);
     if (count($this->xml->Spiel) > 0) {
         foreach ($this->xml->Spiel as $spiel) {
             $element = $this->getHash($spiel);
             $show_heim = substr($spiel->Heim, 0, 9) == 'HSG Wesel';
             $show_gast = substr($spiel->Gast, 0, 9) == 'HSG Wesel';
             switch ($this->art) {
                 case '188':
                     $cond = $show_heim;
                     break;
                 case '199':
                     $cond = $show_gast;
                     break;
                 default:
                     $cond = $show_heim || $show_gast;
                     break;
             }
             if ($cond) {
                 $description = $spiel->LigaName . '..... www.hsg-wesel.de ..... www.handballinwesel.de ..... www.facebook.com/hsgwesel';
                 $description = str_replace("\r\n", "\\n", $description);
                 $vEvent = new \Eluceo\iCal\Component\Event();
                 $vEvent->setDtStart(new \DateTime($spiel->SpielVon));
                 $vEvent->setDtEnd(new \DateTime($spiel->SpielBis));
                 $vEvent->setSummary($spiel->Heim . ' - ' . $spiel->Gast);
                 $vEvent->setDescription($description);
                 $vEvent->setLocation($spiel->HallenName . ', ' . $spiel->HallenStrasse . ', ' . $spiel->HallenOrt);
                 $vEvent->setUseTimezone(TRUE);
                 // 3. Add event to calendar
                 $vCalendar->addComponent($vEvent);
                 unset($vEvent);
             }
         }
     }
     // 4. Set headers
     header('Content-Type: text/calendar; charset=utf-8');
     header('Content-Disposition: attachment; filename="' . $ics_file_name . '"');
     // 5. Output
     echo $vCalendar->render();
     exit;
 }