/** * Triggered when the '\mod_teamwork\event\course_module_viewed' event is triggered. * * This does the same job as {@link teamworkallocation_scheduled_cron()} but for the * single teamwork. The idea is that we do not need to wait for cron to execute. * Displaying the teamwork main view.php can trigger the scheduled allocation, too. * * @param \mod_teamwork\event\course_module_viewed $event * @return bool */ public static function teamwork_viewed($event) { global $DB, $CFG; require_once $CFG->dirroot . '/mod/teamwork/locallib.php'; $teamwork = $event->get_record_snapshot('teamwork', $event->objectid); $course = $event->get_record_snapshot('course', $event->courseid); $cm = $event->get_record_snapshot('course_modules', $event->contextinstanceid); $teamwork = new \teamwork($teamwork, $cm, $course); $now = time(); // Non-expensive check to see if the scheduled allocation can even happen. if ($teamwork->phase == \teamwork::PHASE_SUBMISSION and $teamwork->submissionend > 0 and $teamwork->submissionend < $now) { // Make sure the scheduled allocation has been configured for this teamwork, that it has not // been executed yet and that the passed teamwork record is still valid. $sql = "SELECT a.id\n FROM {teamworkallocation_scheduled} a\n JOIN {teamwork} w ON a.teamworkid = w.id\n WHERE w.id = :teamworkid\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('teamworkid' => $teamwork->id, 'phase' => \teamwork::PHASE_SUBMISSION, 'now' => $now); if ($DB->record_exists_sql($sql, $params)) { // Allocate submissions for assessments. $allocator = $teamwork->allocator_instance('scheduled'); $result = $allocator->execute(); // Todo inform the teachers about the results. } } return true; }
} else { $teamworkrecord = $DB->get_record('teamwork', array('id' => $w), '*', MUST_EXIST); $course = $DB->get_record('course', array('id' => $teamworkrecord->course), '*', MUST_EXIST); $cm = get_coursemodule_from_instance('teamwork', $teamworkrecord->id, $course->id, false, MUST_EXIST); } require_login($course, true, $cm); require_capability('mod/teamwork:view', $PAGE->context); $teamwork = new teamwork($teamworkrecord, $cm, $course); // Mark viewed $completion = new completion_info($course); $completion->set_module_viewed($cm); $eventdata = array(); $eventdata['objectid'] = $teamwork->id; $eventdata['context'] = $teamwork->context; $PAGE->set_url($teamwork->view_url()); $event = \mod_teamwork\event\course_module_viewed::create($eventdata); $event->add_record_snapshot('course', $course); $event->add_record_snapshot('teamwork', $teamworkrecord); $event->add_record_snapshot('course_modules', $cm); $event->trigger(); if ($teamwork->applyover == 0 and $teamwork->applyend > 0 and $teamwork->applyend < time()) { generate_instanse_from_templet($teamwork->id); $DB->set_field('teamwork', 'applyover', 1, array('id' => $teamwork->id)); $teamwork->applyover = 1; } if (!is_null($editmode) && $PAGE->user_allowed_editing()) { $USER->editing = $editmode; } $PAGE->set_title($teamwork->name); $PAGE->set_heading($course->fullname); $output = $PAGE->get_renderer('mod_teamwork');