Modify "Function scheduler_free_late_unused_slots"

Modify "Function scheduler_free_late_unused_slots"

by Susan Ruiz -
Number of replies: 2

Good day I need help with this function, I want the Scheduler just  can delete  appointments that are gone but after 24 hours.


That is, if a student requests an appointment, you should not book another unless 24 hours have passed, any suggestions on how to modify this function:


function scheduler_free_late_unused_slots($schedulerid, $now=0){

    global $CFG, $DB;

    

    if(!$now) {

        $now = time();

    }

    $sql = '

        SELECT DISTINCT

        s.id

        FROM

        {scheduler_slots} s

        LEFT JOIN

        {scheduler_appointment} a

        ON

        s.id = a.slotid

        WHERE

        a.studentid IS NULL AND

        s.schedulerid = ? AND

        starttime < ?

        ';

    $to_delete = $DB->get_records_sql($sql, array($schedulerid, $now));

    if ($to_delete){

        list($usql, $params) = $DB->get_in_or_equal(array_keys($to_delete));

        $DB->delete_records_select('scheduler_slots', "id $usql", $params);


    }

}


Average of ratings: -
In reply to Susan Ruiz

Re: Modify "Function scheduler_free_late_unused_slots"

by Henning Bostelmann -
Picture of Core developers Picture of Plugin developers

Try this:

$to_delete = $DB->get_records_sql($sql, array($schedulerid, $now - DAYSECS));

In reply to Henning Bostelmann

Re: Modify "Function scheduler_free_late_unused_slots"

by Susan Ruiz -

¡Gracias! I've already solved.

Regards from Venezuela.