简体   繁体   English

健身房预约数据库架构

[英]Gym Appointments database schema

i am developing a Gym Management app in PHP / Symfony2 / Doctrine 2. And i am developing the Appointments Module. 我正在用PHP / Symfony2 / Doctrine 2开发一个Gym Management应用程序。我也在开发约会模块。 An Appointment can not be a single row with e certain event_date( the date when it is going to happen ) because it continues for several day per week for several weeks or months. 约会不能是带有特定event_date(发生日期的日期)的单行,因为约会每周持续几天,持续数周或数月。 How can i design the Entities for keeping tract of the appointments by displaying them in a Calendar Format, where every day of a certain month i can view the appointments of that day? 我如何通过以日历格式显示约会来设计用于保留约会的实体,以便在某个月的每一天都可以查看当天的约会?

Thank you in advance. 先感谢您。

An Appointment entity should hold information such as an ID, descriptor, start_date, end_date, etc. The important thing to note is the "start" and "end," which gives your Appointment the flexibility of spanning multiple days/months. Appointment实体应该保存ID,描述符,start_date,end_date等信息。要注意的重要一点是“开始”和“结束”,这使您的Appointment可以灵活地跨越多个天/月。

In your calendar, if you wanted to display events whose start and end date are between the week of Jan. 1 to Jan. 7, it would be the following query builder object: 在日历中,如果要显示开始和结束日期在1月1日到1月7日之间的事件,它将是以下查询构建器对象:

// In EntityRepository for Appointments

$this->getQueryBuilder('a')
     ->where('a.startDate BETWEEN :start AND :end')
     ->andWhere('a.endDate BETWEEN :start AND :end')
     ->setParameters([
        "start" => '2016-01-01',
        "end"   => '2016-01-07'
     ])
     ->getQuery()
     ->getResult();

If you wanted just the events of a single day and ending that same day, all you would need to do is adjust your parameters accordingly. 如果您只希望某天发生并在同一天结束的事件,则只需调整参数即可。

Okay, this is a good start. 好的,这是一个好的开始。 I think it forfills all the constraints you have set. 我认为它可以弥补您设置的所有限制。 I have used a cupple of composit keys, but this is to simplify the table. 我已经使用了很多合成键,但这是为了简化表格。

Since the constraint you have set: "because it continues for several day per week for several weeks or months" is the wrong way to look at it. 由于您设置了约束:“因为它每周持续几天,持续数周或数月”,因此是错误的查看方式。 You have to store each entry of the appointment in the table (you can use an xml file if you absolutte want it, but the best way is to use mysql as you were thinking about) 您必须将约会的每个条目存储在表中(如果绝对需要,可以使用xml文件,但是最好的方法是按照您的想法使用mysql)

Here you store each date inside the C_date table then references that in the Appointment_date. 在这里,您将每个日期存储在C_date表中,然后在Appointment_date中引用该日期。 This is when the appointment is. 这是约会的时间。 I would mabye have removed C_date and insted added the info to appointment_date. 我会拜拜删除C_date并insted将信息添加到约会。

create table User(
    user varchar(32) NOT NULL PRIMARY KEY
); 


create table C_date ( 
    c_date DATE NOT NULL PRIMARY KEY 
);

create table Appointment(
    user varchar(32) NOT NULL, 
    trainer varchar(32) NOT NULL,
    CONSTRAINT FOREIGN KEY(user) REFERENCES User(user), 
    CONSTRAINT FOREIGN KEY(trainer) REFERENCES User(user),
    CONSTRAINT id PRIMARY KEY(user, trainer)
); 


create table Appointment_date( 
    user varchar(32) NOT NULL, 
    trainer varchar(32) NOT NULL,
    app_date DATE NOT NULL COMMENT "The time and date for the appointment",
    time TIME NOT NULL, 
    CONSTRAINT FOREIGN KEY(user, trainer) REFERENCES Appointment(user, trainer),
    CONSTRAINT FOREIGN KEY(app_date) REFERENCES C_date(c_date), 
    CONSTRAINT id PRIMARY KEY(user, trainer, app_date) 

); );

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM