Jump to content
Sarnoc

Help needed with a system that pulls up a specific page for each day of the year

Recommended Posts

Hi all,

Found Processwire when trying to decide what to use to update a website I run for a friend and was hoping for some advice on designing the most important system I need for this website to work.

First some background: the site is for a Priest; he has hundreds of homilies, one for each day of the year. The concept is that on each day of the year, the relevant day's homily will be highlighted to readers (probably at the top of the homepage). The complication with this is that the Church calendar runs in a three year cycle on Sundays and two years on weekdays, and Easter moves around which means that a homily could, for example, either be on the 28th February or the 20th May, or various dates in between. So I'm trying to escape from being tied to the Gregorian calendar except in a superficial way.

Each homily is unique to a specific day of a specific year, so I've added fields that can be selected to find a specific homily, getting more granular each time:

  1. Year1 (1 of the 3 Sunday years)
  2. Year2 (1 of the 2 weekday years)
  3. Season (1 of 6 or so seasons, e.g. Lent)
  4. Week (1, number of weeks dependent on length of season)
  5. Day of week (1 of 7)

So with this information we can find any homily for any given day. For example, today (15/04/2019) [value in brackets] is Day[Monday], Week[6], Season[Lent], Year2[Cycle 1], Year1[Year C].

At the moment, I've thrown that into a database - so now I can input any date 2019-2022 and find out what that specific day would be in 'Church calendar' terms - and that can be extended pretty much infinitely without much effort

On the Processwire end, I followed the Tutorial: Approaches to categorising site content - Tutorials - ProcessWire Support Forums tutorial using the Simple Multiple Categories approach and ended up with the following page structure:

> Home

>>Homilies

>>>Homily1, Homily2, etc

>>Season

>>>Lent, Advent, etc

and so on.

One of the things that was confusing me was that you can't seem to address a page by its Title but instead have to use its Id number - e.g. instead of just looking for "Lent" it has to be "1057". This is fine when you're only addressing things in Processwire, but I don't want to have to hardcode the page Id into my background database when I know that "Lent" is never going to be changed from being "Lent" - basically in my use case, "Lent" is as reliable as "1057" for me to work with. So I went looking in Adminer and found that the "field_title" database in Processwire contains the Id of each page and its Title. The concept I'm now working with is that I should be able to just search in this table for "Lent", return "1057" for the page Id, and then place that into a second query (somehow on the Processwire end) which just looks for each relevant Id number like any query in Processwire - e.g.

$dailyhomily = $pages->find("template='homily', Year1='1029', Season='1057'"); etc.

Obviously, the Year1, Season etc would have to use variables.

To be honest, I'm just looking for suggestions on approach at this point. I'm right at my limits when it comes to PHP (can get by) and SQL (really bad) but I don't mind learning and messing around until something works!

Gut feeling is that this is a module somehow, but I'm not even close to understanding how to hook into the background stuff with Processwire so likely to need a lot of help with that?

Share this post


Link to post
Share on other sites

A specific page, or list of pages for a specific day of the year is exactly what I'm using Processwire for with https://www.birthfactdeathcalendar.net/. I'm definitely not a PHP crack either. On my home page of course I only search for events on this day and month:

    $todayday = date("d");
    $todaymonth = date("m");
    $features = $pages->find("parent=/events/|/the-eyes/, bfd_day.name=$todayday, bfd_month.name=$todaymonth, sort=bfd_year");

To me id is more reliable than title and/or page name, because at some point it happens I find out a title (like a person's name or even a street address) was misspelled. When I change the title and/or page name I'd have to re-code every reference to it, while the id just stays the same. I have over 26000 pages by now and everything still runs very smooth for several years now.

With help from dedicated members here I also learned a lot. Most of what I use is in Processwire itself, hardly using any modules apart from MapMarker. Good luck!

  • Thanks 1

Share this post


Link to post
Share on other sites

I think another approach is just having a "Homily" template.That uses a repeater field to storage dates and seasons.
Maybe a structure similar to this

<homilies>
<homily>

   <title />

  <about />

   <repeater>
       <priority type="int"/>

       <date/>

       <season />

   </repeater>

</homily>
  <homily>

   <title />

  <about />

   <repeater>
       <priority type="int"/>

       <date/>

       <season />

   </repeater>

</homily>
  <homily>

   <title />

  <about />

   <repeater>
       <priority type="int"/>

       <date/>

       <season />

   </repeater>

</homily>
</homilies>

 So you can search all the homilies and put the different dates and season configuration for that homily.

If one or more homily is on the same date then you can use the priority field to sort them out.

Edited by clsource
added homilies for more clarity
  • Thanks 1

Share this post


Link to post
Share on other sites

Hi @Sarnoc and welcome to the forum,

53 minutes ago, Sarnoc said:

Gut feeling is that this is a module somehow, but I'm not even close to understanding how to hook into the background stuff with Processwire so likely to need a lot of help with that?

It does not sound like you'll need any hooks or custom SQL to get what you are trying 😉 This page is your best friend: https://processwire.com/docs/selectors/

I think your setup is good as it is! I'd not recommend using repeaters for that. Pages are in general more flexible and better/easier to maintain in the long run in my opinion.

I also wonder why the find operation does not work... IMHO it should. I guess your pages have a different NAME (not title)... Using TracyDebugger you can easily and quickly try such things:

LoJ9PNn.png

"poc" is a page reference field. And the referenced field has title="Jakob Enigl Pagetitle" and name="Jakob Enigl Pagename"

That's why the first line does NOT work and the other lines do work. The first dump looks for the pagename (no subfield specified) and I guess it does work because the string is sanitized to a pagename (see last dump).

When building your queries with user input or dynamic values it's sometimes easier and more readable to build your selectors as arrays:

aUC5mob.png

 

  • Like 4

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.

×
×
  • Create New...