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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • 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.
    • By BFD Calendar
      We're looking for someone who can make an addon for our website using Formbuilder and publishing the pages to a Google Calendar instantly.
      The use is a setup for laser reservations for a modelbuilding lab, see www.mekano.info to have a bit of an idea. On the 'calendar' page you'll find a linked Google calendar that lists all events per day. These events are now all added by staff members in a shared Google calendar. Underneath the calendar is a list of recent use of our lasercutters, generated by a form where user, machine and start time are entered and duration is calculated by editing that form. I have a likely form to add a reservation to enter user, machine and time/date but we want them to go into our shared Google calendar 'immediately'. If you look at early June in the calendar you can see how it should look like.
      I know there are simple solutions to make this happen but haven't figured a working out.
      We want Google calendar so all our staff can subscribe and see the calendar on all their devices. On the other hand we want to keep a list of students who made reservations because at some point they are limited.
      If you're interested I can give you a login to see a bit more behind the curtains. Part of the website is public for students and guests, quite a few functional pages are only visible when you're logged in.
    • By jds43
      Hello, I have a Page Reference by template radio button field to promote a certain page (only two options), but I'd like to target the page that isn't selected. This would be used dynamically throughout the site.
      Does anyone know how I could accomplish this? Would I use something like remove() or not()?
       
    • By VeiJari
      Hello forum! 
      Our customer wants to choose only 15 minute intervals in the inputfield Datetime. So the dropdown values would be: 0, 15, 30 and 45.
      Is there an easy way to achieve this?
      Any help is appreciated 🙂
    • By neophron
      Hi,
      I'm looking for a calendar solution. It should be like this: http://www.graalmueritz.net/plan-aurum.php
      The important part is, that the calendar should show 4 different stages:
      1. free
      2. arrival
      3. departure
      4. occupied
      and the actual date.
      This is for a german website. The client wants to manage the calendar be themself.
      I need detailed offers/estimations in €.
       
      thank you, Nikolai
       

×
×
  • Create New...