コード例 #1
0
 /**
  * Triggered when the '\mod_workshopplus\event\course_module_viewed' event is triggered.
  *
  * This does the same job as {@link workshopplusallocation_scheduled_cron()} but for the
  * single workshopplus. The idea is that we do not need to wait for cron to execute.
  * Displaying the workshopplus main view.php can trigger the scheduled allocation, too.
  *
  * @param \mod_workshopplus\event\course_module_viewed $event
  * @return bool
  */
 public static function workshopplus_viewed($event)
 {
     global $DB, $CFG;
     require_once $CFG->dirroot . '/mod/workshopplus/locallib.php';
     $workshopplus = $event->get_record_snapshot('workshopplus', $event->objectid);
     $course = $event->get_record_snapshot('course', $event->courseid);
     $cm = $event->get_record_snapshot('course_modules', $event->contextinstanceid);
     $workshopplus = new \workshopplus($workshopplus, $cm, $course);
     $now = time();
     // Non-expensive check to see if the scheduled allocation can even happen.
     if ($workshopplus->phase == \workshopplus::PHASE_SUBMISSION and $workshopplus->submissionend > 0 and $workshopplus->submissionend < $now) {
         // Make sure the scheduled allocation has been configured for this workshopplus, that it has not
         // been executed yet and that the passed workshopplus record is still valid.
         $sql = "SELECT a.id\n                      FROM {workshopplusallocation_sch} a\n                      JOIN {workshopplus} w ON a.workshopplusid = w.id\n                     WHERE w.id = :workshopplusid\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('workshopplusid' => $workshopplus->id, 'phase' => \workshopplus::PHASE_SUBMISSION, 'now' => $now);
         if ($DB->record_exists_sql($sql, $params)) {
             // Allocate submissions for assessments.
             $allocator = $workshopplus->allocator_instance('scheduled');
             $result = $allocator->execute();
             // Todo inform the teachers about the results.
         }
     }
     return true;
 }
コード例 #2
0
    $course = $DB->get_record('course', array('id' => $workshopplusrecord->course), '*', MUST_EXIST);
    $cm = get_coursemodule_from_instance('workshopplus', $workshopplusrecord->id, $course->id, false, MUST_EXIST);
}
require_login($course, true, $cm);
require_capability('mod/workshopplus:view', $PAGE->context);
$workshopplus = new workshopplus($workshopplusrecord, $cm, $course);
// Mark viewed
$completion = new completion_info($course);
$completion->set_module_viewed($cm);
$eventdata = array();
$eventdata['objectid'] = $workshopplus->id;
$eventdata['context'] = $workshopplus->context;
$eventdata['courseid'] = $course->id;
$eventdata['other']['content'] = $workshopplus->phase;
$PAGE->set_url($workshopplus->view_url());
$event = \mod_workshopplus\event\course_module_viewed::create($eventdata);
$event->add_record_snapshot('course', $course);
$event->add_record_snapshot('workshopplus', $workshopplusrecord);
$event->add_record_snapshot('course_modules', $cm);
$event->set_page_detail();
$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 ($workshopplus->phase == workshopplus::PHASE_SUBMISSION and $workshopplus->phaseswitchassessment and $workshopplus->submissionend > 0 and $workshopplus->submissionend < time()) {
    $workshopplus->switch_phase(workshopplus::PHASE_ASSESSMENT);
    $workshopplus->log('update switch phase', $workshopplus->view_url(), $workshopplus->phase);
    // 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('workshopplus', 'phaseswitchassessment', 0, array('id' => $workshopplus->id));
    $workshopplus->phaseswitchassessment = 0;
}