예제 #1
0
// course module
$phase = required_param('phase', PARAM_INT);
// the code of the new phase
$confirm = optional_param('confirm', false, PARAM_BOOL);
// confirmation
$cm = get_coursemodule_from_id('teamwork', $cmid, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$teamwork = $DB->get_record('teamwork', array('id' => $cm->instance), '*', MUST_EXIST);
$teamwork = new teamwork($teamwork, $cm, $course);
$PAGE->set_url($teamwork->switchphase_url($phase), array('cmid' => $cmid, 'phase' => $phase));
require_login($course, false, $cm);
require_capability('mod/teamwork:switchphase', $PAGE->context);
if ($confirm) {
    if (!confirm_sesskey()) {
        throw new moodle_exception('confirmsesskeybad');
    }
    if (!$teamwork->switch_phase($phase)) {
        print_error('errorswitchingphase', 'teamwork', $teamwork->view_url());
    }
    redirect($teamwork->view_url());
}
$PAGE->set_title($teamwork->name);
$PAGE->set_heading($course->fullname);
$PAGE->navbar->add(get_string('switchingphase', 'teamwork'));
//
// Output starts here
//
echo $OUTPUT->header();
echo $OUTPUT->heading(format_string($teamwork->name));
echo $OUTPUT->confirm(get_string('switchphase' . $phase . 'info', 'teamwork'), new moodle_url($PAGE->url, array('confirm' => 1)), $teamwork->view_url());
echo $OUTPUT->footer();
예제 #2
0
/**
 * Regular jobs to execute via cron
 *
 * @return boolean true on success, false otherwise
 */
function teamwork_cron()
{
    global $CFG, $DB;
    $now = time();
    mtrace(' processing teamwork subplugins ...');
    cron_execute_plugin_type('teamworkallocation', 'teamwork allocation methods');
    // now when the scheduled allocator had a chance to do its job, check if there
    // are some teamworks to switch into the assessment phase
    $teamworks = $DB->get_records_select("teamwork", "phase = 20 AND phaseswitchassessment = 1 AND submissionend > 0 AND submissionend < ?", array($now));
    if (!empty($teamworks)) {
        mtrace('Processing automatic assessment phase switch in ' . count($teamworks) . ' teamwork(s) ... ', '');
        require_once $CFG->dirroot . '/mod/teamwork/locallib.php';
        foreach ($teamworks as $teamwork) {
            $cm = get_coursemodule_from_instance('teamwork', $teamwork->id, $teamwork->course, false, MUST_EXIST);
            $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
            $teamwork = new teamwork($teamwork, $cm, $course);
            $teamwork->switch_phase(teamwork::PHASE_ASSESSMENT);
            $params = array('objectid' => $teamwork->id, 'context' => $teamwork->context, 'courseid' => $teamwork->course->id, 'other' => array('teamworkphase' => $teamwork->phase));
            $event = \mod_teamwork\event\phase_switched::create($params);
            $event->trigger();
            // 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('teamwork', 'phaseswitchassessment', 0, array('id' => $teamwork->id));
            // todo inform the teachers
        }
        mtrace('done');
    }
    return true;
}