Exemplo n.º 1
0
 /**
  * Test the workshop reset feature.
  */
 public function test_reset_phase()
 {
     $this->resetAfterTest(true);
     $this->workshop->switch_phase(workshop::PHASE_CLOSED);
     $this->assertEquals(workshop::PHASE_CLOSED, $this->workshop->phase);
     $settings = (object) array('reset_workshop_phase' => 0);
     $status = $this->workshop->reset_userdata($settings);
     $this->assertEquals(workshop::PHASE_CLOSED, $this->workshop->phase);
     $settings = (object) array('reset_workshop_phase' => 1);
     $status = $this->workshop->reset_userdata($settings);
     $this->assertEquals(workshop::PHASE_SETUP, $this->workshop->phase);
     foreach ($status as $result) {
         $this->assertFalse($result['error']);
     }
 }
Exemplo n.º 2
0
// 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;
}
$PAGE->set_title($workshop->name);
$PAGE->set_heading($course->fullname);
if ($perpage and $perpage > 0 and $perpage <= 1000) {
    require_sesskey();
    set_user_preference('workshop_perpage', $perpage);
    redirect($PAGE->url);
}
Exemplo n.º 3
0
/**
 * Regular jobs to execute via cron
 *
 * @return boolean true on success, false otherwise
 */
function workshop_cron() {
    global $CFG, $DB;

    $now = time();

    mtrace(' processing workshop subplugins ...');
    cron_execute_plugin_type('workshopallocation', 'workshop allocation methods');

    // now when the scheduled allocator had a chance to do its job, check if there
    // are some workshops to switch into the assessment phase
    $workshops = $DB->get_records_select("workshop",
        "phase = 20 AND phaseswitchassessment = 1 AND submissionend > 0 AND submissionend < ?", array($now));

    if (!empty($workshops)) {
        mtrace('Processing automatic assessment phase switch in '.count($workshops).' workshop(s) ... ', '');
        require_once($CFG->dirroot.'/mod/workshop/locallib.php');
        foreach ($workshops as $workshop) {
            $cm = get_coursemodule_from_instance('workshop', $workshop->id, $workshop->course, false, MUST_EXIST);
            $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
            $workshop = new workshop($workshop, $cm, $course);
            $workshop->switch_phase(workshop::PHASE_ASSESSMENT);
            $workshop->log('update switch phase', $workshop->view_url(), $workshop->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('workshop', 'phaseswitchassessment', 0, array('id' => $workshop->id));

            // todo inform the teachers
        }
        mtrace('done');
    }

    return true;
}
Exemplo n.º 4
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('workshop', $cmid, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$workshop = $DB->get_record('workshop', array('id' => $cm->instance), '*', MUST_EXIST);
$workshop = new workshop($workshop, $cm, $course);
$PAGE->set_url($workshop->switchphase_url($phase), array('cmid' => $cmid, 'phase' => $phase));
require_login($course, false, $cm);
require_capability('mod/workshop:switchphase', $PAGE->context);
if ($confirm) {
    if (!confirm_sesskey()) {
        throw new moodle_exception('confirmsesskeybad');
    }
    if (!$workshop->switch_phase($phase)) {
        print_error('errorswitchingphase', 'workshop', $workshop->view_url());
    }
    redirect($workshop->view_url());
}
$PAGE->set_title($workshop->name);
$PAGE->set_heading($course->fullname);
$PAGE->navbar->add(get_string('switchingphase', 'workshop'));
//
// Output starts here
//
echo $OUTPUT->header();
echo $OUTPUT->heading(format_string($workshop->name));
echo $OUTPUT->confirm(get_string('switchphase' . $phase . 'info', 'workshop'), new moodle_url($PAGE->url, array('confirm' => 1)), $workshop->view_url());
echo $OUTPUT->footer();