From 32c78bc325587fe48fb8b5e4b3b677a31cd80524 Mon Sep 17 00:00:00 2001 From: David Mudrak Date: Fri, 9 Jul 2010 07:55:23 +0000 Subject: [PATCH] NOMDL workshop: added new toolbox viewlet, first tool lets you to clear aggregated grades --- mod/workshop/lang/en/workshop.php | 4 +++ mod/workshop/locallib.php | 58 +++++++++++++++++++++++++++++++ mod/workshop/styles.css | 6 ++++ mod/workshop/toolbox.php | 49 ++++++++++++++++++++++++++ mod/workshop/version.php | 2 +- mod/workshop/view.php | 14 ++++++++ 6 files changed, 132 insertions(+), 1 deletion(-) create mode 100644 mod/workshop/toolbox.php diff --git a/mod/workshop/lang/en/workshop.php b/mod/workshop/lang/en/workshop.php index a8de5d57ced..0edebb87a56 100644 --- a/mod/workshop/lang/en/workshop.php +++ b/mod/workshop/lang/en/workshop.php @@ -63,6 +63,9 @@ $string['calculategradinggrades'] = 'Calculate assessment grades'; $string['calculategradinggradesdetails'] = 'expected: {$a->expected}
calculated: {$a->calculated}'; $string['calculatesubmissiongrades'] = 'Calculate submission grades'; $string['calculatesubmissiongradesdetails'] = 'expected: {$a->expected}
calculated: {$a->calculated}'; +$string['clearaggregatedgrades'] = 'Clear all aggregated grades'; +$string['clearaggregatedgrades_help'] = 'The calculated grades for submission and grades for assessment will be reset. You can re-calculate these grades from scratch in Grading evaluation phase again.'; +$string['clearaggregatedgradesconfirm'] = 'Are you sure you want to clear the calculated grades for submissions and grades for assessment? '; $string['configexamplesmode'] = 'Default mode of examples assessment in workshops'; $string['configgrade'] = 'Default maximum grade for submission in workshops'; $string['configgradedecimals'] = 'Default number of digits that should be shown after the decimal point when displaying grades.'; @@ -209,6 +212,7 @@ $string['taskinstructauthors'] = 'Provide instructions for submission'; $string['taskinstructreviewers'] = 'Provide instructions for assessment'; $string['taskintro'] = 'Set the workshop introduction'; $string['tasksubmit'] = 'Submit your work'; +$string['toolbox'] = 'Workshop toolbox'; $string['undersetup'] = 'The workshop is currently being set up. Please wait until it is switched to the next phase.'; $string['useexamples'] = 'Use examples'; $string['useexamples_desc'] = 'Example submissions are provided for practice in assessing'; diff --git a/mod/workshop/locallib.php b/mod/workshop/locallib.php index f6dcd62345b..4ee2d6b3c7b 100644 --- a/mod/workshop/locallib.php +++ b/mod/workshop/locallib.php @@ -1038,6 +1038,14 @@ class workshop { return new moodle_url('/mod/workshop/aggregate.php', array('cmid' => $this->cm->id)); } + /** + * @return moodle_url of this workshop's toolbox page + */ + public function toolbox_url($tool) { + global $CFG; + return new moodle_url('/mod/workshop/toolbox.php', array('id' => $this->cm->id, 'tool' => $tool)); + } + /** * Are users allowed to create/edit their submissions? * @@ -1447,6 +1455,31 @@ class workshop { return $this->real_grade_value($value, $this->gradinggrade); } + /** + * Sets the grades for submission to null + * + * @param null|int|array $restrict If null, update all authors, otherwise update just grades for the given author(s) + * @return void + */ + public function clear_submission_grades($restrict=null) { + global $DB; + + $sql = "workshopid = :workshopid AND example = 0"; + $params = array('workshopid' => $this->id); + + if (is_null($restrict)) { + // update all users - no more conditions + } elseif (!empty($restrict)) { + list($usql, $uparams) = $DB->get_in_or_equal($restrict, SQL_PARAMS_NAMED); + $sql .= " AND authorid $usql"; + $params = array_merge($params, $uparams); + } else { + throw new coding_exception('Empty value is not a valid parameter here'); + } + + $DB->set_field_select('workshop_submissions', 'grade', null, $sql, $params); + } + /** * Calculates grades for submission for the given participant(s) and updates it in the database * @@ -1501,6 +1534,31 @@ class workshop { $rs->close(); } + /** + * Sets the aggregated grades for assessment to null + * + * @param null|int|array $restrict If null, update all reviewers, otherwise update just grades for the given reviewer(s) + * @return void + */ + public function clear_grading_grades($restrict=null) { + global $DB; + + $sql = "workshopid = :workshopid"; + $params = array('workshopid' => $this->id); + + if (is_null($restrict)) { + // update all users - no more conditions + } elseif (!empty($restrict)) { + list($usql, $uparams) = $DB->get_in_or_equal($restrict, SQL_PARAMS_NAMED); + $sql .= " AND userid $usql"; + $params = array_merge($params, $uparams); + } else { + throw new coding_exception('Empty value is not a valid parameter here'); + } + + $DB->set_field_select('workshop_aggregations', 'gradinggrade', null, $sql, $params); + } + /** * Calculates grades for assessment for the given participant(s) * diff --git a/mod/workshop/styles.css b/mod/workshop/styles.css index f2798b40fce..9e82c108b6d 100644 --- a/mod/workshop/styles.css +++ b/mod/workshop/styles.css @@ -386,6 +386,12 @@ display: inline; } +.path-mod-workshop .toolboxaction, +.path-mod-workshop .toolboxaction form, +.path-mod-workshop .toolboxaction form div { + display: inline; +} + .path-mod-workshop div.buttonwithhelp div { display: inline; } diff --git a/mod/workshop/toolbox.php b/mod/workshop/toolbox.php new file mode 100644 index 00000000000..2988f63215b --- /dev/null +++ b/mod/workshop/toolbox.php @@ -0,0 +1,49 @@ +. + +/** + * Various workshop maintainance utilities + * + * @package mod_workshop + * @copyright 2010 David Mudrak + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +require_once(dirname(dirname(dirname(__FILE__))).'/config.php'); +require_once(dirname(__FILE__).'/locallib.php'); + +$id = required_param('id', PARAM_INT); // course_module ID +$tool = required_param('tool', PARAM_ALPHA); + +$cm = get_coursemodule_from_id('workshop', $id, 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); + +require_login($course, false, $cm); +$workshop = new workshop($workshop, $cm, $course); +require_sesskey(); + +switch ($tool) { +case 'clearaggregatedgrades': + require_capability('mod/workshop:overridegrades', $workshop->context); + add_to_log($course->id, 'workshop', $tool, 'view.php?id=' . $cm->id, $workshop->name, $cm->id); + $workshop->clear_submission_grades(); + $workshop->clear_grading_grades(); + break; +} + +redirect($workshop->view_url()); diff --git a/mod/workshop/version.php b/mod/workshop/version.php index 40f9c9241a0..f9fbfd0546d 100644 --- a/mod/workshop/version.php +++ b/mod/workshop/version.php @@ -28,6 +28,6 @@ defined('MOODLE_INTERNAL') || die(); -$module->version = 2010070701; +$module->version = 2010070800; $module->requires = 2010070604; // Requires this Moodle version //$module->cron = 60; diff --git a/mod/workshop/view.php b/mod/workshop/view.php index 183161ed504..020a4572792 100644 --- a/mod/workshop/view.php +++ b/mod/workshop/view.php @@ -318,6 +318,20 @@ case workshop::PHASE_EVALUATION: echo $output->render($pagingbar); } } + if (has_capability('mod/workshop:overridegrades', $workshop->context)) { + print_collapsible_region_start('', 'workshop-viewlet-cleargrades', get_string('toolbox', 'workshop')); + echo $output->box_start('generalbox toolbox'); + // Clear aggregated grades + $url = new moodle_url($workshop->toolbox_url('clearaggregatedgrades'), array('confirmed' => false)); + $btn = new single_button($url, get_string('clearaggregatedgrades', 'workshop'), 'post'); + $btn->add_confirm_action(get_string('clearaggregatedgradesconfirm', 'workshop')); + $btn->class .= ' toolboxaction'; + echo $output->render($btn); + echo $output->help_icon('clearaggregatedgrades', 'workshop'); + + echo $output->box_end(); + print_collapsible_region_end(); + } if (has_capability('mod/workshop:submit', $PAGE->context)) { print_collapsible_region_start('', 'workshop-viewlet-ownsubmission', get_string('yoursubmission', 'workshop')); echo $output->box_start('generalbox ownsubmission');