Jump to content

Sarnoc

Members
  • Posts

    5
  • Joined

  • Last visited

Everything posted by Sarnoc

  1. On the site I run, we present a page for each day of the year. Each page is found using page reference fields because the date that the page presented moves every year, and depending on the day or time of year the page can have a different template. (More background on this previous post if helpful) I currently have a 'relevant pages' section at the top of a page which presents the page for today's date, the previous 2 days, and the next 2 days. The way I've approached this so far is to run a separate MySQL query for each day, load it into a variable, and then run another query, load that into a variable, etc. However, the problem with this is that I'm having to repeat the code for each variable. So for example, create a selector "$find_less_two" for 2 days before today: $find_less_two = " SELECT * FROM `TABLE 1` WHERE `date` = SUBDATE(CURDATE(),2) "; if ($result = $conn->query($find_less_two)) { while ($row = $result->fetch_assoc()) { $sundayyearvar = $row["sunday_year"]; $weekdayyearvar = $row["weekday_year"]; $seasonvar = $row["season"]; $weekvar = $row["week"]; $dayvar = $row["day"]; $solemnityvar = $row["solemnity"]; $typevar = $row["type"]; $feastvar = $row["feast1"]; } if ($typevar == 'season') $date_less_two = $pages->find([ 'template' => 'season-homily', 'Liturgical_Season.title' => $seasonvar, 'Liturgical_Week.title' => $weekvar, 'Day' => $dayvar ]); elseif ($typevar == 'solemnity') $date_less_two = $pages->find([ 'template' => 'solemnity', 'Solemnity' => $solemnityvar, 'Liturgical_Season.title' => $seasonvar ]); etc etc for each '$typevar' that needs to be considered. Rinse and repeat, each time, 5 times. Then, in the PW template, I load the selector that's been populated from the database. That means that for each "$find_day_x" selector, it runs the "find" function and populates a styled front-end: foreach ($date_less_two as $datetwo) { echo " <a href='$datetwo->url' class='day' style='border-top-color:$colour;'> <div class='relevant-date'>{$datetime->date($format = 'l', $ts = '-2 day')}</div>"; if($datetwo->Solemnity) { echo "<div class='relevant-solemnity'>{$datetwo->Solemnity->title}</div>"; } echo "<div class='relevant-title'>{$datetwo->title}</div></a>"; } foreach ($date_less_one as $dateone) { (etc etc) } Again, this means that I have to repeat the code for each selector separately, just to get it to appear as 5 separate days. I honestly can't believe this is the most efficient way, so instead I struck upon the idea of loading all 5 day's results straight into an array from the database. However, I can't find a way to get PW to iteratively $find each page based on that array. Works well enough with one array, but that's basically what I've been doing up until now anyway. I was trying to get away from loading each page individually, but I've run out of ideas. Does anyone have any ideas for how I could make this more efficient? Really, I'd like to extend it well beyond 5 days to cover a whole month or year in a calendar format, but I don't fancy the overhead of running each day as a separate selector for 365 days...
  2. Ok thanks, I'll take a look. I'm really struggling with this so I'm just going to have to hack around with it until I can get something to work..
  3. Hi All, Back again! Following on from my last post (useful for background), I'm now trying to build filters for my website to make it easier to find the correct page. I've used the Skyscrapers style of building an array but I can't work out how to insert logic into the filter. For example, I have the following set up within my filters: Year_Sunday (1 of the 3 Sunday years) Year_Weekday (1 of the 2 weekday years) Season (1 of 6 or so seasons, e.g. Lent) Week (1, number of weeks dependent on length of season) These are referencing page references, so each of those is a separate part of the site structure. In my code, I've just got: foreach(array('Liturgical_Year_Sunday', 'Liturgical_Year_Weekday', 'Liturgical_Season', 'Liturgical_Week') as $key) { if(!$value = $input->get($key)) continue; } as shown in the Skyscrapers demo. This gives me the ability to apply filters, but the logic appears to be OR rather than AND? For example, if I've got both Season and Week filters applied, (e.g. Lent, Week 4), I'll get any results that are tagged with Lent OR Week 4, when in fact what I want is the following filter logic: Liturgical_Year_Sunday OR Liturgical_Year_Weekday AND/OR Liturgical_Season AND Liturgical_Week I'm guessing it's something to do with how you build the selector, but I can't see that in the Skyscrapers code. If someone could give me some hints on where to find it and how to implement this, it would be much appreciated. Thanks
  4. Thanks everyone - I'll have a look and see what I can do! I'll let you know how it goes!
  5. 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: Year1 (1 of the 3 Sunday years) Year2 (1 of the 2 weekday years) Season (1 of 6 or so seasons, e.g. Lent) Week (1, number of weeks dependent on length of season) 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?
×
×
  • Create New...