D
D
Dmitriy G2019-02-01 13:07:29
MySQL
Dmitriy G, 2019-02-01 13:07:29

How to do free time check for Yii2 entry?

Hello, I am developing a system for recording filming, I would like to know how to check a person’s free time for recording, day and time, (an analogy for an appointment with a doctor, a doctor cannot see several people at the same time)
There is a table - an event
5c54152ac1ef2014266885.png
where id_operator, id_journalist, id_driver , id_car is taken from the table
5c541625edae7857774404.png
, you need to check everyone for free time,
and I also wanted to know how to make a selection when recording - showing free dates / times for recording as in public services when making an appointment with a doctor or
5c541729910f5539950638.png
Datetimepickere displayed free time for recording
Googling aside, what to read
found a similar example, but here the time and date are different fields,
is it possible to split when checking DATETIME for further use in fullcalendar?

class Record extends ActiveRecord
{
    // you code

    public function rules()
    {
        return [
            // you code
            [['time', 'data', 'doctor_fio'], 'required'],
            ['doctor_fio', 'validateRecord'],
        ];
    }

    public function validateRecord($attribute)
    {
        // Условие в выражение where установите то, которое вам нужно. 
        // Ниже приведен как пример.
        $exist = self::find()
            ->where([
                'time' => $this->time,
                'date' => $this->date,
                'doctor_fio' => $this->doctor_fio,
            ])->exists();
        if ($exist) {
            $this->addError($attribute, "Запись на это время не возможна");
        }
    }

    // you code
}

I broke my head to implement a "clean" stable version,
I'm sorry, I'm just learning, before that I wrote a site with the MVC model from scratch, I just recently got acquainted with YII2, I really liked
watching the lessons on creating an online store

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
G
grinat, 2019-02-01
@grinat

At first you receive the information on what there are records for this day.
Then you form possible intervals for this day in increments of 15 minutes, for example, you check whether there is already a record for this interval, if not, you display it, otherwise you hide it. All.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question