Create a past event calendar list template
Permalink
I have an event calendar working successfully on a client's website. They have now asked if there is a way to display a list of past events.
Is there a simple code change to create a template that displays past events rather than future?
Basically reversing the way the current calendar list block works.
Similar to the concept of how the page list block can display past posts.
Thanks
Is there a simple code change to create a template that displays past events rather than future?
Basically reversing the way the current calendar list block works.
Similar to the concept of how the page list block can display past posts.
Thanks
Thank you for pointing me in the right direction.
by changing the code to
sorted this out.
I am just trying to figure out how to reorder the list to descend from the most recent past event down to the last.
by changing the code to
$list->filterByStartTimeBefore($time);
sorted this out.
I am just trying to figure out how to reorder the list to descend from the most recent past event down to the last.
Hi Studio108
Did you manage to solve the list of past events showing from most recent back in time?
Also, can you have both lists coexisting on the same page?
I have the same issue.
Thanks
Did you manage to solve the list of past events showing from most recent back in time?
Also, can you have both lists coexisting on the same page?
I have the same issue.
Thanks
Hi Kevin,
I got as far as re-creating another standalone version based on the cores Event Calendar Block (called Past Event Block for example) and adjusted the controller file (using the code above) to list events that occurred before the current day. This worked great, but I never found a pretty way with PHP of getting the events to list in descending order down from the most recent past event to the furthest. So for now I have cheated and used css to flip the list order. I am not happy using that method but it is a temporary fix to produce the result I needed.
To answer your second question they worked as independent blocks on the same page without issue.
I got as far as re-creating another standalone version based on the cores Event Calendar Block (called Past Event Block for example) and adjusted the controller file (using the code above) to list events that occurred before the current day. This worked great, but I never found a pretty way with PHP of getting the events to list in descending order down from the most recent past event to the furthest. So for now I have cheated and used css to flip the list order. I am not happy using that method but it is a temporary fix to produce the result I needed.
To answer your second question they worked as independent blocks on the same page without issue.
Thanks.
I managed to get mine showing all events, past and future, with my rudimentary php, but could not work out how to list them from most recent to furthest in the past.
I think it would be better on our site to have both a past events and upcoming events block, so I may attempt to do the same and create a Past Event block. I tried last night but it wouldn't load so I obviously did something wrong.
Would you be willing to share the CSS code to reverse the order?
I managed to get mine showing all events, past and future, with my rudimentary php, but could not work out how to list them from most recent to furthest in the past.
I think it would be better on our site to have both a past events and upcoming events block, so I may attempt to do the same and create a Past Event block. I tried last night but it wouldn't load so I obviously did something wrong.
Would you be willing to share the CSS code to reverse the order?
I'm not 100% sure if this would work or not, but in your controller right before $this->set('list', $list); you should be able to add this and reverse the order
That's untested, but I think it should work to reverse the order.
$list->orderBy('eo.startTime', 'desc'); $list->addOrderBy('ve.evName');
That's untested, but I think it should work to reverse the order.
Sadly not working for me - assuming I'm putting it in the right controller - I'm putting it in the event_list controller like this:
and I get the attached exception message.
$list->orderBy('eo.startTime', 'desc'); $list->addOrderBy('ve.evName'); $this->set('list', $list); $this->set('calendar', $calendar); if ($this->internalLinkCID) { $calendarPage = \Page::getByID($this->internalLinkCID); if (is_object($calendarPage) && !$calendarPage->isError()) { $this->set('calendarPage', $calendarPage);
and I get the attached exception message.
Ah I see where I went wrong, sorry. Try this instead
If you have two events that are the exact same start time they will show up in a somewhat random order, but this should change the overall order.
$list->executeSortBy('eo.startTime', 'desc');
If you have two events that are the exact same start time they will show up in a somewhat random order, but this should change the overall order.
Still an exception message unfortunately:
I get these errors?
orderBy method does not exist for the Concrete\Core\Calendar\Event\EventOccurrenceList class
and for the other way
executeSortBy method does not exist for the Concrete\Core\Calendar\Event\EventOccurrenceList class
orderBy method does not exist for the Concrete\Core\Calendar\Event\EventOccurrenceList class
and for the other way
executeSortBy method does not exist for the Concrete\Core\Calendar\Event\EventOccurrenceList class
Sorry about that, did not go back far enough in the code. Does this one work?
$list-sortBy('eo.startTime', 'desc');
Hi Hutman,
thank you so much for your input on this query.
Unfortunately, I am still getting the error message "Call to undefined function Application\Block\PastEventsList\sortBy()"
thank you so much for your input on this query.
Unfortunately, I am still getting the error message "Call to undefined function Application\Block\PastEventsList\sortBy()"
Did you do $this->sortBy or $list->sortBy?
Hi, I used...
$list->sortBy
Error message...
Call to undefined method Application\Block\PastEventsList\Controller::sortBy()
$list->sortBy
Error message...
Call to undefined method Application\Block\PastEventsList\Controller::sortBy()
I think it is now solved.
I was still using
rather than only this...
Thank you so much!!!!
I was still using
$list->sortBy('eo.startTime', 'desc'); $list->addOrderBy('ve.evName');
rather than only this...
$list->sortBy('eo.startTime', 'desc');
Thank you so much!!!!
https://github.com/concrete5/concrete5/blob/8.5.4/concrete/blocks/ev...