/**
  * Get scheduler instance.
  *
  * NOTE: to be used from observers only.
  *
  * @throws \coding_exception
  * @return \scheduler_instance
  */
 public function get_scheduler()
 {
     if ($this->is_restored()) {
         throw new \coding_exception('get_scheduler() is intended for event observers only');
     }
     if (!isset($this->scheduler)) {
         debugging('scheduler property should be initialised in each event', DEBUG_DEVELOPER);
         global $CFG;
         require_once $CFG->dirroot . '/mod/scheduler/locallib.php';
         $this->scheduler = \scheduler_instance::load_by_coursemodule_id($this->contextinstanceid);
     }
     return $this->scheduler;
 }
 /**
  * Test the "appointment" data object
  * (basic functionality, with minimal reference to slots)
  **/
 public function test_appointment()
 {
     global $DB;
     $instance = scheduler_instance::load_by_coursemodule_id($this->moduleid);
     $slot = array_values($instance->get_slots())[0];
     $factory = new scheduler_appointment_factory($slot);
     $user = $this->getdataGenerator()->create_user();
     $app0 = new stdClass();
     $app0->slotid = 1;
     $app0->studentid = $user->id;
     $app0->attended = 0;
     $app0->grade = 0;
     $app0->appointmentnote = 'testnote';
     $app0->timecreated = time();
     $app0->timemodified = time();
     $id1 = $DB->insert_record('scheduler_appointment', $app0);
     $appobj = $factory->create_from_id($id1);
     $this->assertEquals($user->id, $appobj->studentid);
     $this->assertEquals(fullname($user), fullname($appobj->get_student()));
     $this->assertFalse($appobj->is_attended());
     $this->assertEquals(0, $appobj->grade);
     $app0->attended = 1;
     $app0->grade = -7;
     $id2 = $DB->insert_record('scheduler_appointment', $app0);
     $appobj = $factory->create_from_id($id2);
     $this->assertEquals($user->id, $appobj->studentid);
     $this->assertEquals(fullname($user), fullname($appobj->get_student()));
     $this->assertTrue($appobj->is_attended());
     $this->assertEquals(-7, $appobj->grade);
 }
 public function test_add_slot()
 {
     $scheduler = scheduler_instance::load_by_coursemodule_id($this->moduleid);
     $newslot = $scheduler->create_slot();
     $newslot->teacherid = $this->getDataGenerator()->create_user()->id;
     $newslot->starttime = time() + MINSECS;
     $newslot->duration = 10;
     $allslots = $scheduler->get_slots();
     $this->assertEquals(7, count($allslots));
     $scheduler->save();
 }
예제 #4
0
/**
 * Process ajax requests
 *
 * @package    mod
 * @subpackage scheduler
 * @copyright  2014 Henning Bostelmann and others (see README.txt)
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
define('AJAX_SCRIPT', true);
require_once dirname(dirname(dirname(__FILE__))) . '/config.php';
require_once 'locallib.php';
$id = required_param('id', PARAM_INT);
$action = required_param('action', PARAM_ALPHA);
$cm = get_coursemodule_from_id('scheduler', $id, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$scheduler = scheduler_instance::load_by_coursemodule_id($id);
require_login($course, true, $cm);
require_sesskey();
$return = 'OK';
switch ($action) {
    case 'saveseen':
        $appid = required_param('appointmentid', PARAM_INT);
        $slotid = $DB->get_field('scheduler_appointment', 'slotid', array('id' => $appid));
        $slot = $scheduler->get_slot($slotid);
        $app = $slot->get_appointment($appid);
        $newseen = required_param('seen', PARAM_BOOL);
        if ($USER->id != $slot->teacherid) {
            require_capability('mod/scheduler:manageallappointments', $scheduler->context);
        }
        $app->attended = $newseen;
        $slot->save();