Forum

Thread tagged as: Question, Events

Filtering an event by matching with fields in a separate region

Hi there, I'm making a site that includes concert listings for various artists, following the listing/details tutorial. I've got the listing/details pages working, but am now looking to filter outputted events on the details pages to match the artist of each page.

So as far as I can see ( and I hope the code below demonstrates this ) I need to see if the event ID "artist" matches with the "title" ID in the Artist's array.

I'm having trouble using filter, match and value to find this value however. Anybody any experience with something similar?

<?php include('perch/runtime.php'); ?>

    <!doctype html>
    <html lang="en">
      <head>
        <meta charset="utf-8" />
        <title>Artists</title>
      </head>
      <body>

    <?php
    perch_content_create('Artists', array(
     'template'   => 'artist_detail.html',
     'multiple'    => true,
     'edit-mode' => 'listdetail'
    ));
    ?>

    <?php
    if (perch_get('s')) {
     // Detail mode
     perch_content_custom('Artists', array(
          'template' => 'artist_detail.html',
          'filter' => 'slug',
          'match' => 'eq',
          'value' => perch_get('s'),
          'count' => 1
     ));
    perch_events_custom('Artists', array(
          'past-events' => false,
          'filter' => 'title',
          'match' => 'eq',
          'value' => perch_get('s')
));
    perch_layout('global.bottom');
    } else {
     // List mode
     perch_content_custom('Artists', array(
          'template' => 'artist_listing.html'
     ));
    }
    ?>

      </body>
    </html>

Here's how I declare the artist names in the 'Artists' region:

<h1><perch:content id="title" type="text" label="Artist Name" required="true" title="true" /></h1>

And here's my events template.

<div class="table-row col-lg-12">
    <div class="table-left">
        <h4 class="date-day">
        FRI
        </h4>
        <h3 class="date-number">08</h3>
        <h4 class="date-month">JUL</h4>
    </div>
    <div class="table-right">
        <h4 class="venue"><a href="nathan-carter.html">
        <perch:events id="artist" label="Artist List" type="dataselect" page="*" region="Artists" options="title"/>
        </a></h4>
        <a class="special-event" href="">
            <perch:events id="venue" encode="false" label="Venue" />
        </a>
    </div>
</div>
Marc Murray

Marc Murray 0 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

If perch_get('s') holds the artist slug, you might be better storing that against the event

<perch:events id="artist" label="Artist List" type="dataselect" page="*" region="Artists" options="title" values="slug" />

then you'd be able to use

perch_events_custom('Artists', array( 
'past-events' => false, 
'filter' => 'artist', 
'match' => 'eq', 
'value' => perch_get('s') 
));

Hi Drew. When I try that code, the event template shows up empty, and I can't seem to figure out why.

So my region/field ID structure is like this:

events
---artist
---venue

artists
---title

I'm looking to compare the value of 'title' in the Artist's region with the value of 'artist' in events.

When I get to, for example the following URL:

site/artists.php?s=tome-johannes

The artist title is output in artist_detail.html like so:

<h1><perch:content id="title" type="text" label="Artist Name" required="true" title="true" /></h1>

But where the events are output, nothing shows up. I have replaced the code in the events template with the code you provided.

When I leave the perch_events_cutom('Artists', array()); function completely blank, it outputs all events, not filtered by the slug, and echoes the slug of an artists title rather than their name. Even adding 'past-events' => false seems to stop any output. If I then delete values="slug" from the events template, the events go back to not outputting.

Thanks for the response by the way, having real trouble with filter, match and value and it's pretty essential for this project.

Drew McLellan

Drew McLellan 2638 points
Perch Support

the event template shows up empty

Can you clarify what you're seeing? If you turn debug on, do you get any output? If not, have you checked your error log?

Okay I just found a mistake I was making regarding the event template, I was calling artist instead of output. So updated event.html:

<div class="table-row col-lg-12">
    <div class="table-left">
        <h4 class="date-day">
        FRI
        </h4>
        <h3 class="date-number">08</h3>
        <h4 class="date-month">JUL</h4>
    </div>
    <div class="table-right">
        <h4 class="venue"><a href="nathan-carter.html">
        <perch:events id="title" label="Artist List" encode="false" type="dataselect" page="*" region="Artists" options="title" values="slug" /></a></h4>
        <a class="special-event" href="">
            <perch:events id="venue" encode="false" label="Venue" />
        </a>
    </div>
</div>

And what I'm seeing is here: https://imgur.com/a/iSaRj

Debug Log

Debug Message
[1] SELECT regionKey, regionHTML FROM perch2_content_regions WHERE regionPage='/countrynights/artists.php' OR regionPage='*' ORDER BY regionPage DESC
[1] SELECT regionID, regionTemplate, regionPage, regionRev AS rev FROM perch2_content_regions WHERE regionKey='Artists' AND (regionPage='/countrynights/artists.php' OR regionPage='*')
[1] SELECT * FROM ( SELECT idx.itemID, c.regionID, idx.pageID, c.itemJSON, idx2.indexValue as sortval FROM perch2_content_index idx JOIN perch2_content_items c ON idx.itemID=c.itemID AND idx.itemRev=c.itemRev AND idx.regionID=c.regionID JOIN perch2_content_index idx2 ON idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev AND idx2.indexKey='_order' WHERE ((idx.regionID=3 AND idx.itemRev=27)) AND ((idx.indexKey='slug' AND idx.indexValue='tome-johannes')) AND idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev ) as tbl GROUP BY itemID, pageID, itemJSON, sortval ORDER BY sortval ASC LIMIT 0, 1
[1] Using template: /templates/content/artist_detail.html
[2] SELECT DISTINCT e.* FROM perch2_events e
[11] SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=0
[2] Using template: /addons/apps/perch_events/templates/events/event.html
[nil] SELECT c.* FROM perch2_events_categories c, perch2_events_to_categories e2c WHERE c.categoryID=e2c.categoryID AND e2c.eventID='9'
[nil] SELECT c.* FROM perch2_events_categories c, perch2_events_to_categories e2c WHERE c.categoryID=e2c.categoryID AND e2c.eventID='10'
Drew McLellan

Drew McLellan 2638 points
Perch Support

Is your filter now working? What problem are we trying to solve?

The problem is that the filter isn't working. When I try to filter the output with this code:

perch_events_custom('Artists', array( 
'past-events' => false, 
'filter' => 'artist', 
'match' => 'eq', 
'value' => perch_get('s') 
));

The events return blank, without showing the artist name, as shown in this image here: https://imgur.com/a/GfL18

Drew McLellan

Drew McLellan 2638 points
Perch Support

If you turn on debug, what does it output?

Debug Message here:

Debug Message
[1] SELECT regionKey, regionHTML FROM perch2_content_regions WHERE regionPage='/countrynights/artists.php' OR regionPage='*' ORDER BY regionPage DESC
[1] SELECT regionID, regionTemplate, regionPage, regionRev AS rev FROM perch2_content_regions WHERE regionKey='Artists' AND (regionPage='/countrynights/artists.php' OR regionPage='*')
[1] SELECT * FROM ( SELECT idx.itemID, c.regionID, idx.pageID, c.itemJSON, idx2.indexValue as sortval FROM perch2_content_index idx JOIN perch2_content_items c ON idx.itemID=c.itemID AND idx.itemRev=c.itemRev AND idx.regionID=c.regionID JOIN perch2_content_index idx2 ON idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev AND idx2.indexKey='_order' WHERE ((idx.regionID=3 AND idx.itemRev=27)) AND ((idx.indexKey='slug' AND idx.indexValue='tome-johannes')) AND idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev ) as tbl GROUP BY itemID, pageID, itemJSON, sortval ORDER BY sortval ASC LIMIT 0, 1
[1] Using template: /templates/content/artist_detail.html
[2] SELECT DISTINCT e.* FROM perch2_events e
[11] SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=0
[2] Using template: /addons/apps/perch_events/templates/events/event.html
[nil] SELECT c.* FROM perch2_events_categories c, perch2_events_to_categories e2c WHERE c.categoryID=e2c.categoryID AND e2c.eventID='9'
[nil] SELECT c.* FROM perch2_events_categories c, perch2_events_to_categories e2c WHERE c.categoryID=e2c.categoryID AND e2c.eventID='10'

Diagnostics if that's of any use:

Perch: 2.8.31
Production mode: Production (100)
Installed apps: content (2.8.31), assets (2.8.31), categories (2.8.31), perch_events (1.9.3)
DB driver: PDO
DB tables: perch2_categories (0), perch2_category_counts (0), perch2_category_sets (0), perch2_content_index (125), perch2_content_items (46), perch2_content_regions (3), perch2_events (2), perch2_events_categories (0), perch2_events_to_categories (0), perch2_navigation (0), perch2_navigation_pages (0), perch2_page_templates (1), perch2_pages (5), perch2_resource_log (48), perch2_resource_tags (0), perch2_resources (20), perch2_resources_to_tags (0), perch2_settings (11), perch2_user_passwords (0), perch2_user_privileges (28), perch2_user_role_privileges (16), perch2_user_roles (2), perch2_users (1)
Users: 1
App runtimes:
<?php
    $apps_list = array(
        'content', 
        'categories',
        'perch_events'
    );
Scheduled tasks for perch_events: update_category_counts (60 mins)
Editor plug-ins: markitup
H1: 421aa90e079fa326b6494f812ad13e79
L1: 04624fc13b207a8bed031c288c3776cf
F1: 2edba60ed1f613d6dd804feb202456a2
headerColour: #ffffff
content_singlePageEdit: 1
helpURL:
siteURL: /
hideBranding: 0
content_collapseList: 1
lang: en-gb
update_2.8.31: done
latest_version: 2.8.15
on_sale_version: 2.8.32
perch_events_update: 1.8
PERCH_DEVELOPMENT: 10
PERCH_STAGING: 50
PERCH_PRODUCTION: 100
PERCH_DB_USERNAME: cn-admin
PERCH_DB_SERVER: localhost
PERCH_DB_DATABASE: cn-admin
PERCH_DB_PREFIX: perch2_
PERCH_TZ: UTC
PERCH_EMAIL_FROM: marc.murray.92@gmail.com
PERCH_EMAIL_FROM_NAME: Marc Murray
PERCH_LOGINPATH: /countrynights/perch
PERCH_PATH: /Applications/MAMP/htdocs/countrynights/perch
PERCH_CORE: /Applications/MAMP/htdocs/countrynights/perch/core
PERCH_RESFILEPATH: /Applications/MAMP/htdocs/countrynights/perch/resources
PERCH_RESPATH: /countrynights/perch/resources
PERCH_HTML5: 1
PERCH_DEBUG: 1
PERCH_RUNWAY:
PERCH_ERROR_MODE: DIE
PERCH_DATE_LONG: %d %B %Y
PERCH_DATE_SHORT: %d %b %Y
PERCH_TIME_SHORT: %H:%M
PERCH_TIME_LONG: %H:%M:%S
PERCH_RUNWAY_ROUTED:
PERCH_STRONG_PASSWORDS:
PERCH_PREVIEW_ARG: preview
PERCH_TEMPLATE_PATH: /Applications/MAMP/htdocs/countrynights/perch/templates
PERCH_DEFAULT_DOC: index.php
PERCH_DEFAULT_EXT: .php
PERCH_PRODUCTION_MODE: 100
PERCH_RWD:
PERCH_HTML_ENTITIES:
PERCH_SSL:
PERCH_STRIPSLASHES:
PERCH_PROGRESSIVE_FLUSH: 1
PERCH_PARANOID:
PERCH_FORCE_SECURE_COOKIES:
PERCH_PASSWORD_MIN_LENGTH: 6
PERCH_MAX_FAILED_LOGINS: 10
PERCH_AUTH_LOCKOUT_DURATION: 1 HOUR
PERCH_VERIFY_UPLOADS:
PERCH_AUTH_PLUGIN:
PERCH_DB_CHARSET: utf8
PERCH_DB_PORT:
PERCH_DB_SOCKET:
PERCH_SESSION_TIMEOUT_MINS: 20
HOSTING SETTINGS

PHP: 5.6.10
Zend: 2.6.0
OS: Darwin
SAPI: apache2handler
Safe mode: not detected
MySQL client: mysqlnd 5.0.11-dev - 20120503 - $Id: 3c688b6bbc30d36af3ac34fdd4b7b5b787fe5555 $
MySQL server: 5.5.42
Free disk space: 29.63 GB
Extensions: Core, date, ereg, libxml, openssl, pcre, sqlite3, zlib, bcmath, bz2, calendar, ctype, curl, dom, hash, fileinfo, filter, ftp, gd, SPL, iconv, intl, json, ldap, mbstring, session, standard, mysqlnd, mysqli, PDO, pdo_mysql, pdo_sqlite, Phar, posix, Reflection, mysql, SimpleXML, soap, sockets, exif, tokenizer, wddx, xml, xmlreader, xmlwriter, xsl, zip, apache2handler, imap, yaz, mcrypt, gettext, pgsql, pdo_pgsql
GD: Yes
ImageMagick: No
PHP max upload size: 32M
PHP max form post size: 32M
PHP memory limit: 128M
Total max uploadable file size: 32M
Resource folder writeable: Yes
Session timeout: 24 minutes
Native JSON: Yes
Filter functions: Yes
Transliteration functions: Yes
HTTP_HOST: localhost:8888
HTTP_CONNECTION: keep-alive
HTTP_UPGRADE_INSECURE_REQUESTS: 1
HTTP_USER_AGENT: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36
HTTP_ACCEPT: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
HTTP_DNT: 1
HTTP_REFERER: https://localhost:8888/countrynights/perch/core/settings/diagnostics/
HTTP_ACCEPT_ENCODING: gzip, deflate, sdch, br
HTTP_ACCEPT_LANGUAGE: en-US,en;q=0.8
HTTP_COOKIE: SQLiteManager_currentLangue=2; cmsa=1; PHPSESSID=f13fb4a2b2a218a0e99d3207b8d4d18a
PATH: /usr/bin:/bin:/usr/sbin:/sbin
SERVER_SOFTWARE: Apache/2.2.29 (Unix) mod_wsgi/3.4 Python/2.7.8 PHP/5.6.10 mod_ssl/2.2.29 OpenSSL/0.9.8zh DAV/2 mod_fastcgi/2.4.6 mod_perl/2.0.8 Perl/v5.20.0
SERVER_NAME: localhost
SERVER_ADDR: ::1
SERVER_PORT: 8888
REMOTE_ADDR: ::1
DOCUMENT_ROOT: /Applications/MAMP/htdocs
SERVER_ADMIN: you@example.com
SCRIPT_FILENAME: /Applications/MAMP/htdocs/countrynights/perch/core/settings/diagnostics/index.php
REMOTE_PORT: 56715
GATEWAY_INTERFACE: CGI/1.1
SERVER_PROTOCOL: HTTP/1.1
REQUEST_METHOD: GET
QUERY_STRING: extended
REQUEST_URI: /countrynights/perch/core/settings/diagnostics/?extended
SCRIPT_NAME: /countrynights/perch/core/settings/diagnostics/index.php
PHP_SELF: /countrynights/perch/core/settings/diagnostics/index.php
REQUEST_TIME_FLOAT: 1478705791.98
REQUEST_TIME: 1478705791
argc: 1
Drew McLellan

Drew McLellan 2638 points
Perch Support

Ah, if this is filtering Events, then I don't think it's going to work. The Events app is very elderly and doesn't support filtering by dynamic fields - you can only filter the predefined fields.

So there is no way to categorize events? Or can I restructure the site and hardcode the values in? Do the 'name' and 'description' properties count as dynamic, as in can I only filter by date?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Events can have categories, yes.

You can filter on the title, slug, date/time, description, URL.

Hi Drew, Thanks for looking into this. Given that the events app can't filter by custom dynamic fields I've decided to use perch custom content and am making headway with that. Thanks!