Open TheBnl opened 7 years ago
I think it's because the list is immutable. Should be $events = $events->sort(...);
isn't the extra sort and limit not redundant as far as I see it getEventList either in it's main Path or in the getCachedEventList already sorts by StartDate and limits by $l/$limit.
Think I found out what's wrong If you set a Limit of 1 it first sorts all Events by StartDate ASC then limits 1 and then the return events get sorted StartDate DESC and then limited by once more i think getEventList needs another Paramter for DESC/ASC direction.
Changed the Functions to this and now works as intended
public function getCachedEventList($start, $end, $filter = null, $limit = null, $sort = "ASC") {
return CachedCalendarEntry::get()
->filter(array(
"CachedCalendarID" => $this->ID
))
->exclude(array(
"StartDate:LessThan" => $end,
"EndDate:GreaterThan" => $start,
))
->sort(array(
"StartDate" => $sort,
"StartTime" => $sort
))
->limit($limit);
}
public function getEventList($start, $end, $filter = null, $limit = null, $announcement_filter = null,$sortorder = "ASC") {
if(Config::inst()->get("Calendar", "caching_enabled")) {
return $this->getCachedEventList($start, $end, $filter, $limit,$sortorder);
}
$eventList = new ArrayList();
foreach($this->getAllCalendars() as $calendar) {
if($events = $calendar->getStandardEvents($start, $end, $filter)) {
$eventList->merge($events);
}
$announcements = DataList::create($this->getAnnouncementClass())
->filter(array(
"CalendarID" => $calendar->ID,
"StartDate:LessThan:Not" => $start,
"EndDate:GreaterThan:Not" => $end,
));
if($announcement_filter) {
$announcements = $announcements->where($announcement_filter);
}
if($announcements) {
foreach($announcements as $announcement) {
$eventList->push($announcement);
}
}
if($recurring = $calendar->getRecurringEvents($filter)) {
$eventList = $calendar->addRecurringEvents($start, $end, $recurring, $eventList);
}
if($feedevents = $calendar->getFeedEvents($start,$end)) {
$eventList->merge($feedevents);
}
}
$eventList = $eventList->sort(array("StartDate" => $sortorder, "StartTime" => $sortorder));
$eventList = $eventList->limit($limit);
return $this->EventList_cache = $eventList;
}
public function RecentEvents($limit = null, $filter = null) {
$start_date = sfDate::getInstance();
$end_date = sfDate::getInstance();
$l = ($limit === null) ? "9999" : $limit;
$events = $this->getEventList(
$start_date->subtractMonth($this->DefaultFutureMonths)->date(),
$end_date->yesterday()->date(),
$filter,
$l,
null,
"DESC"
);
return $events;
}
In the
Calendar
'sRecentEvents
method the sorting is ignored after thegetEventList
method is called.Removing the sort from the
getEventList
method solves the issue, but i'm not sure if that is desired. The$default_sort
of theCalendarDateTime
keeps it in good order though.