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

studio108
 
hutman replied on at Permalink Reply
hutman
In order to do this you would have to override the event_list controller (or copy the whole block and make a new one). On line 96-98 it is hard coded to filter by start time after today at midnight.

https://github.com/concrete5/concrete5/blob/8.5.4/concrete/blocks/ev...
studio108 replied on at Permalink Reply
studio108
Thank you for pointing me in the right direction.
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.
KevinBarton replied on at Permalink Reply
KevinBarton
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
studio108 replied on at Permalink Reply
studio108
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.
KevinBarton replied on at Permalink Reply
KevinBarton
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?
hutman replied on at Permalink Reply
hutman
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

$list->orderBy('eo.startTime', 'desc');
$list->addOrderBy('ve.evName');


That's untested, but I think it should work to reverse the order.
KevinBarton replied on at Permalink Reply 1 Attachment
KevinBarton
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:

$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.
hutman replied on at Permalink Reply
hutman
Ah I see where I went wrong, sorry. Try this instead

$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.
KevinBarton replied on at Permalink Reply 1 Attachment
KevinBarton
Still an exception message unfortunately:
studio108 replied on at Permalink Reply
studio108
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
hutman replied on at Permalink Reply
hutman
Sorry about that, did not go back far enough in the code. Does this one work?

$list-sortBy('eo.startTime', 'desc');
studio108 replied on at Permalink Reply
studio108
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()"
hutman replied on at Permalink Reply
hutman
Did you do $this->sortBy or $list->sortBy?
studio108 replied on at Permalink Reply
studio108
Hi, I used...

$list->sortBy

Error message...
Call to undefined method Application\Block\PastEventsList\Controller::sortBy()
studio108 replied on at Permalink Reply
studio108
I think it is now solved.

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!!!!