PHP calendar recurrence logic

2020-08-08 10:59发布

问题:

I know that there are a million projects out there that have done this already. Having said that what I am trying to do is create an online calendar using PHP & MySQL here is what I am planning:

  1. tables in database

    ((calendar_item)
    id, title, start_date, start time, end time, recurrence_type_id,
    recurrence_qty, interval, end_date)
    ((recurrence_type)
    id, name, value (where I want to store the logic so it can be edited
    on the fly))
    ((calendar_item_exception)
    id, calendar_item_id, title, start_date, start time, end time,
    recurrence_type_id, recurrence_qty, interval, end_date)
    ((join_calendar_day)
    calendar_id, day_id)
    ((day)
    id, name)
    
  2. Basic flow, pull all records from the database INNER JOIN calendar_item and calendar_item_exception ON id/calendar_item_id

  3. begin by looking at today's date for an exception and print anything that's there... if nothing move on to the calendar_item.

This all makes perfect sense in my head up until this point. I'd like to know where to go from here to add the actual logic for the recurrence_id and how to implement it:

ie item is on __date recurs (recurrence_id) daily (qty) 5x (interval) every 3 days (join_calendar_day) on Monday, Wednesday, Friday

I have seen the ical format, and have looked at PEAR, but honestly can't grasp the next step in my head to make the exceptions (which I really want to see happen without using another framework, preferably just PHP and MySQL).

To clarify my question further, I am looking for real world examples, not abstract principles; I am not programmer, so I have to see something working so I can dissect it to understand it.

No PEAR, no Ruby, no Horde, no other frameworks, just PHP and MySQL and as simple as possible please.

回答1:

This is a duplicate of these questions:

  • Design question: How would you design a recurring event system?
  • What’s the best way to model recurring events in a calendar application?

A good link from one of those questions is this article about it by Martin Fowler.