function scheduler_save_slotform(scheduler_instance $scheduler, $course, $slotid, $data)
{
    global $DB;
    if ($slotid) {
        $slot = scheduler_slot::load_by_id($slotid, $scheduler);
    } else {
        $slot = new scheduler_slot($scheduler);
    }
    // Set data fields from input form.
    $slot->starttime = $data->starttime;
    $slot->duration = $data->duration;
    $slot->exclusivity = $data->exclusivityenable ? $data->exclusivity : 0;
    $slot->teacherid = $data->teacherid;
    $slot->notes = $data->notes['text'];
    $slot->notesformat = $data->notes['format'];
    $slot->appointmentlocation = $data->appointmentlocation;
    $slot->hideuntil = $data->hideuntil;
    $slot->emaildate = $data->emaildate;
    $slot->timemodified = time();
    $currentapps = $slot->get_appointments();
    $processedstuds = array();
    for ($i = 0; $i < $data->appointment_repeats; $i++) {
        if ($data->studentid[$i] > 0) {
            $app = null;
            foreach ($currentapps as $currentapp) {
                if ($currentapp->studentid == $data->studentid[$i]) {
                    $app = $currentapp;
                    $processedstuds[] = $currentapp->studentid;
                }
            }
            if ($app == null) {
                $app = $slot->create_appointment();
                $app->studentid = $data->studentid[$i];
            }
            $app->attended = isset($data->attended[$i]);
            $app->appointmentnote = $data->appointmentnote[$i]['text'];
            $app->appointmentnoteformat = $data->appointmentnote[$i]['format'];
            if (isset($data->grade)) {
                $selgrade = $data->grade[$i];
                $app->grade = $selgrade >= 0 ? $selgrade : null;
            }
        }
    }
    foreach ($currentapps as $currentapp) {
        if (!in_array($currentapp->studentid, $processedstuds)) {
            $slot->remove_appointment($currentapp);
        }
    }
    $slot->save();
}
Example #2
0
function scheduler_save_slotform(scheduler_instance $scheduler, $course, $slotid, $data)
{
    global $DB, $COURSE;
    $courseid = $COURSE->id;
    //echo "Course ID: ".$courseid."<br>";
    if ($slotid) {
        $slot = scheduler_slot::load_by_id($slotid, $scheduler);
        $slot->slotid = $slotid;
    } else {
        $slot = new scheduler_slot($scheduler);
    }
    //echo "<pre>";
    //print_r($data);
    //echo "</pre>";
    //die();
    // Set new data from input form.
    $slot->starttime = $data->starttime;
    $slot->duration = $data->duration;
    $slot->teacherid = $data->teacherid;
    $slot->notes = $data->notes['text'];
    $slot->exclusivity = $data->exclusivity;
    $slot->emaildate = $data->emaildate;
    $slot->notesformat = $data->notes['format'];
    $slot->appointmentlocation = $data->appointmentlocation;
    $slot->hideuntil = $data->hideuntil;
    $slot->emaildate = $data->emaildate;
    $slot->timemodified = time();
    $currentapps = $slot->get_appointments();
    $processedstuds = array();
    for ($i = 0; $i < $data->appointment_repeats; $i++) {
        if ($data->studentid[$i] > 0) {
            $app = null;
            foreach ($currentapps as $currentapp) {
                if ($currentapp->studentid == $data->studentid[$i]) {
                    $app = $currentapp;
                    $processedstuds[] = $currentapp->studentid;
                }
            }
            if ($app == null) {
                $app = $slot->create_appointment();
                $app->studentid = $data->studentid[$i];
            }
            $app->attended = isset($data->attended[$i]);
            $app->appointmentnote = $data->appointmentnote[$i]['text'];
            $app->appointmentnoteformat = $data->appointmentnote[$i]['format'];
            if (isset($data->grade)) {
                $selgrade = $data->grade[$i];
                $app->grade = $selgrade >= 0 ? $selgrade : null;
            }
        }
    }
    foreach ($currentapps as $currentapp) {
        if (!in_array($currentapp->studentid, $processedstuds)) {
            $slot->remove_appointment($currentapp);
        }
    }
    // Add additional slot for other course
    if ($courseid == 44 || $courseid == 45) {
        $ds = new Schedule();
        if ($courseid == 44) {
            // Add same slot for Phlebotomy with EKG Workshop course
            $schedulerid = 5;
        }
        // end if $courseid==44
        if ($courseid == 45) {
            // Add same slot for Phlebotomy Workshop course
            $schedulerid = 6;
        }
        $slot->schedulerid = $schedulerid;
        $ds->save_additional_slot($slot);
        //die('Stopped');
    }
    // end if $courseid == 44 || $courseid == 45
    // Saves original slot
    $slot->save();
    // Notify non Phleb workshop users
    // other users notified inside save_additional_slot()
    if ($courseid != 44 && $courseid != 45) {
        if (property_exists($slot, 'slotid')) {
            $slots_array = array($slot->slotid);
            $ds->notify_students($slots_array);
        }
    }
}
 public function test_calendar_events()
 {
     global $DB;
     $scheduler = scheduler_instance::load_by_id($this->schedulerid);
     $slot = scheduler_slot::load_by_id($this->slotid, $scheduler);
     $slot->save();
     $oldstart = $slot->starttime;
     $this->assert_event_exists($this->teacherid, $slot->starttime, "Meeting with your Students");
     foreach ($this->students as $student) {
         $this->assert_event_exists($student, $slot->starttime, "Meeting with your Teacher");
     }
     $newstart = time() + 3 * DAYSECS;
     $slot->starttime = $newstart;
     $slot->save();
     foreach ($this->students as $student) {
         $this->assert_event_absent($student, $oldstart);
         $this->assert_event_exists($student, $newstart, "Meeting with your Teacher");
     }
     $this->assert_event_absent($this->teacherid, $oldstart);
     $this->assert_event_exists($this->teacherid, $newstart, "Meeting with your Students");
     // Delete one of the appointments.
     $app = $slot->get_appointment($this->appointmentids[0]);
     $slot->remove_appointment($app);
     $slot->save();
     $this->assert_event_absent($this->students[0], $newstart);
     $this->assert_event_exists($this->students[1], $newstart, "Meeting with your Teacher");
     $this->assert_event_exists($this->teacherid, $newstart, "Meeting with your Students");
     // Delete all appointments.
     $DB->delete_records('scheduler_appointment', array('slotid' => $this->slotid));
     $slot = scheduler_slot::load_by_id($this->slotid, $scheduler);
     $slot->save();
     foreach ($this->students as $student) {
         $this->assert_event_absent($student, $newstart);
     }
     $this->assert_event_absent($this->teacherid, $newstart);
 }