Ejemplo n.º 1
0
 public function Events($filter = null, $start_date = null, $end_date = null, $default_view = false, $limit = null, $announcement_filter = null)
 {
     $this->start_date = $start_date instanceof sfDate ? $start_date : ($start_date !== null ? new sfDate($start_date) : new sfDate());
     $this->end_date = $end_date instanceof sfDate ? $end_date : ($end_date !== null ? new sfDate($end_date) : new sfDate());
     if ($end_date instanceof sfDate) {
         $this->end_date = $end_date;
     } elseif ($end_date !== null) {
         $this->end_date = new sfDate($end_date);
     } else {
         $this->end_date = new sfDate($this->start_date->addMonth(Calendar::$defaultFutureMonths)->date());
         $default_view = true;
         $this->start_date->reset();
     }
     if ($events = $this->getStandardEvents($filter)) {
         $event_list = $events;
     } else {
         $event_list = new DataObjectSet();
     }
     $where = $announcement_filter !== null ? " AND {$announcement_filter}" : "";
     $start = $this->start_date->date();
     $end = $this->end_date->date();
     if ($announcements = DataObject::get($this->getEventDateTimeClass(), "CalendarDateTime.CalendarID={$this->ID}\n\t\t\t      AND (\n\t\t\t         (StartDate <= '{$start}' AND EndDate >= '{$end}') OR\n\t\t\t         (StartDate BETWEEN '{$start}' AND '{$end}') OR\n\t\t\t         (EndDate BETWEEN '{$start}' AND '{$end}')\n\t\t\t      ) AND\n\t\t\t      CalendarDateTime.is_announcement=1\n\t\t\t      {$where}", "StartDate ASC")) {
         foreach ($announcements as $announcement) {
             $event_list->push($announcement);
         }
     }
     if ($recurring = $this->getRecurringEvents($filter)) {
         $event_list = $this->addRecurringEvents($recurring, $event_list);
     }
     if ($this->Feeds()) {
         $event_list = $this->importFromFeeds($event_list);
     }
     $e = $event_list->toArray();
     CalendarUtil::date_sort($e);
     $max = $limit === null ? $this->DefaultEventDisplay : $limit;
     if ($default_view && $event_list->Count() > $max) {
         $e = array_slice($e, 0, $max);
     }
     $event_list = new DataObjectSet($e);
     return $event_list;
 }