CakePHP - 事件的日期和时间time(s) - 如何构建

发布于 2024-11-04 02:16:09 字数 701 浏览 1 评论 0原文

TLDR:需要了解用户添加日期和日期的最佳方式。事件的时间,以及如何构建数据库


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

添加一个活动,在本周的周一和周三以及三周后的晚上 8 点到 10 点进行。仅在本周的周二和周四,营业时间为下午 6 点至晚上 9 点。


到目前为止我的想法:

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

但是 - 那么如果他们想编辑它,我该如何管理它 - 因为它刚刚创建了多个字段?


我是否在正确的轨道上,我是 CakePHP 的新手。 ,而且我很难想出做事的最佳方法...我还没有寻求技术帮助(不过不会拒绝)-现在,我只需要了解一下也许我需要一个“日期”表和一个“时间”表?也许一个带有引用“dates_data”表中许多单独行的“日期”表

?非常提前寻求任何帮助/指导!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

音盲 2024-11-11 02:16:09

你做得很好。让我分享一下我的想法。

如果我要设计这个,我会有 3 个模型:

事件

  • id
  • user_id
  • 描述
  • 创建(日期时间)
  • 更新(日期时间)

计划

  • id
  • event_id
  • 描述
  • 开始(日期时间)
  • 结束(日期时间)
  • 持续时间(时间,如果为空(NULL),则意味着这是一整天的活动)
  • repeat_time(例如 3:00pm 表示每天下午 3 点)
  • repeat_day(每周/每月,例如周一、周一和周二、周一至周五)
  • repeat_date(每月,例如 1 表示每个月的第 1 天,31 表示每个 31 日或每月月底)
  • repeat_anniversary(每年的特定日期,例如每年 12 月 25 日)

日期

  • id
  • Schedule_id
  • start (datetime)
  • end (datetime)

现在让我们看一个事件的示例。假设我们想要一个将在五月和五月的每个星期六和星期日重复的活动。 2011 年 6 月下午 1:00 至下午 3:00(两小时):

事件表包含事件的基本详细信息。此处将保存一条记录。

时间表表是分开的,以便您可以添加多个时间表。一条记录也将保存在时间表中,其中包含以下字段:

  • 持续时间:02:00
  • 开始:2011-05-01
  • 结束:2011-06-30
  • 重复时间:13:00:00
  • 重复日:01,07(星期日和星期六)

现在,在日期表上,将有 17 条记录,每一条记录对应时间表的一次出现。我之所以把它分开,是为了让我更容易知道事件什么时候发生。例如,在创建日历时,这将很有用。日期表的记录之一如下所示:

  • 开始:2011-05-01 13:00:00
  • 结束:2011-05-01 15:00:00

现在,如果用户编辑时间表怎么办?日程记录将被编辑。所有日期记录也将被编辑。您不想删除并重新创建日期,因为您可能将每个记录用于另一个模型(例如,用户可能希望将其他用户标记为活动每个日期的参与者)。

我希望这有帮助。祝你的项目好运!

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

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

Event

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

Schedule

  • 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)

Date

  • 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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文