Forum for discussing general topics related to Couch.
7 posts Page 1 of 1
I'm trying to think something through and would welcome any advice or insight.

My project involves listing events for a parish church. Events come in four forms:
a) one-off events (with a simple date and time)
b) regular weekly events (on the same day of each week)
c) regular monthly events type 1 (on the same date each month) - 'monthly-1' below
d) regular monthly events type 2 (on the same set weekday of the nth week) - 'monthly-2' below
e) regular monthly events type 3 (on the last set weekday of the month) - 'monthly-3' below

Regular events may or may not have an expiry date.

Examples:
a) 21:30 on the 5th February 2020
b) every Saturday at 18:30
c) 13:00 on the 10th of each month
d) 12:30 on the third Thursday of each month until 4 April 2020
e) 20:30 on the last Sunday of each month

I would like to be able to set up a 'what's on this/next week' page. The problem is how to get all the events due on a day, in time order.

Given a date, I think I'm probably best to create functions which return the weekday, week number and whether we're in the last seven days of the month. My mind is boggling a little over how to get the events back. I'll need a request for each day of the week which looks like:

Code: Select all
[event date] = [current date]
or
(([event expiry date not set] or ([event expiry date] > [current date]))
   and (   ([event is weekly] and ([event day] = [current day]))
      or    ([event is monthly-1] and ([event date] = [current date]))
      or   (([event is monthly-2]) and (([event day] = [current day]) and ([event week] = [current week])))
      or   (([event is monthly-3]) and ([in last seven days] and ([event day] = [current day])))
   )


So for a page showing a week's worth of events, that's looping seven times over quite a complex "pages" tags to be performed.

Is there an easier (and less typing error-prone) way? Or a better way of thinking about this? Might it even be better to pull the whole lot (i.e all events) back and process the resulting list with PHP or Javascript?
Depending on the number of events, this might be a costly db request. Caching of result is very much dependent on site's event-adding strategy. If events are never added on the day they happen, then a cron job to run the query would be okay (or the first visitor of the day triggers the query) with subsequent caching of the result.
Depending on the number of events, this might be a costly db request.


Yes, that was rather my concern!

Is there any mechanism within Couch for cacheing the results and working on a cached copy?

A cron job could be backed up by user instructions to visit a special page (which would trigger the cron job) if adding or editing an event during the same day. I don't see people as likely to add events that late, but late cancellations could well happen.
daldred wrote: ..visit a special page (which would trigger the cron job) if adding or editing an event during the same day.

Certainly, this can be done automatically upon save of a page. There was a discussion about that somewhere and when time comes, I could help find that technical detail.

Important question - are your events coming from a single template or multiple templates? It would help to know how you have events organized and what editables are responsible for all 5 types of events.
I have had some thinking about it and this is THE idea -

A new template with pages reflecting days of the year. Events are processed and added to the pages-days for the year ahead. There will be no query fetching events while deciding if it fits the week. There will he simpler listing of existing pages from the new templatr within 7 days. Trivial job follows to output events from those pages.
That sounds a really good idea! I'll have a think about it and try a few things out. Thanks - exactly the sort of creative thought process I was hoping someone would come up with!
daldred wrote: That sounds a really good idea! I'll have a think about it and try a few things out. Thanks - exactly the sort of creative thought process I was hoping someone would come up with!

I am curious - did anything come out of this idea? :)
7 posts Page 1 of 1
cron