Jump to content
j__

Listing and filtering contents of repeater fields (similiar to SQL JOIN)

Recommended Posts

On a site that lists events, I am using a repeater field 'event_time', which contains two Inputfield Time fields 'event_time_start' and 'event_time_end'. Some events take place multiple times, others just once. Here's an example for the data structure:

  • event1
    • title: First Event
    • event_time (1):
      • event_time_start: 08:00
      • event_time_end: 09:00
  • event2
    • title: Second Event
    • event_time (1):
      • event_time_start: 08:00
      • event_time_end: 09:00
    • event_time (2):
      • event_time_start: 14:00
      • event_time_end: 18:00
  • event3
    • title: Third Event
    • event_time (1):
      • event_time_start: 07:00
      • event_time_end: 09:30

First, I'd like to generate a list of all events, sorted by event_time_start, with every repeater item added as an actual event (similar to a SQL JOIN clause). The desired output would be:

  • 07:00-09:30 Third Event
  • 08:00-09:00 First Event
  • 08:00-09:00 Second Event
  • 14:00-18:00 Second Event

A selector like

$pages->find('template=event,event_time.event_time_start!=,sort=event_time.event_time_start');

would only return each event page once:

  • 07:00-09:30 Third Event
  • 08:00-09:00 First Event
  • 08:00-09:00 Second Event

without

  • 14:00-18:00 Second Event

Is there a possible alteration of the selector to take all different occurrences into account?

Also I'd like to filter for events taking place in the morning, using a selector like:

$pages->find('template=event,event_time.event_time_start>=06:00,event_time.event_time_start<=12:00,sort=event_time.event_time_start');

However, this would only return each 'event' page, which then contains also the afternoon version of event2.

While I have the impression these are rather simple tasks, I struggle finding a selector-based solution to it. In this example on opening times are some similarities, but it does not deal with multiple occurrences. I'd appreciate your ideas to it.

Share this post


Link to post
Share on other sites

Hello @j__,

using a Repeater field for this use case may be nice on the back-end but as you have already experienced difficult to output.

One possibility could be to build yourself a new PageArray, where you add all repeater items and sort or filter them however you like.

Or you could reconsider and use regular pages for your events. 😉

Regards, Andreas

  • Like 1

Share this post


Link to post
Share on other sites

You could use a selector to match the repeater pages (according to their template) and then get their owner pages (the events) with getForPage().

// You need check_access=0 to match repeater pages for non-superusers
$repeater_items = $pages->find("template=repeater_event_time, event_time_start>=06:00, event_time_start<=12:00, sort=event_time_start, check_access=0");
foreach($repeater_items as $repeater_item) {
    $owner_page = $repeater_item->getForPage();
    // Use $repeater_item and $owner_page as needed to build the event/time string
    // ...
}

 

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 Orkun
      Hi Guys
      I have a problem with a repeater field. Some weeks ago I had exported a repeater field from a dev installation and then imported it to a live installation. All just had worked fine as I remember (the field was created etc...). But today I got an email from the developer of our customer that he has a problem with two repeater fields. When he had changed the fields of another repeater it has also changed it in the other repeater field (which I had imported some weeks ago). I investigated this further and found out that exporting/importing of repeater fields doesn't work for my version of processwire (we are using 2.7.3) (see https://github.com/processwire/processwire-issues/issues/416). 
      So I decided to remove the repeater field and create it again manually on the live enviroment. I could remove the repeater field from the template but I can't delete the repeater field because it is referring to a false repeater template. How can I fix this issue so that I can delete the repeater field?
       
      The "event_dates" repeater field is referring to the "repeater_speciality_adresses" template which is wrong.

      When I try to delete the field I get this error:

       
      Do I need to manually remove the field from the db? What do I exactly need to do?
      Kind Regards
      Orkun
    • By Leftfield
      Hi,

      First, this is production realestate site, big one. So please, if any chanse to fix this without touching database, it would be great

      I have field "pstatus" as a PageReference,
      In the tree under Status as children:
      sold unavailable paused In the template "property" I have dropdown were I choose: empty (nothing); sold; unavailable or paused. If you do not choose anything, property will have active selling status.

      I need help sorting property template in this order: show all empty and than show all sold.

      1031 is Status, parent of the sold unavailable and paused.
       
      $status = $pages->get('1031')->children('sort=pstatus'); $selector[] = "sort=price, pstatus!=$status"; But I got there all except from status. I need to list "sold" too.

       
    • By David Karich
      ProcessWire InputfieldRepeaterMatrixDuplicate
      Thanks to the great ProModule "RepeaterMatrix" I have the possibility to create complex repeater items. With it I have created a quite powerful page builder. Many different content modules, with many more possible design options. The RepeaterMatrix module supports the cloning of items, but only within the same page. Now I often have the case that very design-intensive pages and items are created. If you want to use a content module on a different page (e.g. in the same design), you have to rebuild each item manually every time.
      This module extends the commercial ProModule "RepeaterMatrix" by the function to duplicate repeater items from one page to another page. The condition is that the target field is the same matrix field from which the item is duplicated. This module is currently understood as proof of concept. There are a few limitations that need to be considered. The intention of the module is that this functionality is integrated into the core of RepeaterMatrix and does not require an extra module.
      Check out the screencast
      What the module can do
      Duplicate a repeater item from one page to another No matter how complex the item is Full support for file and image fields Multilingual support Support of Min and Max settings Live synchronization of clipboard between multiple browser tabs. Copy an item and simply switch the browser tab to the target page and you will immediately see the past button Support of multiple RepeaterMatrix fields on one page Configurable which roles and fields are excluded Duplicated items are automatically pasted to the end of the target field and set to hidden status so that changes are not directly published Automatic clipboard update when other items are picked Automatically removes old clipboard data if it is not pasted within 6 hours Delete clipboard itself by clicking the selected item again Benefit: unbelievably fast workflow and content replication What the module can't do
      Before an item can be duplicated in its current version, the source page must be saved. This means that if you make changes to an item and copy this, the old saved state will be duplicated Dynamic loading is currently not possible. Means no AJAX. When pasting, the target page is saved completely No support for nested repeater items. Currently only first level items can be duplicated. Means a repeater field in a repeater field cannot be duplicated. Workaround: simply duplicate the parent item Dynamic reloading and adding of repeater items cannot be registered. Several interfaces and events from the core are missing. The initialization occurs only once after the page load event Changelog
      1.0.4
      Bug fix: Various bug fixes and improvements in live synchronization Bug fix: Items are no longer inserted when the normal save button is clicked. Only when the past button is explicitly clicked Feature: Support of multiple repeater fields in one page Feature: Support of repeater Min/Max settings Feature: Configurable roles and fields Enhancement: Improved clipboard management Enhancement: Documentation improvement Enhancement: Corrected few typos #1 1.0.3
      Feature: Live synchronization Enhancement: Load the module only in the backend Enhancement: Documentation improvement 1.0.2
      Bug fix: Various bug fixes and improvements in JS functions Enhancement: Documentation improvement Enhancement: Corrected few typos 1.0.1
      Bug fix: Various bug fixes and improvements in the duplication process 1.0.0
      Initial release Support this module
      If this module is useful for you, I am very thankful for your small donation: Donate 5,- Euro (via PayPal – or an amount of your choice. Thank you!)
      Download this module
      > Github: https://github.com/FlipZoomMedia/InputfieldRepeaterMatrixDuplicate
      > PW module directory: – soon –
    • By Hubris
      Hi there!
      I'm using some page reference fields to create lists of tags, categories, years, etc.. I'm able to find the pages like so:
      $pages->find("template=project, {$filter}={$page->title}"); Which dynamically does something like: 
      $pages->find("template=project, tags=Experimental"); Only if the value (the page name, like "Experimental") starts with letters. If it starts with numbers, find returns nothing.
      Why is this and how can I fix it?
    • By Elchin
      Hi.
      I want select pages where now between date and end_date or now bigger than date and end_date is empty.
      I have five tried variants:
      $start = strtotime(date('Y-m-d') . " 00:00:00"); $results = $page->children("foo=(date<$start,date_end=''),bar=(date<$start,date_end>=$start),sort=-date,limit=12"); $start = strtotime(date('Y-m-d') . " 00:00:00"); $results = $page->children("date<$start,(date_end='',date_end>=$start),sort=-date,limit=12"); $start = strtotime(date('Y-m-d') . " 00:00:00"); $results = $page->children("date_end=''|date_end>=$start,date<$start,sort=-date,limit=12"); $start = strtotime(date('Y-m-d') . " 00:00:00"); $results = $page->children("!date_end|date_end>=$start,date<$start,sort=-date,limit=12"); $start = strtotime(date('Y-m-d') . " 00:00:00"); $results = $page->children("date_end>=$start|!date_end,date<$start,sort=-date,limit=12"); All this variants not worked for me and returned zero results.
×
×
  • Create New...