Skip to content

Commit

Permalink
MDL-37781 Check for switching the workshop phase without waiting for …
Browse files Browse the repository at this point in the history
…cron

Now we are checking for the need to switch the phase when the main
view.php is displayed to any user (previously this was done via cron
only). To give our subplugins (such as the scheduled allocation method)
a chance to do what they need to do, the workshop_viewed event is
triggered before the phase is actually switched.
  • Loading branch information
mudrd8mz committed Jan 31, 2013
1 parent 9130843 commit 4ab0bf0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mod/workshop/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

defined('MOODLE_INTERNAL') || die();

$module->version = 2012061700; // the current module version (YYYYMMDDXX)
$module->version = 2012061701; // the current module version (YYYYMMDDXX)
$module->requires = 2012061700; // requires this Moodle version
$module->component = 'mod_workshop'; // full name of the plugin (used for diagnostics)
$module->cron = 60; // give as a chance every minute
18 changes: 18 additions & 0 deletions mod/workshop/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,24 @@
$completion = new completion_info($course);
$completion->set_module_viewed($cm);

// Fire the event
events_trigger('workshop_viewed', (object)array(
'workshop' => $workshop,
'user' => $USER,
));

// 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);
$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));
$workshop->phaseswitchassessment = 0;
}

if (!is_null($editmode) && $PAGE->user_allowed_editing()) {
$USER->editing = $editmode;
}
Expand Down

0 comments on commit 4ab0bf0

Please sign in to comment.