From a80b7728644ffab82c0146de2d00ee953a181c2f Mon Sep 17 00:00:00 2001 From: David Mudrak Date: Fri, 30 Mar 2012 22:08:02 +0200 Subject: [PATCH] MDL-32235 scheduled allocation settings form displays the execution status AMOS BEGIN CPY [allocationsettings,workshopallocation_random],[randomallocationsettings,workshopallocation_scheduled] AMOS END --- .../allocation/random/settings_form.php | 2 +- .../lang/en/workshopallocation_scheduled.php | 22 ++++- mod/workshop/allocation/scheduled/lib.php | 41 ++++++--- .../allocation/scheduled/settings_form.php | 91 ++++++++++++++++++- mod/workshop/lib.php | 2 + 5 files changed, 134 insertions(+), 24 deletions(-) diff --git a/mod/workshop/allocation/random/settings_form.php b/mod/workshop/allocation/random/settings_form.php index 28a523db6a2..ebd702853b5 100644 --- a/mod/workshop/allocation/random/settings_form.php +++ b/mod/workshop/allocation/random/settings_form.php @@ -46,7 +46,7 @@ class workshop_random_allocator_form extends moodleform { $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) { diff --git a/mod/workshop/allocation/scheduled/lang/en/workshopallocation_scheduled.php b/mod/workshop/allocation/scheduled/lang/en/workshopallocation_scheduled.php index 53201479f70..046605872ec 100644 --- a/mod/workshop/allocation/scheduled/lang/en/workshopallocation_scheduled.php +++ b/mod/workshop/allocation/scheduled/lang/en/workshopallocation_scheduled.php @@ -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'; diff --git a/mod/workshop/allocation/scheduled/lib.php b/mod/workshop/allocation/scheduled/lib.php index c58d958ed98..11095a97b58 100644 --- a/mod/workshop/allocation/scheduled/lib.php +++ b/mod/workshop/allocation/scheduled/lib.php @@ -56,20 +56,32 @@ class workshop_scheduled_allocator implements workshop_allocator { 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 { @@ -82,9 +94,6 @@ class workshop_scheduled_allocator implements workshop_allocator { // 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; @@ -104,13 +113,6 @@ class workshop_scheduled_allocator implements workshop_allocator { $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 @@ -211,10 +213,11 @@ class workshop_scheduled_allocator implements workshop_allocator { * 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; @@ -222,9 +225,15 @@ class workshop_scheduled_allocator implements workshop_allocator { $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); @@ -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'); diff --git a/mod/workshop/allocation/scheduled/settings_form.php b/mod/workshop/allocation/scheduled/settings_form.php index 7e4a6325eef..172506d2093 100644 --- a/mod/workshop/allocation/scheduled/settings_form.php +++ b/mod/workshop/allocation/scheduled/settings_form.php @@ -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']; - $mform->addElement('header', 'scheduledsettings', get_string('pluginname', 'workshopallocation_scheduled')); - $mform->addHelpButton('scheduledsettings', 'scheduledsettings', 'workshopallocation_scheduled'); + if (!empty($workshop->submissionend)) { + $strtimeexpected = workshop::timestamp_formats($workshop->submissionend); + } - $mform->addElement('static', 'submissionendinfo', get_string('submissionend', 'workshop'), - workshop::timestamp_formats($workshop->submissionend)->datetime); + if (!empty($current->timeallocated)) { + $strtimeexecuted = workshop::timestamp_formats($current->timeallocated); + } + + $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'); } } diff --git a/mod/workshop/lib.php b/mod/workshop/lib.php index 557a149fd8e..c12c7f5c55b 100644 --- a/mod/workshop/lib.php +++ b/mod/workshop/lib.php @@ -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; }