Jump to content
gmclelland

Upcoming Events Listing Selector

Recommended Posts

I'm trying to show upcoming calendar posting pages that have an event_start_datetime and an event_end_datetime.

The listing should show

  • calendar postings greater than or equal to today (no past events unless it has an event_end_datetime that is within 3 days after today)
  • if the calendar posting has an event_end_datetime and is within 3 days of today it should still show even though the event_start_datetime has passed.

Ex. an event that spans Wed-Saturday. If today is Friday, I still want to show the event on my calendar.

Here is the code I have tried:

$date = date("Y-m-d");// current date
$date_start = strtotime( date('Y-m-d') . " 00:00:00");

$date_end = strtotime(date("Y-m-d", strtotime($date)) . " +1 week");

$paginated_calendar_postings = $pages->get("/calendar")->children("template=calendar-posting|community-event,event_start_datetime>=$date_start, event_end_datetime<=$date_end, sort=-event_start_datetime");

But that doesn't return the correct results.

I've spent all day searching through the forums, but couldn't find an answer.  Any help is appreciated.

Also is there anyway to format your selector on multiple lines like this:

$paginated_calendar_postings = $pages->get("/calendar")->children(
  "template=calendar-posting|community-event,
  event_start_datetime>=$date_start,
  event_end_datetime<=$date_end,
  sort=-event_start_datetime");

It would make it easier to read long selectors.  When I tried it, it didn't work.  I think it even gave the wrong results.

Share this post


Link to post
Share on other sites

you can use arrays in selectors now, or if you prefer you can setup the selector parts in a plain array and then implode it with commas , into a variable, e.g. $selector.

also, i believe to make the logic work in your selector, you may need to use OR groups https://processwire.com/api/selectors/#or-groups

you can't do the separate lines within the selector because there would probably be 'junk' like \n, \s, and possibly \t

  • Like 1

Share this post


Link to post
Share on other sites

Thanks @Macrura.  I think I need to simplify things and limit the calendar postings to single day events only that don't span multiple days.  I would need to create multiple calendar postings for an event that spans multiple days.

Share this post


Link to post
Share on other sites

Simple string concatenation also may help:

$selector  = "parent={$myParentContainer}, template=atemplatesname";
$selector .= ", fieldnameOne=1";
if(--someConditionHere--) $selector .= ", fieldnameTwo!=selected";
...
$selector .= ", sort=afieldname, limit=10";

and this:

 

  • Like 1

Share this post


Link to post
Share on other sites
On 3/16/2017 at 5:35 PM, gmclelland said:

I'm trying to show upcoming calendar posting pages that have an event_start_datetime and an event_end_datetime.

The listing should show

  • calendar postings greater than or equal to today (no past events unless it has an event_end_datetime that is within 3 days after today)
  • if the calendar posting has an event_end_datetime and is within 3 days of today it should still show even though the event_start_datetime has passed.

Ex. an event that spans Wed-Saturday. If today is Friday, I still want to show the event on my calendar.

Here is the code I have tried:


$date = date("Y-m-d");// current date
$date_start = strtotime( date('Y-m-d') . " 00:00:00");

$date_end = strtotime(date("Y-m-d", strtotime($date)) . " +1 week");

$paginated_calendar_postings = $pages->get("/calendar")->children("template=calendar-posting|community-event,event_start_datetime>=$date_start, event_end_datetime<=$date_end, sort=-event_start_datetime");

 

@gmclelland Did you ever find a solution to this issue? I've been searching the forums for this exact thing and can't find anyone else with this problem. Thanks!

Share this post


Link to post
Share on other sites

I think I did, but I can't remember.

I think these links helped me. 

Hope that helps you

 

  • Like 1

Share this post


Link to post
Share on other sites
25 minutes ago, gmclelland said:

For future help, this thread is the most accurate solution in my opinion. Thanks for the reference!

 

 

 

  • Like 1

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 Robin S
      Lister Selector
      A Process module that uses Lister/ListerPro, but with a selector string input instead of the normal InputfieldSelector filters.
      Features
      For power users, typing a selector string is often faster and more intuitive than fiddling with InputfieldSelector. It also lets you copy/paste selector strings that you might be using somewhere else in your code.
      Allows the Lister rows to be sorted by multiple fields (not possible in Lister/ListerPro)
      Allows the use of OR-groups (not possible in Lister/ListerPro)
      If ListerPro is installed you can run ListerPro actions on the listed pages - the available actions are defined in the module config.
      Bookmarks can be configured in the module config and accessed via the flyout menu for the module page.
      Usage
      Type your selector string on the Selector tab. The selector is applied when the "Selector string" field is blurred, so hit Tab when you have finished typing your selector.
      Unlike Lister/ListerPro, you can't sort results by clicking the column headings. Control the sort within the selector string instead.
      Superusers can jump to the module config (e.g. to create a bookmark) by clicking the cog icon at the top right of the module interface.
      The module is mostly intended for use by superusers, because in most cases site editors won't understand the ProcessWire selector string syntax. If you want another role to be able to access Lister Selector then give the role the "lister-selector" permission. Only superusers can define bookmarks because in ProcessWire module config screens are only accessible to superusers.
      Screenshots
      Process page

      Module config (when ListerPro is installed)

      Advanced
      If for any reason you want to create dynamic bookmark links to Lister Selector for a given selector you can do that like this:
      /** @var $pls ProcessListerSelector */ $pls = $modules->get('ProcessListerSelector'); $selector = "template=foo, title%=bar"; $pls_link = $pls->getProcessPage()->url . '?bm=' . $pls->urlSafeBase64Encode($selector); echo "<a href='$pls_link'>My link</a>";  
      https://github.com/Toutouwai/ProcessListerSelector
      https://modules.processwire.com/modules/process-lister-selector/
    • By ottogal
      Hello all,
      using PW 3.0.148 with the regular site profile for a blog, I got an an empty pagination output when I had a Toggle field in the selector.
      The Toggle Fieldtype was introduced with https://processwire.com/blog/posts/pw-3.0.139/ .
      The selector resulting in empty pagination:
      $posts = $pages->find("parent=blog, sort=-date, limit=10, toggle_field=0"); It worked well, when I replaced the Toggle field with a Checkbox field:
      $posts = $pages->find("parent=blog, sort=-date, limit=10, checkbox_field=0"); So the prerequisites for the pagination to work are given.
      The settings for the Toggle field were:
      Formatted value: Integer Label Type: Yes/No Input Type: Toggle buttons Default selected option: No Thanks for any hints!
    • By snck
      Hi there,
      I have a problem constructing a selector that finds all pages that refer to pages with a specific template.
      I have pages using an event template and I want to show events based on a specific context. In this example I want to filter the results and only show event pages that relate to a specific template (exhibitions) in their page field related_pages.
      What I tried:
      $events = $pages->find("template=event, related_pages.template.name=exhibition"); Unfortunately it does not work (0 results).
      Same with this:
      $events = $pages->find("template=event, related_pages=[template.name=exhibition]"); At the moment I am helping myself with the following lines, but I have a strong feeling that there is a more efficient solution:
      $events = $pages->find("template=event"); foreach($events as $event){ if(!count($event->related_pages->find("template=exhibition"))){ $events->remove($event); } }  
      I really hope that one of you can help me out.
      Thanks in advance!
      Flo
    • By Kiwi Chris
      The selector in the following code included in a template is returning nothing, however if I take out the compId.resultsdate<={$today} bit, it works fine, although obviously not filtered on the date field.
      $today = strtotime(date('Y-m-d')); $setImages = $pages->find("template=competitionImage, compId={$page->id}, compId.resultsdate<={$today}, compSubject.name=s, imageRating.title=Merit|Honours,check_access=0"); Here's the results of an example from Tracey Debugger
      templates_id=79, resultsdate<=1587729600, status<2048   SELECT pages.id,pages.parent_id,pages.templates_id FROM `pages` JOIN field_resultsdate AS field_resultsdate ON field_resultsdate.pages_id=pages.id AND (((field_resultsdate.data<='2020-04-25 00:00:00' ) )) WHERE (pages.templates_id=79) AND (pages.status<2048) GROUP BY pages.id Over in my ready.php I have inside a hook that refers directly to the page template that's used for the pages in the page field above:
      $today = strtotime(date('Y-m-d')) $event->return = $event->pages->find("template=competition,eventEnd>={$today},eventStart<={$today}"); In this case the filtering on date fields (albeit different ones) works fine. Can anyone suggest why the filter on the date subfield of the page field isn't working?
      Just to confirm, I do have a date value in the field, and it is a date before today. 🙂
      The problem may be something blatantly obvious, but I can't for the life of me figure out why the selector is returning no results when I include the date filter.
    • By Roberts R
      I have simple page structure:
      category subcategory simple-product simple-product simple-product simple-product subcategory .... category2 so Im at category page and running
      $pages->find("template=simple-product, has_parent=$page, limit=8"); and it returns 0 pages
       
      but this returns 4 pages
      $pages->find("template=simple-product, has_parent=$page"); Can someone explain why limit does not work here?
      EDIT:
      So I did some tests and it seems that any limit=n where n is >= actual page count that is possible ... selector return 0 results.
×
×
  • Create New...