コード例 #1
0
/**
 * Update activity grades
 *
 * @param object $scheduler
 * @param int $userid specific user only, 0 means all
 */
function scheduler_update_grades($schedulerrecord, $userid = 0, $nullifnone = true)
{
    global $CFG, $DB;
    require_once $CFG->libdir . '/gradelib.php';
    $scheduler = scheduler_instance::load_by_id($schedulerrecord->id);
    if ($scheduler->scale == 0) {
        scheduler_grade_item_update($schedulerrecord);
    } else {
        if ($grades = $scheduler->get_user_grades($userid)) {
            foreach ($grades as $k => $v) {
                if ($v->rawgrade == -1) {
                    $grades[$k]->rawgrade = null;
                }
            }
            scheduler_grade_item_update($schedulerrecord, $grades);
        } else {
            scheduler_grade_item_update($schedulerrecord);
        }
    }
}
コード例 #2
0
 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);
 }
コード例 #3
0
 /**
  * Creates a scheduler with certain settings,
  * having 10 appointments, from 1 hour in the future to 9 days, 1 hour in the future,
  * and booking a given student into these slots - either unattended bookings ($bookedslots)
  * or attended bookings ($attendedslots).
  *
  * The scheduler is created in a new course, into which the given student is enrolled.
  * Also, two other students (without any slot bookings) is created in the course.
  *
  */
 private function create_data_for_bookable_appointments($schedulermode, $maxbookings, $guardtime, $studentid, array $bookedslots, array $attendedslots)
 {
     global $DB;
     $course = $this->getDataGenerator()->create_course();
     $this->getDataGenerator()->enrol_user($studentid, $course->id);
     $options['slottimes'] = array();
     for ($c = 0; $c < 10; $c++) {
         $options['slottimes'][$c] = time() + $c * DAYSECS + HOURSECS;
         if (in_array($c, $bookedslots) || in_array($c, $attendedslots)) {
             $options['slotstudents'][$c] = $studentid;
         }
     }
     $schedrec = $this->getDataGenerator()->create_module('scheduler', array('course' => $course->id), $options);
     $scheduler = scheduler_instance::load_by_id($schedrec->id);
     $scheduler->schedulermode = $schedulermode;
     $scheduler->maxbookings = $maxbookings;
     $scheduler->guardtime = $guardtime;
     $scheduler->save();
     $slotrecs = $DB->get_records('scheduler_slots', array('schedulerid' => $scheduler->id), 'starttime ASC');
     $slotrecs = array_values($slotrecs);
     foreach ($attendedslots as $id) {
         $DB->set_field('scheduler_appointment', 'attended', 1, array('slotid' => $slotrecs[$id]->id));
     }
     for ($i = 0; $i < 2; $i++) {
         $dummystud = $this->create_student($course->id);
     }
     return $scheduler->id;
 }
コード例 #4
0
require_once $CFG->dirroot . '/mod/scheduler/lib.php';
require_once $CFG->dirroot . '/mod/scheduler/locallib.php';
require_once $CFG->dirroot . '/mod/scheduler/renderable.php';
// Read common request parameters.
$id = optional_param('id', '', PARAM_INT);
// Course Module ID - if it's not specified, must specify 'a', see below.
$action = optional_param('what', 'view', PARAM_ALPHA);
$subaction = optional_param('subaction', '', PARAM_ALPHA);
$offset = optional_param('offset', -1, PARAM_INT);
if ($id) {
    $cm = get_coursemodule_from_id('scheduler', $id, 0, false, MUST_EXIST);
    $scheduler = scheduler_instance::load_by_coursemodule_id($id);
} else {
    $a = required_param('a', PARAM_INT);
    // Scheduler ID.
    $scheduler = scheduler_instance::load_by_id($a);
    $cm = $scheduler->get_cm();
}
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$defaultsubpage = groups_get_activity_groupmode($cm) ? 'myappointments' : 'allappointments';
$subpage = optional_param('subpage', $defaultsubpage, PARAM_ALPHA);
require_login($course->id, false, $cm);
$context = context_module::instance($cm->id);
// TODO require_capability('mod/scheduler:view', $context);
// Initialize $PAGE, compute blocks.
$PAGE->set_url('/mod/scheduler/view.php', array('id' => $cm->id));
$output = $PAGE->get_renderer('mod_scheduler');
// Print the page header.
$strschedulers = get_string('modulenameplural', 'scheduler');
$strscheduler = get_string('modulename', 'scheduler');
$strtime = get_string('time');