简体   繁体   中英

Gym Appointments database schema

i am developing a Gym Management app in PHP / Symfony2 / Doctrine 2. And i am developing the Appointments Module. 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. 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.

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:

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

Here you store each date inside the C_date table then references that in the Appointment_date. This is when the appointment is. I would mabye have removed C_date and insted added the info to appointment_date.

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) 

);

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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