protected function set_slot(\scheduler_slot $slot)
 {
     $this->add_record_snapshot('scheduler_slots', $slot->data);
     $this->add_record_snapshot('scheduler', $slot->get_scheduler()->data);
     $this->slot = $slot;
     $this->data['objecttable'] = 'scheduler_slots';
 }
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 #3
0
 public function add_slot(scheduler_slot $slotmodel, scheduler_student_list $students, $editable)
 {
     $slot = new stdClass();
     $slot->slotid = $slotmodel->id;
     $slot->starttime = $slotmodel->starttime;
     $slot->endtime = $slotmodel->endtime;
     $slot->teacher = $slotmodel->get_teacher();
     $slot->students = $students;
     $slot->editable = $editable;
     $slot->isattended = $slotmodel->is_attended();
     $slot->isappointed = $slotmodel->get_appointment_count();
     $slot->exclusivity = $slotmodel->exclusivity;
     $this->slots[] = $slot;
 }
 /**
  * Create a scheduler slot from the database.
  */
 public static function load_by_id($id, scheduler_instance $scheduler)
 {
     $slot = new scheduler_slot($scheduler);
     $slot->load($id);
     return $slot;
 }
 public function get_value(scheduler_slot $slot, $appointment)
 {
     if (!$appointment instanceof scheduler_appointment) {
         return '';
     }
     return $this->renderer->format_grade($slot->get_scheduler(), $appointment->grade);
 }
Example #6
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);
 }
 /**
  * retrieves an appointment and the corresponding slot
  */
 public function get_slot_appointment($appointmentid)
 {
     global $DB;
     $appointrec = $DB->get_record('scheduler_appointment', array('id' => $appointmentid), '*', MUST_EXIST);
     $slotrec = $DB->get_record('scheduler_slots', array('id' => $appointrec->slotid), '*', MUST_EXIST);
     $slot = new scheduler_slot($this);
     $slot->load_record($slotrec);
     $appointment = new scheduler_appointment($slot);
     $appointment->load_record($appointrec);
     return array($slot, $appointment);
 }