2011-04-27 23:41
浏览 14

CakePHP - 事件的日期和时间 - 如何构建

TLDR: Need to understand the best way for a user to be able to add a date(s) & time(s) for an event, and how to structure database

Explanation: When a user adds an event, they need to be able to choose the date of the event, whether or not it will repeat daily/weekly/monthly, start and end time of the event or "all-day", if it's weekdays only or weekend...etc. Basically everything you can do w/ Google calendar when you create an event and they need to be able to edit it too (if that matters). But ALSO, they need to be able to add another date/time - for instance:

Add an event where on Monday and Wednesday of this week and three weeks from now, it goes from 8-10pm. On Tuesday and Thursday this week only, it goes from 6-9pm.

My thoughts so far:

Create a "dates" table with a HABTM relationship w/ my "events" table. When a user adds a date (with all the options of repeat..etc etc., it runs a function to process those repeats/limits...etc and adds all the dates into the dates table w/ their start/end times.

But - then how do I manage it if they want to edit that - since it just created multiple fields.

Question / Help?:

Am I even on the right track with this? I'm new to CakePHP, and it's hard for me to wrap my head around the best ways to do things... I'm not yet looking for technical help (would not turn it down though) - for now, I just need to get the idea for the best way to structure everything to be able to manage this. Maybe I need a "dates" table AND a "times" table? Maybe a "dates" table with an id that references many individual rows in a "dates_data" table?

Thank you very much ahead of time for any help / direction!

图片转代码服务由CSDN问答提供 功能建议

TLDR 需要了解用户能够添加的最佳方式 日期& 一个事件的时间,以及如何构建数据库

说明: 当用户添加事件时,他们需要 能够选择活动的日期,是否会重复每日/每周/每月,活动的开始和结束时间或“全天”,如果只是工作日或周末......等等。 基本上,当您创建活动时,您可以使用Google日历执行所有操作,并且他们也需要能够编辑它(如果这很重要)。 但另外,他们需要能够添加另一个日期/时间 - 例如:

在本周一和周三添加一个事件,从现在开始三周,它从8开始 -下午10点。 仅在本周二和周四,它从6-9点开始。

到目前为止我的想法: \ n

使用我的“事件”表创建一个带有HABTM关系的“日期”表。 当用户添加日期(具有repeat..etc等所有选项)时,它会运行一个函数来处理这些重复/限制...等等,并将所有日期添加到日期表中,以及它们的开始/结束时间。

但是 - 如果他们想要编辑它,我该怎么办呢?因为它只创建了多个字段。


我是否正确地走上正轨?我是CakePHP的新手,我很难缠头 围绕最好的做事方式......我还没有寻求技术帮助(虽然不会拒绝) - 现在,我只需要想出最好的方法来构建一切能够管理的东西 也许我需要一个“日期”表和一个“时间”表?也许一个“日期”表的id引用了“dates_data”表中的许多单独的行?

谢谢 你提前得到任何帮助/指示!

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duangu9666 2011-04-28 03:51

    You're doing great. Let me just share my thoughts.

    If I would design this, I'd have 3 models:


    • id
    • user_id
    • description
    • created (datetime)
    • updated (datetime)


    • id
    • event_id
    • description
    • start (datetime)
    • end (datetime)
    • duration (time, if empty(NULL) it means this is a whole day event)
    • repeat_time (e.g. 3:00pm means 3pm daily)
    • repeat_day (for weekly/monthly, e.g. Monday, Monday & Tuesday, Monday to Friday)
    • repeat_date (for monthly, e.g. 1 means every 1st day of month, 31 means every 31st or end of the month)
    • repeat_anniversary (for specific date every year, e.g. every December 25th)


    • id
    • schedule_id
    • start (datetime)
    • end (datetime)

    Now let's have an example of an event. Let's say we want an event that will repeat every Saturday and Sunday of May & June 2011 at 1:00pm until 3:00pm (two hours):

    The events table contains the basic detail of an event. One record will be saved here.

    The schedules table is separated so that you could add multiple schedules. One record will also be saved in schedule with the following fields:

    • duration: 02:00
    • start: 2011-05-01
    • end: 2011-06-30
    • repeat_time: 13:00:00
    • repeat_day: 01,07 (Sunday & Saturday)

    Now on dates table, there will be 17 records, one for each occurrence of the schedule. The reason why I separated this is that it will be easier for me know when will the event fall. This will be useful, for example, when creating the calendar. One of the records for the dates table will look like this:

    • start: 2011-05-01 13:00:00
    • end: 2011-05-01 15:00:00

    Now what if the user edits the schedule? The schedule record would be edited. All dates record would also be edited. You don't wanna delete and recreate the dates, since you might use each record for another model (e.g. user might want to tag other users as attendees for each date of the event).

    I hope this helps. Goodluck on your project!

    点赞 评论

相关推荐 更多相似问题