public function getDashletFields()
 {
     $fields = parent::getDashletFields();
     $fields->push(MultiSelect2Field::create('Calendars', 'Calendars')->setSource(Calendar::get()->map()->toArray())->setMultiple(true));
     $fields->push(CheckboxField::create('OnlyUpcoming'));
     return $fields;
 }
Beispiel #2
0
 function events($group_id = FALSE)
 {
     $calendar = new Calendar();
     if ($group_id) {
         $calendar->where('group_id', $group_id);
     }
     $events = $calendar->get()->all_to_array();
     echo json_encode($events);
 }
Beispiel #3
0
 public function process()
 {
     increase_time_limit_to(300);
     DB::query("DELETE FROM CachedCalendarEntry");
     $future_years = $this->config()->cache_future_years;
     foreach (Calendar::get() as $calendar) {
         echo "<h2>Caching calendar '{$calendar->Title}'</h2>\n";
         foreach ($calendar->getAllCalendars() as $c) {
             foreach ($c->AllChildren() as $event) {
                 // All the dates of regular events
                 if ($event->Recursion) {
                     echo "<h3>Creating recurring events for '{$event->Title}'</h3>\n";
                     $i = 0;
                     $dt = $event->DateTimes()->first();
                     if (!$dt) {
                         continue;
                     }
                     if ($dt->EndDate) {
                         $end_date = sfDate::getInstance($dt->EndDate);
                     } else {
                         $end_date = sfDate::getInstance()->addYear($future_years);
                     }
                     $start_date = sfDate::getInstance($dt->StartDate);
                     $recursion = $event->getRecursionReader();
                     while ($start_date->get() <= $end_date->get()) {
                         if ($recursion->recursionHappensOn($start_date->get())) {
                             $dt->StartDate = $start_date->format('Y-m-d');
                             $cached = CachedCalendarEntry::create_from_datetime($dt, $calendar);
                             $cached->EndDate = $cached->StartDate;
                             $cached->write();
                         }
                         $start_date->addDay();
                         $i++;
                     }
                     echo "<p>{$i} events created.</p>\n";
                 } else {
                     foreach ($event->DateTimes() as $dt) {
                         echo "<p>Adding dates for event '{$event->Title}'</p>\n";
                         $cached = CachedCalendarEntry::create_from_datetime($dt, $calendar);
                         $cached->write();
                     }
                 }
                 // Announcements
             }
             foreach ($c->Announcements() as $a) {
                 echo "<p>Adding announcement {$a->Title}</p>\n";
                 $cached = CachedCalendarEntry::create_from_announcement($a, $calendar);
                 $cached->write();
             }
         }
     }
     echo "Done!";
 }
 public function getCMSFields()
 {
     Requirements::javascript('event_calendar/javascript/calendar_cms.js');
     $f = parent::getCMSFields();
     $configuration = _t('Calendar.CONFIGURATION', 'Configuration');
     $f->addFieldsToTab("Root.{$configuration}", array(new DropdownField('DefaultView', _t('Calendar.DEFAULTVIEW', 'Default view'), array('upcoming' => _t('Calendar.UPCOMINGVIEW', "Show a list of upcoming events."), 'month' => _t('Calendar.MONTHVIEW', "Show this month's events."), 'week' => _t('Calendar.WEEKVIEW', "Show this week's events. If none, fall back on this month's"), 'today' => _t('Calendar.TODAYVIEW', "Show today's events. If none, fall back on this week's events"), 'weekend' => _t('Calendar.WEEKENDVIEW', "Show this weekend's events."))), new NumericField('DefaultFutureMonths', _t('Calendar.DEFAULTFUTUREMONTHS', 'Number maximum number of future months to show in default view')), new NumericField('EventsPerPage', _t('Calendar.EVENTSPERPAGE', 'Events per page')), new TextField('DefaultDateHeader', _t('Calendar.DEFAULTDATEHEADER', 'Default date header (displays when no date range has been selected)')), new NumericField('OtherDatesCount', _t('Calendar.NUMBERFUTUREDATES', 'Number of future dates to show for repeating events'))));
     // Announcements
     $announcements = _t('Calendar.Announcements', 'Announcements');
     $f->addFieldToTab("Root.{$announcements}", $announcementsField = GridField::create("Announcements", $announcements, $this->Announcements(), GridFieldConfig_RecordEditor::create()));
     $announcementsField->setDescription(_t('Calendar.ANNOUNCEMENTDESCRIPTION', 'Announcements are simple entries you can add to your calendar that do not have detail pages, e.g. "Office closed"'));
     // Feeds
     $feeds = _t('Calendar.FEEDS', 'Feeds');
     $f->addFieldToTab("Root.{$feeds}", $feedsField = GridField::create("Feeds", $feeds, $this->Feeds(), GridFieldConfig_RecordEditor::create()));
     $feedsField->setDescription(_t('Calendar.ICSFEEDDESCRIPTION', 'Add ICS feeds to your calendar to include events from external sources, e.g. a Google Calendar'));
     $otherCals = Calendar::get()->exclude(array("ID" => $this->ID));
     if ($otherCals->exists()) {
         $f->addFieldToTab("Root.{$feeds}", new CheckboxSetField('NestedCalendars', _t('Calendar.NESTEDCALENDARS', 'Include events from these calendars'), $otherCals->map('ID', 'Link')));
     }
     $f->addFieldToTab("Root.Main", new TextField('RSSTitle', _t('Calendar.RSSTITLE', 'Title of RSS Feed')), 'Content');
     $this->extend('updateCMSFields', $f);
     return $f;
 }
Beispiel #5
0
            } else {
                if ($days === 42) {
                    break;
                }
            }
            $res[] = $calendar;
            $days++;
        }
        return $res;
    }
    public function set($arr = [])
    {
        foreach ($arr as $key => $val) {
            if ($key === 'year') {
                $this->year = $val;
            } else {
                if ($key === 'month') {
                    $this->month = $val;
                }
            }
        }
    }
    private function build($unixtime)
    {
        $date = getdate($unixtime);
        return ['unixtime' => $unixtime, 'wday' => $date['wday'], 'year' => $date['year'], 'month' => $date['mon'], 'day' => $date['mday'], 'isToday' => $this->today === $unixtime ? true : false];
    }
}
$calendar = new Calendar();
var_dump($calendar->get());
 /**
  * Single calendar
  * Can be public or private
  * For public calendars either the calendar id or the calendar url can be supplied
  * For private calendars user email and hash need to be supplied - like this.
  * The private calendar hash is created in {@see PrivateCalendarMemberExtension}
  */
 function cal()
 {
     //echo 'test';
     $call = null;
     $request = $this->getRequest();
     $ics = null;
     $idOrURL = $request->param('ID');
     //echo $idOrURL;
     //Public calendar via id
     if (is_numeric($idOrURL)) {
         //calendar id is requested
         //echo 'request is numeric';
         $cal = Calendar::get()->ByID((int) $request->param('ID'));
         //echo $cal->getLink();
         //Public calendar via url
     } else {
         //calendar url is requested
         //echo 'request is a string';
         $url = Convert::raw2url($idOrURL);
         $cal = Calendar::get()->filter('URLSegment', $url)->First();
     }
     //If not public calendar is found we check for a private calendar
     if (!$cal) {
         echo $idOrURL;
         $member = Member::get()->filter('Email', $idOrURL)->filter('PrivateCalendarKey', $request->param('OtherID'))->First();
         if ($member && $member->exists()) {
             return $this->memberCalendar($member);
         }
     }
     if ($cal && $cal->exists()) {
         //everybody can access public calendars
         if ($cal->ClassName == 'PublicCalendar') {
             $ics = ICSExport::ics_from_sscal($cal);
             $calName = $cal->Title;
         }
         return $this->output($ics, $calName);
     } else {
         echo "calendar can't be found";
     }
 }
 /**
  * Import events created with: http://www.myeventon.com/
  * into a 'CalendarEvent' Page type from Unclecheese's "Event Calendar" module
  *
  * Step 2) Update the page to 'CalendarEvent' page type and add event data appropriately
  */
 public function importEvents_MyEventOn_Step2($calendarHolder = null)
 {
     $this->logFunctionStart(__FUNCTION__);
     if (!class_exists('CalendarDateTime')) {
         throw new WordpressImportException(__FUNCTION__ . ' requires Unclecheese\'s "Event Calendar" module');
     }
     if (!CalendarDateTime::has_extension('WordpressImportDataExtension')) {
         throw new WordpressImportException('CalendarDateTime requires WordpressImportDataExtension.');
     }
     // Debug
     //Debug::dump($this->_db->getPosts('ajde_events', true)); exit;
     // Get the calendar holder the events should belong to.
     if ($calendarHolder === null) {
         $calendarHolder = Calendar::get()->filter(array('WordpressData' => '1'))->first();
         if (!$calendarHolder) {
             $calendarHolder = Calendar::create();
             $calendarHolder->Title = 'Wordpress Imported Events';
             $calendarHolder->URLSegment = 'events';
             $calendarHolder->WordpressData = 1;
             try {
                 $this->writeAndPublishRecord($calendarHolder);
             } catch (Exception $e) {
                 $this->log($calendarHolder, 'error', $e);
             }
         }
     }
     // Convert to CalendarEvent and attach relevant event data
     $existingWpRecords = singleton('Page')->WordpressRecordsByWordpressID();
     foreach ($this->_db->getPosts('ajde_events') as $wpData) {
         $wpID = $wpData['ID'];
         if (!isset($existingWpRecords[$wpID])) {
             $this->log('Unable to find Wordpress ID #' . $wpID, 'error');
             continue;
         }
         $record = $existingWpRecords[$wpID];
         $wpMeta = $this->_db->attachAndGetPostMeta($wpData);
         if ($record->ClassName !== 'CalendarEvent') {
             $record = $record->newClassInstance('CalendarEvent');
         }
         $record->ParentID = $calendarHolder->ID;
         $startDate = isset($wpMeta['evcal_srow']) && $wpMeta['evcal_srow'] ? (int) $wpMeta['evcal_srow'] : null;
         $endDate = isset($wpMeta['evcal_erow']) && $wpMeta['evcal_erow'] ? (int) $wpMeta['evcal_erow'] : null;
         if ($startDate && $endDate) {
             $subRecord = null;
             if ($record->exists()) {
                 $subRecord = $record->DateTimes()->find('WordpressID', $wpID);
             }
             if (!$subRecord) {
                 $subRecord = CalendarDateTime::create();
             }
             $subRecord->AllDay = isset($wpMeta['evcal_allday']) && $wpMeta['evcal_allday'] === 'yes';
             $subRecord->StartDate = date('Y-m-d', $startDate);
             $subRecord->StartTime = date('H:i:s', $startDate);
             $subRecord->EndDate = date('Y-m-d', $endDate);
             $subRecord->EndTime = date('H:i:s', $endDate);
             $subRecord->WordpressData = $record->WordpressData;
             if (!$subRecord->exists()) {
                 // NOTE(Jake): Will write $subRecord when $record is written if not exists, otherwise
                 //			   it will write it when it's ->add()'d
                 $record->DateTimes()->add($subRecord);
             } else {
                 try {
                     $record->write();
                     $this->log($record, 'changed');
                 } catch (Exception $e) {
                     $this->log($record, 'error', $e);
                 }
             }
         }
         // Support Addressable extension from Addressable module
         if (isset($wpMeta['evcal_location'])) {
             if ($record->Address !== $wpMeta['evcal_location']) {
                 $record->Address = $wpMeta['evcal_location'];
             }
         }
         // Support Geocodable extension from Addressable module
         if (isset($wpMeta['evcal_lat'])) {
             $record->Lat = $wpMeta['evcal_lat'];
         }
         if (isset($wpMeta['evcal_lng'])) {
             $record->Lng = $wpMeta['evcal_lng'];
         }
         $changedFields = $record->getChangedFields(true, DataObject::CHANGE_VALUE);
         unset($changedFields['Lat']);
         unset($changedFields['Lng']);
         if ($changedFields) {
             try {
                 $isPublished = isset($wpData['post_status']) && $wpData['post_status'] === 'publish' || $record->isPublished();
                 $this->writeAndPublishRecord($record, $isPublished);
             } catch (Exception $e) {
                 $this->log($record, 'error', $e);
             }
         } else {
             $this->log($record, 'nochange');
         }
     }
     $this->logFunctionEnd(__FUNCTION__);
 }
Beispiel #8
0
 function events()
 {
     $calendar = new Calendar();
     $events = $calendar->get()->all_to_array();
     echo json_encode($events);
 }