summaryrefslogblamecommitdiffstats
path: root/data_model/TimeSlot.gd
blob: 6f92c817118681792d49e9fc9ac73fa3af262141 (plain) (tree)





































                                                                        






                                                                                      
                    
class_name TimeSlot

class TimeSlot_data:
    var id
    var schedule_id
    var start_time
    var end_time
    var name
    var date_completed

    func _init(record):
        self.id = record['id']
        self.schedule_id = record['schedule_id']
        self.start_time = record['start_time']
        self.end_time = record['end_time']
        self.name = record['name']
        self.date_completed = record['date_completed']

static func get_by_id(id):
    var record = DBMS.query("""
            SELECT * FROM "TimeSlots"
            WHERE id = ?
        """,
        [id])
    record = record[0]
    return TimeSlot_data.new(record)

static func get_by_schedule_name(schedule_name):
    var records = DBMS.query("""
            SELECT "TimeSlots".* FROM "TimeSlots"
            JOIN "Schedules" ON "TimeSlots".schedule_id = "Schedules".id
            WHERE "Schedules".name = ?
            ORDER BY "TimeSlots".start_time
        """,
        [schedule_name])
    var timeslots = []
    for record in records:
        timeslots.push_back(TimeSlot_data.new(record))
    #shift earlier records to the back if they would be <12:00AM after bias correction
    var bias = Time.get_time_zone_from_system().bias * 60
    var tsi = 0
    var tslen = timeslots.size()
    while tsi < tslen && (timeslots[0].start_time + bias < 0):
        tsi += 1
        timeslots.push_back(timeslots.pop_front())
    return timeslots