Skip to content

Commit

Permalink
MDL-32235 scheduled allocation settings form displays the execution s…
Browse files Browse the repository at this point in the history
…tatus

AMOS BEGIN
 CPY [allocationsettings,workshopallocation_random],[randomallocationsettings,workshopallocation_scheduled]
AMOS END
  • Loading branch information
mudrd8mz committed Apr 13, 2012
1 parent 2a3aac4 commit a80b772
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 24 deletions.
2 changes: 1 addition & 1 deletion mod/workshop/allocation/random/settings_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function definition() {
$workshop = $this->_customdata['workshop'];
$plugindefaults = get_config('workshopallocation_random');

$mform->addElement('header', 'settings', get_string('allocationsettings', 'workshopallocation_random'));
$mform->addElement('header', 'randomallocationsettings', get_string('allocationsettings', 'workshopallocation_random'));

$gmode = groups_get_activity_groupmode($workshop->cm, $workshop->course);
switch ($gmode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,32 @@

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

$string['currentstatus'] = 'Current status';
$string['currentstatusexecution'] = 'Status';
$string['currentstatusexecution1'] = 'Executed on {$a->datetime}';
$string['currentstatusexecution2'] = 'To be executed again on {$a->datetime}';
$string['currentstatusexecution3'] = 'To be executed on {$a->datetime}';
$string['currentstatusexecution4'] = 'Awaiting execution';
$string['currentstatusreset'] = 'Reset';
$string['currentstatusresetinfo'] = 'Check the box and save the form to reset the execution result';
$string['currentstatusreset_help'] = 'Saving the form with this checkbox ticked will result in resetting the current status. All the information about the previous execution will be removed so the allocation can be executed again (if enabled above).';
$string['currentstatusresult'] = 'Recent execution result';
$string['currentstatusnext'] = 'Next execution';
$string['currentstatusnext_help'] = 'In some cases, the allocation is scheduled to be automatically executed again even if it was already executed. This may happen if the submissions deadline has been prolonged, for example.';
$string['enablescheduled'] = 'Enable scheduled allocation';
$string['enablescheduledinfo'] = 'Automatically allocate submissions after the deadline';
$string['scheduledsettings'] = 'Scheduled allocation settings';
$string['scheduledsettings_help'] = 'If enabled, the scheduled allocation method will automatically allocate submissions for the assessment at the end of the submission phase. The end of the phase can be defined in the workshop setting \'Submissions deadline\'.
$string['enablescheduledinfo'] = 'Automatically allocate submissions at the end of the submission phase';
$string['scheduledallocationsettings'] = 'Scheduled allocation settings';
$string['scheduledallocationsettings_help'] = 'If enabled, the scheduled allocation method will automatically allocate submissions for the assessment at the end of the submission phase. The end of the phase can be defined in the workshop setting \'Submissions deadline\'.
Internally, the random allocation method is executed with the parameters pre-defined in this form. It means that the scheduled allocation works as if the teacher executed the random allocation themselves at the end of the submission phase using the allocation settings below.
Note that the scheduled allocation is *not* executed if you manually switch the workshop into the assessment phase before the submissions deadline. You have to allocate submissions yourself in that case. The scheduled allocation method is particularly useful when used together with the automatic phase switching feature.';
$string['nosubmissionend'] = 'You have to define the submissions deadline in the workshop settings in order to use scheduled allocation. Press the \'Continue\' button to edit the workshop settings.';
$string['pluginname'] = 'Scheduled allocation';
$string['randomallocationsettings'] = 'Allocation settings';
$string['randomallocationsettings_help'] = 'Parameters for the random allocation method are defined here. They will be used by the random allocation plugin for the actual allocation of submissions.';
$string['resultdisabled'] = 'Scheduled allocation disabled';
$string['resultenabled'] = 'Scheduled allocation enabled';
$string['resultexecuted'] = 'Success';
$string['resultfailed'] = 'Unable to automatically allocate submissions';
$string['resultfailedconfig'] = 'Scheduled allocation misconfigured';
$string['resultfaileddeadline'] = 'Workshop does not have the submissions deadline defined';
Expand Down
41 changes: 26 additions & 15 deletions mod/workshop/allocation/scheduled/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,32 @@ public function init() {
global $PAGE, $DB;

$result = new workshop_allocation_result($this);

$customdata = array();
$customdata['workshop'] = $this->workshop;

$current = $DB->get_record('workshopallocation_scheduled',
array('workshopid' => $this->workshop->id), '*', IGNORE_MISSING);

$customdata['current'] = $current;

$this->mform = new workshop_scheduled_allocator_form($PAGE->url, $customdata);

if ($this->mform->is_cancelled()) {
redirect($PAGE->url->out(false));
redirect($this->workshop->view_url());
} else if ($settings = $this->mform->get_data()) {
if (empty($settings->enablescheduled)) {
$enabled = false;
} else {
$enabled = true;
}
if (empty($settings->reenablescheduled)) {
$reset = false;
} else {
$reset = true;
}
$settings = workshop_random_allocator_setting::instance_from_object($settings);
$this->store_settings($enabled, $settings, $result);
$this->store_settings($enabled, $reset, $settings, $result);
if ($enabled) {
$msg = get_string('resultenabled', 'workshopallocation_scheduled');
} else {
Expand All @@ -82,9 +94,6 @@ public function init() {
// doesn't validate and the form should be redisplayed
// or on the first display of the form.

$current = $DB->get_record('workshopallocation_scheduled',
array('workshopid' => $this->workshop->id), '*', IGNORE_MISSING);

if ($current !== false) {
$data = workshop_random_allocator_setting::instance_from_text($current->settings);
$data->enablescheduled = $current->enabled;
Expand All @@ -104,13 +113,6 @@ public function ui() {

$output = $PAGE->get_renderer('mod_workshop');

// the submissions deadline must be defined
if (empty($this->workshop->submissionend)) {
$out = $output->box(get_string('nosubmissionend', 'workshopallocation_scheduled'), 'generalbox', 'notice');
$out .= $output->continue_button($this->workshop->updatemod_url());
return $out;
}

$out = $output->container_start('scheduled-allocator');
// the nasty hack follows to bypass the sad fact that moodle quickforms do not allow to actually
// return the HTML content, just to display it
Expand Down Expand Up @@ -211,20 +213,27 @@ public static function delete_instance($workshopid) {
* Stores the pre-defined random allocation settings for later usage
*
* @param bool $enabled is the scheduled allocation enabled
* @param bool $reset reset the recent execution info
* @param workshop_random_allocator_setting $settings settings form data
* @param workshop_allocation_result $result logger
*/
protected function store_settings($enabled, workshop_random_allocator_setting $settings, workshop_allocation_result $result) {
protected function store_settings($enabled, $reset, workshop_random_allocator_setting $settings, workshop_allocation_result $result) {
global $DB;


$data = new stdClass();
$data->workshopid = $this->workshop->id;
$data->enabled = $enabled;
$data->submissionend = $this->workshop->submissionend;
$data->timeallocated = null;
$data->settings = $settings->export_text();

if ($reset) {
$data->timeallocated = null;
$data->resultstatus = null;
$data->resultmessage = null;
$data->resultlog = null;
}

$result->log($data->settings, 'debug');

$current = $DB->get_record('workshopallocation_scheduled', array('workshopid' => $data->workshopid), '*', IGNORE_MISSING);
Expand Down Expand Up @@ -257,10 +266,12 @@ function workshopallocation_scheduled_cron() {
$workshops = $DB->get_records_sql($sql, array(time()));

if (empty($workshops)) {
mtrace('No workshops ready for scheduled allocation');
mtrace('... no workshops awaiting scheduled allocation. ', '');
return;
}

mtrace('... executing scheduled allocation in '.count($workshops).' workshop(s) ... ', '');

// let's have some fun!
require_once($CFG->dirroot.'/mod/workshop/locallib.php');

Expand Down
91 changes: 87 additions & 4 deletions mod/workshop/allocation/scheduled/settings_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,99 @@ class workshop_scheduled_allocator_form extends workshop_random_allocator_form {
* Definition of the setting form elements
*/
public function definition() {
global $OUTPUT;

$mform = $this->_form;
$workshop = $this->_customdata['workshop'];
$current = $this->_customdata['current'];

if (!empty($workshop->submissionend)) {
$strtimeexpected = workshop::timestamp_formats($workshop->submissionend);
}

$mform->addElement('header', 'scheduledsettings', get_string('pluginname', 'workshopallocation_scheduled'));
$mform->addHelpButton('scheduledsettings', 'scheduledsettings', 'workshopallocation_scheduled');
if (!empty($current->timeallocated)) {
$strtimeexecuted = workshop::timestamp_formats($current->timeallocated);
}

$mform->addElement('static', 'submissionendinfo', get_string('submissionend', 'workshop'),
workshop::timestamp_formats($workshop->submissionend)->datetime);
$mform->addElement('header', 'scheduledallocationsettings', get_string('scheduledallocationsettings', 'workshopallocation_scheduled'));
$mform->addHelpButton('scheduledallocationsettings', 'scheduledallocationsettings', 'workshopallocation_scheduled');

$mform->addElement('checkbox', 'enablescheduled', get_string('enablescheduled', 'workshopallocation_scheduled'), get_string('enablescheduledinfo', 'workshopallocation_scheduled'), 1);

$mform->addElement('header', 'scheduledallocationinfo', get_string('currentstatus', 'workshopallocation_scheduled'));

if ($current === false) {
$mform->addElement('static', 'infostatus', get_string('currentstatusexecution', 'workshopallocation_scheduled'),
get_string('resultdisabled', 'workshopallocation_scheduled').' '.
html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('t/block'))));

} else {
if (!empty($current->timeallocated)) {
$mform->addElement('static', 'infostatus', get_string('currentstatusexecution', 'workshopallocation_scheduled'),
get_string('currentstatusexecution1', 'workshopallocation_scheduled', $strtimeexecuted).' '.
html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('i/tick_green_big'))));

if ($current->resultstatus == workshop_allocation_result::STATUS_EXECUTED) {
$strstatus = get_string('resultexecuted', 'workshopallocation_scheduled').' '.
html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('i/tick_green_big')));
} else if ($current->resultstatus == workshop_allocation_result::STATUS_FAILED) {
$strstatus = get_string('resultfailed', 'workshopallocation_scheduled').' '.
html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('i/cross_red_big')));
} else {
$strstatus = get_string('resultvoid', 'workshopallocation_scheduled').' '.
html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('i/cross_red_big')));
}

if (!empty($current->resultmessage)) {
$strstatus .= html_writer::empty_tag('br').$current->resultmessage; // yes, this is ugly. better solution suggestions are welcome.
}
$mform->addElement('static', 'inforesult', get_string('currentstatusresult', 'workshopallocation_scheduled'), $strstatus);

if ($current->timeallocated < $workshop->submissionend) {
$mform->addElement('static', 'infoexpected', get_string('currentstatusnext', 'workshopallocation_scheduled'),
get_string('currentstatusexecution2', 'workshopallocation_scheduled', $strtimeexpected).' '.
html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('i/tick_amber_big'))));
$mform->addHelpButton('infoexpected', 'currentstatusnext', 'workshopallocation_scheduled');
} else {
$mform->addElement('checkbox', 'reenablescheduled', get_string('currentstatusreset', 'workshopallocation_scheduled'),
get_string('currentstatusresetinfo', 'workshopallocation_scheduled'));
$mform->addHelpButton('reenablescheduled', 'currentstatusreset', 'workshopallocation_scheduled');
}

} else if (empty($current->enabled)) {
$mform->addElement('static', 'infostatus', get_string('currentstatusexecution', 'workshopallocation_scheduled'),
get_string('resultdisabled', 'workshopallocation_scheduled').' '.
html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('t/block'))));

} else if ($workshop->phase != workshop::PHASE_SUBMISSION) {
$mform->addElement('static', 'infostatus', get_string('currentstatusexecution', 'workshopallocation_scheduled'),
get_string('resultfailed', 'workshopallocation_scheduled').' '.
html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('t/block'))).
html_writer::empty_tag('br').
get_string('resultfailedphase', 'workshopallocation_scheduled'));

} else if (empty($workshop->submissionend)) {
$mform->addElement('static', 'infostatus', get_string('currentstatusexecution', 'workshopallocation_scheduled'),
get_string('resultfailed', 'workshopallocation_scheduled').' '.
html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('t/block'))).
html_writer::empty_tag('br').
get_string('resultfaileddeadline', 'workshopallocation_scheduled'));

} else if ($workshop->submissionend < time()) {
// next cron will execute it
$mform->addElement('static', 'infostatus', get_string('currentstatusexecution', 'workshopallocation_scheduled'),
get_string('currentstatusexecution4', 'workshopallocation_scheduled').' '.
html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('i/tick_amber_big'))));

} else {
$mform->addElement('static', 'infostatus', get_string('currentstatusexecution', 'workshopallocation_scheduled'),
get_string('currentstatusexecution3', 'workshopallocation_scheduled', $strtimeexpected).' '.
html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('i/tick_amber_big'))));
}
}

parent::definition();

$mform->addHelpButton('randomallocationsettings', 'randomallocationsettings', 'workshopallocation_scheduled');
}
}
2 changes: 2 additions & 0 deletions mod/workshop/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,9 @@ function workshop_print_recent_mod_activity($activity, $courseid, $detail, $modn
* @return boolean true on success, false otherwise
*/
function workshop_cron() {
mtrace(' processing workshop subplugins ...');
cron_execute_plugin_type('workshopallocation', 'workshop allocation methods');

return true;
}

Expand Down

0 comments on commit a80b772

Please sign in to comment.