public function initCal($fromDateYmd = NULL, $toDateYmd = NULL, $atts = array()) { // Creates a new Calendar37_CalendarModel object, populating all the event occurrences // Parameters come from either the calling function (TWIG) or from GET/POST. GET/POST always override. $plugin = craft()->plugins->getPlugin('Calendar37'); $this->settings = $plugin->getSettings(); $this->twigAtts = $atts; $cal = new Calendar37_CalendarModel(); $cal->calupdate = array_key_exists('calupdate', $atts) ? $atts['calupdate'] : false; $cal->showTails = $this->getParam('showTails'); $cal->status = $this->getParam('status'); $cal->rowOfDaysFormat = $this->getParam('rowOfDaysFormat'); $cal->dateformat = $this->getParam('dateformat'); $cal->dateformat1st = $this->getParam('dateformat1st'); $cal->occurrenceFormat = $this->getParam('occurrenceFormat'); $cal->title = $this->getParam('title'); $cal->filler1 = $this->getParam('filler1'); $cal->filler2 = $this->getParam('filler2'); $cal->nodate = $this->getParam('nodate'); $catsToInclude = $this->getParam('categoriesToInclude'); $catsToExclude = $this->getParam('categoriesToExclude'); $cal->categoriesToInclude = $catsToInclude ? explode(',', $catsToInclude) : null; $cal->categoriesToExclude = $catsToExclude ? explode(',', $catsToExclude) : null; $cal->desiredStartYmd(craft()->request->getParam('calstart') ?: $fromDateYmd ?: date("Y-m-01", time())); $cal->desiredEndYmd(craft()->request->getParam('calend') ?: $toDateYmd ?: date("Y-m-t", $cal->desiredStartNum)); $view = new Calendar37_ViewsRecord(); $view = $view->findByAttributes(array('startDateYmd' => $cal->desiredStartYmd(), 'endDateYmd' => $cal->desiredEndYmd())); if ($view) { $cal->filler1 = $view->htmlBefore; $cal->filler2 = $view->htmlAfter; } // OK, pull all occurrences from the db $query = craft()->db->createCommand(); $cal->occurrence = $query->select('*')->from('calendar37_occurrences c37')->where("c37.dateYmd >= '{$cal->actualStartYmd()}'")->andWhere("c37.dateYmd <= '{$cal->actualEndYmd()}'")->order('dateYmd ASC, timestr ASC')->queryAll(); // Filter based on category, // and catalog event and category info for valid events (to save re-querying for repeated events) foreach ($cal->occurrence as $key => $occurrence) { $eventID = $occurrence['event_id']; if (!isset($eventIsValid[$eventID])) { // Collect info about this event. Especially, determine whether or not to display it. $entry = craft()->entries->getEntryById($eventID); $category = $entry->mainCategory->last(); $eventIsValid[$eventID] = 'no'; //We'll change it to yes if it turns out to be good. if (empty($cal->categoriesToInclude) || in_array($category->id, $cal->categoriesToInclude)) { if (empty($cal->categoriesToExclude) || !in_array($category->id, $cal->categoriesToExclude)) { $eventIsValid[$eventID] = 'yes'; $event = new Calendar37_EventModel(); $event->url = $entry->getUrl(); $event->css = isset($category) ? $category->cal37Css : ''; $event->eventHandle = isset($category) ? $category->slug : ''; $event->title = $entry->{$this->settings->entryCalendarTextFieldHandle} ?: $entry->title; $image = $entry->calendarImage->first(); if ($image) { $event->title = "<img src='{$image->url}' title='{$event->title}'>"; $event->imageAsTitle = true; } $cal->event[$eventID] = $event; } } } if ($eventIsValid[$eventID] == 'no') { unset($cal->occurrence[$key]); } } $cal->occurrence = array_values($cal->occurrence); // How will we create URLs? $cal->urlFieldHandle = $this->settings->categoryFieldHandle; return $cal; }
public function desiredStartYmd(Calendar37_CalendarModel $cal) { return $cal->desiredStartYmd(); }