Jump to content

Events calendar strategies


Nils Wiere
 Share

Recommended Posts

For one of my projects, I'm currently building a small events calendar in ProcessWire. One requirement is that an event may have an unlimited number of associated dates. I tried two approaches, however each approach come with a difficulty:

 

1) One page per event with a repeater that holds the dates.

Page: Event 1

  • Text fields for shared event info
  • Repeater with a date field (e.g. Jan 1, Feb 1, ...)

Page: Event 2

  • Text fields for shared event info
  • Repeater with a date field (e.g. Jan 10, Jan 11., ...)

Problem: How can I get a chronological list with all events (dates + shared info) that is sorted like that:

  • Jan 1, Event 1 info
  • Jan 10, Event 2 info
  • Jan 11, Event 2 info
  • Feb 1, Event 1 info
  • ...

I know how to access repeaters, however all I got so far is a list structured like that:

Event 1 info

  • Jan 1
  • Feb 1

Event 2 info

  • Jan 10
  • Jan 11

 

2) A page with a page reference field from which the backend user shall be able to directly create child pages for each associated date.

Problem: What selector string do I need in the page reference setup, to make sure the new page is always created as child of the current page (no matter where that page lives in the backend structure)? Or is this only possible with custom PHP code in ready.php?

 

Would you consider one of those approaches a good strategy? If so, do you have any solution to my problems? If not, is there a better way? 

Link to comment
Share on other sites

I prefer the second approach, where the dates are what organize the events, so you can have something like this on the tree:

Events

--- Calendar

------ 2017

---------- January (with page field to reference all events. And using https://modules.processwire.com/modules/connect-page-fields/ will help a lot)

---------- February...

------ 2018

 

--- Event 01 (with page field to reference all dates. And using https://modules.processwire.com/modules/connect-page-fields/ will help a lot)

--- Event 02 ...

----

So you can have URLS like:

List all events of 2017 – example.com/calendar/2017 

Show an event  – example.com/event-title  (the URL should not show the date as the event can happen anytime)

  • Like 1
Link to comment
Share on other sites

Actually, thinking about it more, this approach will only be good if are you planning to have other content on each month, like a page image, a description, etc.

If you only need to list all the dates where an event can occur, maybe it's better to use an Option field or the Textarea Profield.

Link to comment
Share on other sites

I also think a Page Reference field in conjunction with Connect Page Fields would be a good way to go. But not sure that you need a tree structure for the 'date' pages that is broken down into year, month, etc as per @Sérgio's suggestion. You could just have a single 'dates' parent and each 'date' page has a date field (you could create a pseudo-year/month/day structure for your event listings via URL segments if needed). In your 'event' page you select an existing date page if one exists or create a new date page as needed. The date pages are not children of the event pages but are connected to them via the two-way connection provided by Connect Page Fields.

Edit: one issue with this approach might be that as time goes on you could get a large number of date pages cluttering up the inputfield, and you couldn't do something like limit these to only future dates in the Page Reference field settings or else if you edited an old event the selected pages would be invalid. Maybe the autocomplete inputfield would be a good solution.

Alternatively, if you went with the Repeater approach you would do something like this:

  • Find all repeater 'date' pages by template, sorted by date (you may need check_access=0).
  • Foreach those date pages, getting the event pages associated with the date with getForPage().
  • If you wanted only a single date heading when their are multiple events on that date, in the foreach you would only output the date heading if it is different from the previous date heading.
  • Like 4
Link to comment
Share on other sites

Hi Sérgio and Robin,

thanks a lot for helping out. So the Connect Page Fields module seems to be interesting for the page reference approach – I'll check that out later today.

For now, I took the repeater approach, and your three bullets were essential in achieving the goal, @Robin S. That's how I do it:

1. I search for date repeaters by treating them as template  (by putting "_repeater" before the field name); I can now sort and limit the array to my tasting
2. I set "check_access=0" so that all users can see the results
3. I get field data from the page the repeater is living on by using the getForpage() method. 

$allEvents = $pages->find("template=repeater_event_repeater_datetime, event_datetime>today, sort=event_datetime, limit=14, check_access=0");		

foreach ($allEvents as $event):
	echo "<h4>$event->event_date</h4>";
	echo "<h5>{$event->getForpage()->event_title}</h5>";
	echo "<p>{$event->getForpage()->event_desc}</p>";
endforeach;

So far, that works great. Since there are some tricks involved I didn't know before, I'll keep checking, if there are any "side effects".

  • Like 6
Link to comment
Share on other sites

  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...