Jump to content
Nils Wiere

Events calendar strategies

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? 

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By iipa
      Hi!
      I have two Page Reference fields: Category and Subcategory. Category is parent of Subcategory, and can have 0 to n Subcategories. Fields are selected by dropdown selection.
      I'm trying to achieve following logic:
      1. Select Category (obviously works)
      2. Change Subcategory options based on selected Category (this works)
      3. Hide the Subcategory field if Category has no Subcategories (to prevent weird dropdown with nothing to select)
      I have tried to investigate two possible alternatives to achieve step 3:
      A) Make dynamic condition into Subcategory selection's "Only visible if..." field
      B) Make a hook that fires when Category changes, then hides Subcategory field if Category has no children
      So far I haven't been successful in either. Conditions I've tried always lead to hidden field, and I haven't been able to find set up a hook that fires on field change.
      So here's the question (finally): Is there a way to alter field visibility in API, for example in ready.php or inside a hook? In API I could loop through categories, find the ones that have children and then make a selector based on their IDs.
    • By schwarzdesign
      I'm working on a news feed that will show the most recent news in a full teaser grid, and all older news as a simpler archive-type list view. My selectors so far:
      $news_full = $page->children("template=news, limit={$page->feed_count_full}"); $news_archive = $page->children("template=news, start={$page->feed_count_full}, limit=9999"); The $page->feed_count_full field controls how many items to show in the teaser grid (I've confirmed it contains the correct value, and the $news_full selector works as intended).
      This works, but I don't like the limit in the second selector. Unfortunately, if I leave it out (i.e. I only specify a start, not a limit), the start is ignored and I get all news instead. Not a big problem as we will never have more than 9999 news, but it still bothers me, as semantically speaking I don't want to set a limit in this case.
      Is this the intended behaviour of start/limit selectors? Is there a cleaner way to specify an offset (start selector) without a limit?
      ProcessWire Version 3.0.123
      Thanks!
    • By pwFoo
      I played with the Selectors object and would like to use it for a special use case...
      That is a custom Selectors object with dummy data converted to an php array to see the structure (Selectors object is a WireArray with "fields" added)
      Array ( [0] => Array ( [0] => Array ( [field] => seg1 [value] => val1 [not] => [group] => [quote] => [forceMatch] => ) [1] => Array ( [field] => seg2 [value] => val2 [not] => [group] => [quote] => [forceMatch] => ) ) )  
      But instead of "seg1" the field name is "field" with value "seg1" (= my field name).
       
      So I can't search the Selectors WireArray (= custom WireArray with added Selectors objects) with PW "find('seg1=val1')", Is there a way to search with "find()" or build a simple wrapper to make the elements searchable / filterable with find()?
    • By celfred
      Hello,
      I'm struggling with this : a 'group' field of 'Page' type.
      The parent of selectable pages is '/groups', the template is 'group', and a member can create some groups in the /groups tree. I would like this user to see only the groups he or she has created so in my 'Find selector' in the backend, I would like to use :

      template=group, created_users_id=$user->id But that doesn't seem to work... I still get the list of all available groups in the /groups tree.
      Any idea ?
      I had a feeling I had already seen that before (something like $user->id must be replaced by users_id or something, but I can't find anything in the Forums... and all my tests keep failing...
    • By Peter Knight
      <?php $Cats=$pages->find("parent=1086, id!=$page, sort=sort"); foreach($Cats as $Cat) { echo " I have a selector that pulls in 4 child pages of a parent and the order is set to reflect the order of the tree.
      My client has asked that instead of
      Cat 1 | Cat 2 | Cat 3 | Cat 4
      we instead display
      Cat 4 | Cat 1 | Cat 2 | Cat 3 
      However, I can't change the sort order in the tree.
      Can anyone guide me on the correct approach here?
      Thanks
       
×
×
  • Create New...