コード例 #1
0
ファイル: observer.php プロジェクト: evltuma/moodle
 /**
  * Triggered when the '\mod_workshop\event\course_module_viewed' event is triggered.
  *
  * This does the same job as {@link workshopallocation_scheduled_cron()} but for the
  * single workshop. The idea is that we do not need to wait for cron to execute.
  * Displaying the workshop main view.php can trigger the scheduled allocation, too.
  *
  * @param \mod_workshop\event\course_module_viewed $event
  * @return bool
  */
 public static function workshop_viewed($event)
 {
     global $DB, $CFG;
     require_once $CFG->dirroot . '/mod/workshop/locallib.php';
     $workshop = $event->get_record_snapshot('workshop', $event->objectid);
     $course = $event->get_record_snapshot('course', $event->courseid);
     $cm = $event->get_record_snapshot('course_modules', $event->contextinstanceid);
     $workshop = new \workshop($workshop, $cm, $course);
     $now = time();
     // Non-expensive check to see if the scheduled allocation can even happen.
     if ($workshop->phase == \workshop::PHASE_SUBMISSION and $workshop->submissionend > 0 and $workshop->submissionend < $now) {
         // Make sure the scheduled allocation has been configured for this workshop, that it has not
         // been executed yet and that the passed workshop record is still valid.
         $sql = "SELECT a.id\n                      FROM {workshopallocation_scheduled} a\n                      JOIN {workshop} w ON a.workshopid = w.id\n                     WHERE w.id = :workshopid\n                           AND a.enabled = 1\n                           AND w.phase = :phase\n                           AND w.submissionend > 0\n                           AND w.submissionend < :now\n                           AND (a.timeallocated IS NULL OR a.timeallocated < w.submissionend)";
         $params = array('workshopid' => $workshop->id, 'phase' => \workshop::PHASE_SUBMISSION, 'now' => $now);
         if ($DB->record_exists_sql($sql, $params)) {
             // Allocate submissions for assessments.
             $allocator = $workshop->allocator_instance('scheduled');
             $result = $allocator->execute();
             // Todo inform the teachers about the results.
         }
     }
     return true;
 }
コード例 #2
0
} else {
    $workshoprecord = $DB->get_record('workshop', array('id' => $w), '*', MUST_EXIST);
    $course = $DB->get_record('course', array('id' => $workshoprecord->course), '*', MUST_EXIST);
    $cm = get_coursemodule_from_instance('workshop', $workshoprecord->id, $course->id, false, MUST_EXIST);
}
require_login($course, true, $cm);
require_capability('mod/workshop:view', $PAGE->context);
$workshop = new workshop($workshoprecord, $cm, $course);
// Mark viewed
$completion = new completion_info($course);
$completion->set_module_viewed($cm);
$eventdata = array();
$eventdata['objectid'] = $workshop->id;
$eventdata['context'] = $workshop->context;
$PAGE->set_url($workshop->view_url());
$event = \mod_workshop\event\course_module_viewed::create($eventdata);
$event->add_record_snapshot('course', $course);
$event->add_record_snapshot('workshop', $workshoprecord);
$event->add_record_snapshot('course_modules', $cm);
$event->trigger();
// If the phase is to be switched, do it asap. This just has to happen after triggering
// the event so that the scheduled allocator had a chance to allocate submissions.
if ($workshop->phase == workshop::PHASE_SUBMISSION and $workshop->phaseswitchassessment and $workshop->submissionend > 0 and $workshop->submissionend < time()) {
    $workshop->switch_phase(workshop::PHASE_ASSESSMENT);
    // Disable the automatic switching now so that it is not executed again by accident
    // if the teacher changes the phase back to the submission one.
    $DB->set_field('workshop', 'phaseswitchassessment', 0, array('id' => $workshop->id));
    $workshop->phaseswitchassessment = 0;
}
if (!is_null($editmode) && $PAGE->user_allowed_editing()) {
    $USER->editing = $editmode;