OO设计问题(使用Symfony2)

I'm developing a sports court booking system and I need to generate a "booking table" that shows the columns in the table header as courts and the rows as time slots for bookings.

E.g.,

 ___________________________________
|           |           |           |
|  Court 1  |  Court 2  |  Court 3  |
|___________|___________|___________|
|           |           |           |
| 10.00 am  |  10.00 am | 10.00 am  |
|___________|___________|___________|
|           |           |           |
| 11.00 am  |  11.00 am | 11.00 am  |
|___________|___________|___________|

Requirements:

  • A club can have any number of courts
  • A club can have any time increment for bookings (e.g., 1 hour as shown above, 30 minutes, 40 minutes, etc)
  • Each cell in the table represents a "booking"

I want to make sure I do this right from the start so I have a few questions:

  1. What entities would you create to achieve this
  2. How would you go about generating this booking table
  3. How would you link a cell in the above table to a booking

Thanks in advance.

Well, I think this is kind of standard?

First, you need a club entity. Each club can have n courts:

Club 1:n Court

Then there is a booking table, which is 1:n to a court:

Court 1:n Booking

I don't know if your second requirement means that one club has one time increment (in which case this is one variable on the club entity) or if it can has many (than there would be a TimeIncrement entity.

Generating the table can be a bit tricky. Thinking about it for a few minutes I got like 5-6 solutions which might work. You could use special objects which you can ask for the booking for a specific court and time and which search a Collection. Our you could build up an array where you have one key for every time and if there is no booking it's null. Have one array for each court, than do 2 nested for loops and read every value from the arrays. You could build up queries which rearrange the data so you can use them directly. Or maybe you can ask the court object itself for the booking on a specific date and time. But I guess that is what the developer is for... Find out what works best for the given requirements and implement it.

What entities would you create to achieve this

Off the top of my head it looks like you'll need 3: Club, Court, Booking

How would you go about generating this booking table

The table should probably consist of id, court_id, start_time, end_time

How would you link a cell in the above table to a booking

As mentioned above, start/end times are columns in the bookings table.

I would just query the data from the database and turn it into json and pass it into the website. The frontend then can build the table with javascript.

For that I would create a custom entity BookingTable that returns data on request directly as an array which then can be easily turned into json with json_encode.

You can then concentrate on the more detailed pages that show the single booking for which you will automatically create the entities you need (if you didn't already to formulate the DQL for the custom entity for the table).