سؤال

I am developing a php application to manage routine for subjects and teacher timing for my college. However I cannot get the idea (The Logic) behind the proper time management.

The classes are 50 to 100 minutes long and starting from 7 am to 2:30 pm.

I want my application to assign teacher as per the subject and semester and Year and the subjects are also assigned as the year and semester. The timing should not be collided during assignment of the teacher.

I have basic Table setup for my application for now as

Admin users table for admin log in:

1) id 2)username 3)password

Subjects table

1)id 2)name 3) year 4) semester 5) theory_marks 6) practicle_marks

Teacher Table

1)id 2)name 3)position 4)subject_id 5)teacher_time 6)year (which year subject as 1st or second or 3rd) 7)day (Sunday, Monday etc)

My first idea was very basic as to assign a different table for day only which will include column as day names and flag and subject id to know if the day for that subject is active or inactive. and Time in different table as column name as 7am, 730am etc.. however this also does not resolve the logic of assign flag as some subjects will be 100 min long and some will be 50 min only.

How can i make this happen? Right now im clueless behind the logic on how to manage time for subjects and teachers. Please, any help will be great.

هل كانت مفيدة؟

المحلول

All classes take place between 7 am to 2:30 pm, we're talking about 7.5 hrs. which are 450 mins. Now there's a missing input: a class can be scheduled ANYTIME between 7-2:30 ? or only at a certain hours, say: 7am, 8am, ..., 1pm ?

For simplicity (and also cause it makes sense) I'll assume that a class can take place only at specific hours.

So now, when you want to schedule a new class, you'll have to call a PHP function that will look somewhat like the following:

function schedule_class($teacher_id, $subject_id, $day, $hour, $length){
    ...
}

This class will first SELECT from the DB all the classes that this teacher is giving that day within the time-range of:
[$hour - $length, $hour + $length]

Only if you got an empty resultset - you may go ahead and follow with an INSERT.
Otherwise, you should output to screen something like:

"Class <$subject_name> cannot be scheduled at <$day>/<$hour> 
 since it overlaps with <$subject_name of the conflict-class>"

Also, I would take @Havelock's suggestion and separate subjects and teachers.
In addition, I would add to the subjects table fields start_time and end_time so that it'll be easier for you to check if two classes have a conflict.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top