From f6e8b31802041c50caa86d97b039ef448cb28ca3 Mon Sep 17 00:00:00 2001 From: David Mudrak Date: Mon, 4 Jan 2010 18:22:10 +0000 Subject: [PATCH] workshop: general cleanup Moving stuff from lib.php into static methods in localib.php. Removing things from workshop core that were implemented in a subplugin. Dropping stuff related to features not to be implemented in 2.0. --- .../en_utf8/workshopallocation_random.php | 2 + mod/workshop/allocation/random/lib.php | 18 ++ .../version.php => random/settings.php} | 15 +- .../allocation/random/settings_form.php | 15 +- mod/workshop/db/access.php | 12 -- mod/workshop/db/install.xml | 17 +- mod/workshop/form/accumulative/edit_form.php | 8 +- mod/workshop/form/comments/edit_form.php | 2 - mod/workshop/form/numerrors/edit_form.php | 7 +- mod/workshop/lang/en_utf8/workshop.php | 17 -- mod/workshop/lib.php | 160 ----------------- mod/workshop/locallib.php | 163 +++++++++++------- mod/workshop/mod_form.php | 48 ++---- mod/workshop/settings.php | 31 ++-- mod/workshop/simpletest/testlib.php | 49 ------ mod/workshop/submission.php | 3 - 16 files changed, 175 insertions(+), 392 deletions(-) rename mod/workshop/allocation/{manual/version.php => random/settings.php} (65%) delete mode 100644 mod/workshop/simpletest/testlib.php diff --git a/mod/workshop/allocation/random/lang/en_utf8/workshopallocation_random.php b/mod/workshop/allocation/random/lang/en_utf8/workshopallocation_random.php index b3f51486e2..a03600c7a4 100644 --- a/mod/workshop/allocation/random/lang/en_utf8/workshopallocation_random.php +++ b/mod/workshop/allocation/random/lang/en_utf8/workshopallocation_random.php @@ -31,9 +31,11 @@ $string['allocationdeallocategraded'] = 'Unable to deallocate already graded ass $string['allocationsettings'] = 'Allocation settings'; $string['assessmentdeleteddetail'] = 'Assessment deallocated: $a->reviewername is no longer reviewer of $a->authorname'; $string['assesswosubmission'] = 'Participants can assess without having submitted anything'; +$string['confignumofreviews'] = 'Default number of submissions to be randomly allocated'; $string['noallocationtoadd'] = 'No allocations to add'; $string['numofdeallocatedassessment'] = 'Deallocating $a assessment(s)'; $string['numofrandomlyallocatedsubmissions'] = 'Randomly allocating $a submissions'; +$string['numofreviews'] = 'Number of reviews'; $string['numofselfallocatedsubmissions'] = 'Self-allocating $a submission(s)'; $string['numperauthor'] = 'per submission'; $string['numperreviewer'] = 'per reviewer'; diff --git a/mod/workshop/allocation/random/lib.php b/mod/workshop/allocation/random/lib.php index 5150d2b18a..efea09f4c8 100644 --- a/mod/workshop/allocation/random/lib.php +++ b/mod/workshop/allocation/random/lib.php @@ -181,6 +181,24 @@ class workshop_random_allocator implements workshop_allocator { return $out; } + /** + * Return an array of possible numbers of reviews to be done + * + * Should contain numbers 1, 2, 3, ... 10 and possibly others up to a reasonable value + * + * @return array of integers + */ + public static function available_numofreviews_list() { + $options = array(); + $options[30] = 30; + $options[20] = 20; + $options[15] = 15; + for ($i = 10; $i >= 0; $i--) { + $options[$i] = $i; + } + return $options; + } + /** * Allocates submissions to their authors for review * diff --git a/mod/workshop/allocation/manual/version.php b/mod/workshop/allocation/random/settings.php similarity index 65% rename from mod/workshop/allocation/manual/version.php rename to mod/workshop/allocation/random/settings.php index 8eac2d681a..016997313a 100644 --- a/mod/workshop/allocation/manual/version.php +++ b/mod/workshop/allocation/random/settings.php @@ -16,17 +16,18 @@ // along with Moodle. If not, see . /** - * Defines the version of manual allocation subplugin + * The configuration variables for "Random allocation" subplugin * - * This code fragment is called by moodle_needs_upgrading() and - * /admin/index.php - * - * @package mod-workshop + * @package mod-workshopallocation-random * @copyright 2009 David Mudrak * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2009081300; -$plugin->requires = 2009080700; // Requires this Moodle version +require_once(dirname(__FILE__) . '/lib.php'); + +$settings->add(new admin_setting_configselect('workshopallocation_random/numofreviews', + get_string('numofreviews', 'workshopallocation_random'), + get_string('confignumofreviews', 'workshopallocation_random'), 5, + workshop_random_allocator::available_numofreviews_list())); diff --git a/mod/workshop/allocation/random/settings_form.php b/mod/workshop/allocation/random/settings_form.php index 59d6e2b6ce..72d48f1e6a 100644 --- a/mod/workshop/allocation/random/settings_form.php +++ b/mod/workshop/allocation/random/settings_form.php @@ -41,8 +41,9 @@ class workshop_random_allocator_form extends moodleform { * Definition of the setting form elements */ public function definition() { - $mform = $this->_form; - $workshop = $this->_customdata['workshop']; + $mform = $this->_form; + $workshop = $this->_customdata['workshop']; + $plugindefaults = get_config('workshopallocation_random'); $mform->addElement('header', 'settings', get_string('allocationsettings', 'workshopallocation_random')); @@ -60,18 +61,18 @@ class workshop_random_allocator_form extends moodleform { } $mform->addElement('static', 'groupmode', get_string('groupmode', 'group'), $grouplabel); - $options_numofreviewes = array(0=>0,1=>1, 2=>2, 3=>3, 4=>4); // todo $options_numper = array( workshop_random_allocator::USERTYPE_AUTHOR => get_string('numperauthor', 'workshopallocation_random'), workshop_random_allocator::USERTYPE_REVIEWER => get_string('numperreviewer', 'workshopallocation_random') ); $grpnumofreviews = array(); - $grpnumofreviews[] = $mform->createElement('select', 'numofreviews', '', $options_numofreviewes); - $mform->setDefault('numofreviews', 4); + $grpnumofreviews[] = $mform->createElement('select', 'numofreviews', '', + workshop_random_allocator::available_numofreviews_list()); + $mform->setDefault('numofreviews', $plugindefaults->numofreviews); $grpnumofreviews[] = $mform->createElement('select', 'numper', '', $options_numper); $mform->setDefault('numper', workshop_random_allocator::USERTYPE_AUTHOR); - $mform->addGroup($grpnumofreviews, 'grpnumofreviews', get_string('numofreviews', 'workshop'), array(' '), false); - + $mform->addGroup($grpnumofreviews, 'grpnumofreviews', get_string('numofreviews', 'workshopallocation_random'), + array(' '), false); $mform->addElement('checkbox', 'removecurrent', get_string('removecurrentallocations', 'workshopallocation_random')); $mform->setDefault('removecurrent', 0); diff --git a/mod/workshop/db/access.php b/mod/workshop/db/access.php index 5868564c7f..4cc47e2c6e 100644 --- a/mod/workshop/db/access.php +++ b/mod/workshop/db/access.php @@ -168,16 +168,4 @@ $mod_workshop_capabilities = array( ) ), - // Ability to see the given/calculated grades even before the author did not agree - // with the assessment comments yet - 'mod/workshop:viewgradesbeforeagreement' => array( - 'captype' => 'read', - 'contextlevel' => CONTEXT_MODULE, - 'legacy' => array( - 'teacher' => CAP_ALLOW, - 'editingteacher' => CAP_ALLOW, - 'admin' => CAP_ALLOW - ) - ), - ); diff --git a/mod/workshop/db/install.xml b/mod/workshop/db/install.xml index bc4f63e844..ea4bffa48a 100644 --- a/mod/workshop/db/install.xml +++ b/mod/workshop/db/install.xml @@ -1,5 +1,5 @@ - @@ -26,13 +26,9 @@ - - - - - - - + + + @@ -76,9 +72,8 @@ - - - + + diff --git a/mod/workshop/form/accumulative/edit_form.php b/mod/workshop/form/accumulative/edit_form.php index 41a55d686e..729c6d3e6e 100644 --- a/mod/workshop/form/accumulative/edit_form.php +++ b/mod/workshop/form/accumulative/edit_form.php @@ -52,19 +52,17 @@ class workshop_edit_accumulative_strategy_form extends workshop_edit_strategy_fo // value not to be overridden by submitted value $mform->setConstants(array('norepeats' => $norepeats)); - $weights = workshop_get_dimension_weights(); - for ($i = 0; $i < $norepeats; $i++) { $mform->addElement('header', 'dimension'.$i, get_string('dimensionnumber', 'workshopform_accumulative', $i+1)); $mform->addElement('hidden', 'dimensionid__idx_'.$i); $mform->addElement('editor', 'description__idx_'.$i.'_editor', - get_string('dimensiondescription', 'workshopform_accumulative'), '', $descriptionopts); + get_string('dimensiondescription', 'workshopform_accumulative'), '', $descriptionopts); // todo replace modgrade with an advanced element (usability issue discussed with Olli) $mform->addElement('modgrade', 'grade__idx_'.$i, - get_string('dimensionmaxgrade','workshopform_accumulative'), null, true); + get_string('dimensionmaxgrade','workshopform_accumulative'), null, true); $mform->setDefault('grade__idx_'.$i, 10); $mform->addElement('select', 'weight__idx_'.$i, - get_string('dimensionweight', 'workshopform_accumulative'), $weights); + get_string('dimensionweight', 'workshopform_accumulative'), workshop::available_dimension_weights_list()); $mform->setDefault('weight__idx_'.$i, 1); } diff --git a/mod/workshop/form/comments/edit_form.php b/mod/workshop/form/comments/edit_form.php index a8c7d0b18a..44397598f0 100644 --- a/mod/workshop/form/comments/edit_form.php +++ b/mod/workshop/form/comments/edit_form.php @@ -52,8 +52,6 @@ class workshop_edit_comments_strategy_form extends workshop_edit_strategy_form { // value not to be overridden by submitted value $mform->setConstants(array('norepeats' => $norepeats)); - $weights = workshop_get_dimension_weights(); - for ($i = 0; $i < $norepeats; $i++) { $mform->addElement('header', 'dimension'.$i, get_string('dimensionnumber', 'workshopform_comments', $i+1)); $mform->addElement('hidden', 'dimensionid__idx_'.$i); diff --git a/mod/workshop/form/numerrors/edit_form.php b/mod/workshop/form/numerrors/edit_form.php index 0fb2e9ad23..24199b9bc9 100644 --- a/mod/workshop/form/numerrors/edit_form.php +++ b/mod/workshop/form/numerrors/edit_form.php @@ -54,20 +54,19 @@ class workshop_edit_numerrors_strategy_form extends workshop_edit_strategy_form // value not to be overridden by submitted value $mform->setConstants(array('norepeats' => $norepeats)); - $weights = workshop_get_dimension_weights(); - for ($i = 0; $i < $norepeats; $i++) { $mform->addElement('header', 'dimension'.$i, get_string('dimensionnumber', 'workshopform_numerrors', $i+1)); $mform->addElement('hidden', 'dimensionid__idx_'.$i); // the id in workshop_forms $mform->addElement('editor', 'description__idx_'.$i.'_editor', - get_string('dimensiondescription', 'workshopform_numerrors'), '', $descriptionopts); + get_string('dimensiondescription', 'workshopform_numerrors'), '', $descriptionopts); $mform->addElement('text', 'grade0__idx_'.$i, get_string('grade0', 'workshopform_numerrors'), array('size'=>'15')); $mform->setDefault('grade0__idx_'.$i, $plugindefaults->grade0); $mform->setType('grade0__idx_'.$i, PARAM_TEXT); $mform->addElement('text', 'grade1__idx_'.$i, get_string('grade1', 'workshopform_numerrors'), array('size'=>'15')); $mform->setDefault('grade1__idx_'.$i, $plugindefaults->grade1); $mform->setType('grade1__idx_'.$i, PARAM_TEXT); - $mform->addElement('select', 'weight__idx_'.$i, get_string('dimensionweight', 'workshopform_numerrors'), $weights); + $mform->addElement('select', 'weight__idx_'.$i, + get_string('dimensionweight', 'workshopform_numerrors'), workshop::available_dimension_weights_list()); $mform->setDefault('weight__idx_'.$i, 1); } diff --git a/mod/workshop/lang/en_utf8/workshop.php b/mod/workshop/lang/en_utf8/workshop.php index 3c735c401c..9f71411f9d 100644 --- a/mod/workshop/lang/en_utf8/workshop.php +++ b/mod/workshop/lang/en_utf8/workshop.php @@ -37,8 +37,6 @@ $string[''] = ''; $string['accesscontrol'] = 'Access control'; $string['aggregategrades'] = 'Re-calculate grades'; $string['aggregation'] = 'Grades aggregation'; -$string['agreeassessments'] = 'Assessments must be agreed'; -$string['agreeassessmentsdesc'] = 'Authors may comment assessments of their work and agree/disagree with it'; $string['allocate'] = 'Allocate submissions'; $string['allocatedetails'] = 'expected: $a->expected
submitted: $a->submitted
to allocate: $a->allocate'; $string['allocationdone'] = 'Allocation done'; @@ -48,14 +46,12 @@ $string['alreadygraded'] = 'Already graded'; $string['areainstructauthors'] = 'Instructions for submitting'; $string['areasubmissionattachment'] = 'Submission attachments'; $string['areasubmissioncontent'] = 'Submission texts'; -$string['assessallexamples'] = 'Assess all examples'; $string['assess'] = 'Assess'; $string['assessedsubmission'] = 'Assessed submission'; $string['assessingsubmission'] = 'Assessing submission'; $string['assessmentbyknown'] = 'Assessment by $a'; $string['assessmentbyunknown'] = 'Assessment'; $string['assessmentbyyourself'] = 'Assessment by yourself'; -$string['assessmentcomps'] = 'Required level of assessments similarity'; $string['assessmentdeleted'] = 'Assessment deallocated'; $string['assessmentend'] = 'End of assessment phase'; $string['assessmentform'] = 'Assessment form'; @@ -67,20 +63,11 @@ $string['backtoeditform'] = 'Back to editing form'; $string['byfullname'] = 'by url}\">{$a->name}'; $string['calculatetotalgrades'] = 'Calculate total grades'; $string['calculatetotalgradesdetails'] = 'expected: $a->expected
known: $a->known'; -$string['comparisonhigh'] = 'High'; -$string['comparisonlow'] = 'Low'; -$string['comparisonnormal'] = 'Normal'; -$string['comparisonveryhigh'] = 'Very high'; -$string['comparisonverylow'] = 'Very low'; -$string['configanonymity'] = 'Default anonymity mode in workshops'; -$string['configassessmentcomps'] = 'Default value of the setting that influences the calculation of the grade for assessment.'; $string['configexamplesmode'] = 'Default mode of examples assessment in workshops'; $string['configgradedecimals'] = 'Default number of digits that should be shown after the decimal point when displaying grades.'; $string['configgrade'] = 'Default maximum grade for submission in workshops'; $string['configgradinggrade'] = 'Default maximum grade for assessment in workshops'; $string['configmaxbytes'] = 'Default maximum submission file size for all workshops on the site (subject to course limits and other local settings)'; -$string['confignexassessments'] = 'Default number of examples to be reviewed by a user in the example assessment phase'; -$string['confignsassessments'] = 'Default number of allocated submissions to be reviewed by a user in the assessment phase'; $string['configstrategy'] = 'Default grading strategy for workshops'; $string['editassessmentform'] = 'Edit assessment form'; $string['editassessmentformstrategy'] = 'Edit assessment form ($a)'; @@ -124,7 +111,6 @@ $string['modulenameplural'] = 'Workshops'; $string['modulename'] = 'Workshop'; $string['mysubmission'] = 'My submission'; $string['nattachments'] = 'Maximum number of submission attachments'; -$string['nexassessments'] = 'Number of required assessments of examples'; $string['nogradeyet'] = 'No grade yet'; $string['nosubmissionfound'] = 'No submission found for this user'; $string['nosubmissions'] = 'No submissions yet in this workshop'; @@ -132,9 +118,7 @@ $string['nothingtoreview'] = 'Nothing to review'; $string['notoverridden'] = 'Not overriden'; $string['noworkshops'] = 'There are no workshops in this course'; $string['noyoursubmission'] = 'You have not submitted your work yet'; -$string['nsassessments'] = 'Number of required assessments of other users\' work'; $string['nullgrade'] = '-'; -$string['numofreviews'] = 'Number of reviews'; $string['participant'] = 'Participant'; $string['participantrevierof'] = 'Participant is reviewer of'; $string['participantreviewedby'] = 'Participant is reviewed by'; @@ -180,7 +164,6 @@ $string['taskinstructauthors'] = 'Provide instructions for submitting'; $string['taskinstructreviewers'] = 'Provide instructions for assessing'; $string['taskintro'] = 'Set the workshop introduction'; $string['tasksubmit'] = 'Submit your work'; -$string['teacherweight'] = 'Weight of the teacher\'s assessments'; $string['totalgradeof'] = 'Total grade (of $a)'; $string['totalgradesmissing'] = 'Unable to calculate some total grades - they will have to be set manually in Gradebook'; $string['totalgrade'] = 'Total grade'; diff --git a/mod/workshop/lib.php b/mod/workshop/lib.php index b4292a638b..a07946461e 100644 --- a/mod/workshop/lib.php +++ b/mod/workshop/lib.php @@ -20,9 +20,6 @@ * * All the core Moodle functions, neeeded to allow the module to work * integrated in Moodle should be placed here. - * All the workshop specific functions, needed to implement all the module - * logic, should go to locallib.php. This will help to save some memory when - * Moodle is performing actions across all modules. * * @package mod-workshop * @copyright 2009 David Mudrak @@ -31,22 +28,6 @@ defined('MOODLE_INTERNAL') || die(); -/** - * The internal codes of the example assessment modes - */ -define('WORKSHOP_EXAMPLES_VOLUNTARY', 0); -define('WORKSHOP_EXAMPLES_BEFORE_SUBMISSION', 1); -define('WORKSHOP_EXAMPLES_BEFORE_ASSESSMENT', 2); - -/** - * The internal codes of the required level of assessment similarity - */ -define('WORKSHOP_COMPARISON_VERYLOW', 0); /* f = 1.00 */ -define('WORKSHOP_COMPARISON_LOW', 1); /* f = 1.67 */ -define('WORKSHOP_COMPARISON_NORMAL', 2); /* f = 2.50 */ -define('WORKSHOP_COMPARISON_HIGH', 3); /* f = 3.00 */ -define('WORKSHOP_COMPARISON_VERYHIGH', 4); /* f = 5.00 */ - /** * Returns the information if the module supports a feature * @@ -623,144 +604,3 @@ function workshop_extend_settings_navigation(settings_navigation $settingsnav, s $workshopnode->add(get_string('allocate', 'workshop'), $url, settings_navigation::TYPE_SETTING); } } - - - -//////////////////////////////////////////////////////////////////////////////// -// Other functions needed by Moodle core follows. They can't be put into // -// locallib.php because they are used by some core scripts (like modedit.php) // -// where locallib.php is not included. // -//////////////////////////////////////////////////////////////////////////////// - -/** - * Return an array of numeric values that can be used as maximum grades - * - * Used at several places where maximum grade for submission and grade for - * assessment are defined via a HTML select form element. By default it returns - * an array 0, 1, 2, ..., 98, 99, 100. - * - * @return array Array of integers - */ -function workshop_get_maxgrades() { - $grades = array(); - for ($i=100; $i>=0; $i--) { - $grades[$i] = $i; - } - return $grades; -} - -/** - * Return an array of possible numbers of assessments to be done - * - * Should always contain numbers 1, 2, 3, ... 10 and possibly others up to a reasonable value - * - * @return array Array of integers - */ -function workshop_get_numbers_of_assessments() { - $options = array(); - $options[30] = 30; - $options[20] = 20; - $options[15] = 15; - for ($i=10; $i>0; $i--) { - $options[$i] = $i; - } - return $options; -} - -/** - * Return an array of possible values for weight of teacher assessment - * - * @return array Array of integers 0, 1, 2, ..., 10 - */ -function workshop_get_teacher_weights() { - $weights = array(); - for ($i=10; $i>=0; $i--) { - $weights[$i] = $i; - } - return $weights; -} - -/** - * Return an array of possible values of assessment dimension weight - * - * @return array Array of integers 0, 1, 2, ..., 16 - */ -function workshop_get_dimension_weights() { - $weights = array(); - for ($i=16; $i>=0; $i--) { - $weights[$i] = $i; - } - return $weights; -} - -/** - * Return an array of the localized grading strategy names - * - * @todo remove this function from lib.php - * $return array Array ['string' => 'string'] - */ -function workshop_get_strategies() { - $installed = get_plugin_list('workshopform'); - $forms = array(); - foreach ($installed as $strategy => $strategypath) { - if (file_exists($strategypath . '/lib.php')) { - $forms[$strategy] = get_string('pluginname', 'workshopform_' . $strategy); - } - } - return $forms; -} - -/** - * Return an array of available example assessment modes - * - * @return array Array 'mode DB code'=>'mode name' - */ -function workshop_get_example_modes() { - $modes = array(); - $modes[WORKSHOP_EXAMPLES_VOLUNTARY] = get_string('examplesvoluntary', 'workshop'); - $modes[WORKSHOP_EXAMPLES_BEFORE_SUBMISSION] = get_string('examplesbeforesubmission', 'workshop'); - $modes[WORKSHOP_EXAMPLES_BEFORE_ASSESSMENT] = get_string('examplesbeforeassessment', 'workshop'); - - return $modes; -} - -/** - * Return array of assessment comparison levels - * - * The assessment comparison level influence how the grade for assessment is calculated. - * Each object in the returned array provides information about the name of the level - * and the value of the factor to be used in the calculation. - * The structure of the returned array is - * array[code int] of stdClass ( - * ->name string, - * ->value number, - * ) - * where code if the integer code that is actually stored in the database. - * - * @return array Array of objects - */ -function workshop_get_comparison_levels() { - $levels = array(); - - $levels[WORKSHOP_COMPARISON_VERYHIGH] = new stdClass(); - $levels[WORKSHOP_COMPARISON_VERYHIGH]->name = get_string('comparisonveryhigh', 'workshop'); - $levels[WORKSHOP_COMPARISON_VERYHIGH]->value = 5.00; - - $levels[WORKSHOP_COMPARISON_HIGH] = new stdClass(); - $levels[WORKSHOP_COMPARISON_HIGH]->name = get_string('comparisonhigh', 'workshop'); - $levels[WORKSHOP_COMPARISON_HIGH]->value = 3.00; - - $levels[WORKSHOP_COMPARISON_NORMAL] = new stdClass(); - $levels[WORKSHOP_COMPARISON_NORMAL]->name = get_string('comparisonnormal', 'workshop'); - $levels[WORKSHOP_COMPARISON_NORMAL]->value = 2.50; - - $levels[WORKSHOP_COMPARISON_LOW] = new stdClass(); - $levels[WORKSHOP_COMPARISON_LOW]->name = get_string('comparisonlow', 'workshop'); - $levels[WORKSHOP_COMPARISON_LOW]->value = 1.67; - - $levels[WORKSHOP_COMPARISON_VERYLOW] = new stdClass(); - $levels[WORKSHOP_COMPARISON_VERYLOW]->name = get_string('comparisonverylow', 'workshop'); - $levels[WORKSHOP_COMPARISON_VERYLOW]->value = 1.00; - - return $levels; -} diff --git a/mod/workshop/locallib.php b/mod/workshop/locallib.php index e8e4597f0a..72e20125a4 100644 --- a/mod/workshop/locallib.php +++ b/mod/workshop/locallib.php @@ -43,15 +43,20 @@ require_once($CFG->libdir . '/gradelib.php'); // we use some rounding and comp class workshop { /** return statuses of {@link add_allocation} to be passed to a workshop renderer method */ - const ALLOCATION_EXISTS = -1; - const ALLOCATION_ERROR = -2; + const ALLOCATION_EXISTS = -1; + const ALLOCATION_ERROR = -2; /** the internal code of the workshop phases as are stored in the database */ - const PHASE_SETUP = 10; - const PHASE_SUBMISSION = 20; - const PHASE_ASSESSMENT = 30; - const PHASE_EVALUATION = 40; - const PHASE_CLOSED = 50; + const PHASE_SETUP = 10; + const PHASE_SUBMISSION = 20; + const PHASE_ASSESSMENT = 30; + const PHASE_EVALUATION = 40; + const PHASE_CLOSED = 50; + + /** the internal code of the examples modes as are stored in the database */ + const EXAMPLES_VOLUNTARY = 0; + const EXAMPLES_BEFORE_SUBMISSION = 1; + const EXAMPLES_BEFORE_ASSESSMENT = 2; /** @var stdClass course module record */ public $cm = null; @@ -59,6 +64,9 @@ class workshop { /** @var stdClass course record */ public $course = null; + /** @var stdClass context object */ + public $context = null; + /** * @var workshop_strategy grading strategy instance * Do not use directly, get the instance using {@link workshop::grading_strategy_instance()} @@ -150,6 +158,83 @@ class workshop { return $total * $percent / 100; } + /** + * Returns an array of numeric values that can be used as maximum grades + * + * @return array Array of integers + */ + public static function available_maxgrades_list() { + $grades = array(); + for ($i=100; $i>=0; $i--) { + $grades[$i] = $i; + } + return $grades; + } + + /** + * Returns the localized list of supported examples modes + * + * @return array + */ + public static function available_example_modes_list() { + $options = array(); + $options[self::EXAMPLES_VOLUNTARY] = get_string('examplesvoluntary', 'workshop'); + $options[self::EXAMPLES_BEFORE_SUBMISSION] = get_string('examplesbeforesubmission', 'workshop'); + $options[self::EXAMPLES_BEFORE_ASSESSMENT] = get_string('examplesbeforeassessment', 'workshop'); + return $options; + } + + /** + * Returns the list of available grading strategy methods + * + * @return array ['string' => 'string'] + */ + public static function available_strategies_list() { + $installed = get_plugin_list('workshopform'); + $forms = array(); + foreach ($installed as $strategy => $strategypath) { + if (file_exists($strategypath . '/lib.php')) { + $forms[$strategy] = get_string('pluginname', 'workshopform_' . $strategy); + } + } + return $forms; + } + + /** + * Return an array of possible values of assessment dimension weight + * + * @return array of integers 0, 1, 2, ..., 16 + */ + public static function available_dimension_weights_list() { + $weights = array(); + for ($i=16; $i>=0; $i--) { + $weights[$i] = $i; + } + return $weights; + } + + /** + * Helper function returning the greatest common divisor + * + * @param int $a + * @param int $b + * @return int + */ + public static function gcd($a, $b) { + return ($b == 0) ? ($a):(self::gcd($b, $a % $b)); + } + + /** + * Helper function returning the least common multiple + * + * @param int $a + * @param int $b + * @return int + */ + public static function lcm($a, $b) { + return ($a / self::gcd($a,$b)) * $b; + } + //////////////////////////////////////////////////////////////////////////////// // Workshop API // //////////////////////////////////////////////////////////////////////////////// @@ -348,7 +433,7 @@ class workshop { public function get_all_assessments() { global $DB; - $sql = 'SELECT a.id, a.submissionid, a.reviewerid, a.timecreated, a.timemodified, a.timeagreed, + $sql = 'SELECT a.id, a.submissionid, a.reviewerid, a.timecreated, a.timemodified, a.grade, a.gradinggrade, a.gradinggradeover, a.gradinggradeoverby, reviewer.id AS reviewerid,reviewer.firstname AS reviewerfirstname,reviewer.lastname as reviewerlastname, s.title, @@ -639,24 +724,14 @@ class workshop { * Can the given grades be displayed to the authors? * * Grades are not displayed if {@link self::assessments_available()} return false. The returned - * value may be true (if yes, display grades), false (no, hide grades yet) or null (only - * display grades if the assessment has been agreed by the author). + * value may be true (if yes, display grades) or false (no, hide grades yet) * - * @return bool|null + * @return bool */ public function grades_available() { return true; } - /** - * Returns the localized name of the grading strategy method to be displayed to the users - * - * @return string - */ - public function strategy_name() { - return get_string('pluginname', 'workshopform_' . $this->strategy); - } - /** * Prepare an individual workshop plan for the given user. * @@ -691,7 +766,7 @@ class workshop { $task = new stdClass(); $task->title = get_string('editassessmentform', 'workshop'); $task->link = $this->editform_url(); - if ($this->assessment_form_ready()) { + if ($this->grading_strategy_instance()->form_ready()) { $task->completed = true; } elseif ($this->phase > self::PHASE_SETUP) { $task->completed = false; @@ -906,15 +981,6 @@ class workshop { return $phases; } - /** - * Has the assessment form been defined? - * - * @return bool - */ - public function assessment_form_ready() { - return $this->grading_strategy_instance()->form_ready(); - } - /** * Switch to a new workshop phase * @@ -930,6 +996,12 @@ class workshop { if (!isset($known[$newphase])) { return false; } + + if (self::PHASE_CLOSED == $newphase) { + // push the total grades into the gradebook + + } + $DB->set_field('workshop', 'phase', $newphase, array('id' => $this->id)); return true; } @@ -1377,10 +1449,9 @@ class workshop { } /** - * TODO: short description. + * Returns the mform the teachers use to put a feedback for the reviewer * - * @param array $actionurl - * @return TODO + * @return workshop_feedbackreviewer_form */ public function get_feedbackreviewer_form(moodle_url $actionurl, stdClass $assessment, $editable=true) { global $CFG; @@ -1404,32 +1475,6 @@ class workshop { 'post', '', null, $editable); } - //////////////////////////////////////////////////////////////////////////// - // Helper methods // - //////////////////////////////////////////////////////////////////////////// - - /** - * Helper function returning the greatest common divisor - * - * @param int $a - * @param int $b - * @return int - */ - public static function gcd($a, $b) { - return ($b == 0) ? ($a):(self::gcd($b, $a % $b)); - } - - /** - * Helper function returning the least common multiple - * - * @param int $a - * @param int $b - * @return int - */ - public static function lcm($a, $b) { - return ($a / self::gcd($a,$b)) * $b; - } - //////////////////////////////////////////////////////////////////////////////// // Internal methods (implementation details) // //////////////////////////////////////////////////////////////////////////////// diff --git a/mod/workshop/mod_form.php b/mod/workshop/mod_form.php index 5e232a7b2d..ac4432a78c 100644 --- a/mod/workshop/mod_form.php +++ b/mod/workshop/mod_form.php @@ -85,7 +85,7 @@ class mod_workshop_mod_form extends moodleform_mod { // Grading settings ----------------------------------------------------------- $mform->addElement('header', 'gradingsettings', get_string('gradingsettings', 'workshop')); - $grades = workshop_get_maxgrades(); + $grades = workshop::available_maxgrades_list(); $label = get_string('submissiongrade', 'workshop'); $mform->addElement('select', 'grade', $label, $grades); @@ -98,7 +98,7 @@ class mod_workshop_mod_form extends moodleform_mod { $mform->setHelpButton('gradinggrade', array('gradinggrade', $label, 'workshop')); $label = get_string('strategy', 'workshop'); - $mform->addElement('select', 'strategy', $label, workshop_get_strategies()); + $mform->addElement('select', 'strategy', $label, workshop::available_strategies_list()); $mform->setDefault('strategy', $workshopconfig->strategy); $mform->setHelpButton('strategy', array('strategy', $label, 'workshop')); @@ -128,17 +128,18 @@ class mod_workshop_mod_form extends moodleform_mod { $mform->setDefault('nattachments', 1); $mform->setHelpButton('nattachments', array('nattachments', $label, 'workshop')); - $label = get_string('latesubmissions', 'workshop'); - $text = get_string('latesubmissionsdesc', 'workshop'); - $mform->addElement('advcheckbox', 'latesubmissions', $label, $text); - $mform->setHelpButton('latesubmissions', array('latesubmissions', $label, 'workshop')); - $options = get_max_upload_sizes($CFG->maxbytes, $COURSE->maxbytes); $options[0] = get_string('courseuploadlimit') . ' ('.display_size($COURSE->maxbytes).')'; $mform->addElement('select', 'maxbytes', get_string('maximumsize', 'assignment'), $options); $mform->setDefault('maxbytes', $workshopconfig->maxbytes); $mform->setHelpButton('maxbytes', array('maxbytes', $label, 'workshop')); + $label = get_string('latesubmissions', 'workshop'); + $text = get_string('latesubmissionsdesc', 'workshop'); + $mform->addElement('advcheckbox', 'latesubmissions', $label, $text); + $mform->setHelpButton('latesubmissions', array('latesubmissions', $label, 'workshop')); + $mform->setAdvanced('latesubmissions'); + // Assessment settings -------------------------------------------------------- $mform->addElement('header', 'assessmentsettings', get_string('assessmentsettings', 'workshop')); @@ -146,43 +147,14 @@ class mod_workshop_mod_form extends moodleform_mod { $mform->addElement('editor', 'instructreviewerseditor', $label, null, workshop::instruction_editors_options($this->context)); - $label = get_string('nexassessments', 'workshop'); - $options = workshop_get_numbers_of_assessments(); - $options[0] = get_string('assessallexamples', 'workshop'); - $mform->addElement('select', 'nexassessments', $label, $options); - $mform->setDefault('nexassessments', $workshopconfig->nexassessments); - $mform->setHelpButton('nexassessments', array('nexassessments', $label, 'workshop')); - $mform->disabledIf('nexassessments', 'useexamples'); - $label = get_string('examplesmode', 'workshop'); - $options = workshop_get_example_modes(); + $options = workshop::available_example_modes_list(); $mform->addElement('select', 'examplesmode', $label, $options); $mform->setDefault('examplesmode', $workshopconfig->examplesmode); $mform->setHelpButton('examplesmode', array('examplesmode', $label, 'workshop')); - $mform->disabledIf('nexassessments', 'useexamples'); + $mform->disabledIf('examplesmode', 'useexamples'); $mform->setAdvanced('examplesmode'); - $label = get_string('teacherweight', 'workshop'); - $options = workshop_get_teacher_weights(); - $mform->addElement('select', 'teacherweight', $label, $options); - $mform->setDefault('teacherweight', 1); - $mform->setHelpButton('teacherweight', array('teacherweight', $label, 'workshop')); - - $label = get_string('agreeassessments', 'workshop'); - $text = get_string('agreeassessmentsdesc', 'workshop'); - $mform->addElement('advcheckbox', 'agreeassessments', $label, $text); - $mform->setHelpButton('agreeassessments', array('agreeassessments', $label, 'workshop')); - $mform->setAdvanced('agreeassessments'); - - $label = get_string('assessmentcomps', 'workshop'); - $levels = array(); - foreach (workshop_get_comparison_levels() as $code => $level) { - $levels[$code] = $level->name; - } - $mform->addElement('select', 'assessmentcomps', $label, $levels); - $mform->setDefault('assessmentcomps', $workshopconfig->assessmentcomps); - $mform->setHelpButton('assessmentcomps', array('assessmentcomps', $label, 'workshop')); - // Access control ------------------------------------------------------------- $mform->addElement('header', 'accesscontrol', get_string('accesscontrol', 'workshop')); diff --git a/mod/workshop/settings.php b/mod/workshop/settings.php index c36bbb9f30..fe435ac82a 100644 --- a/mod/workshop/settings.php +++ b/mod/workshop/settings.php @@ -28,8 +28,9 @@ defined('MOODLE_INTERNAL') || die(); require_once($CFG->dirroot.'/mod/workshop/lib.php'); +require_once($CFG->dirroot.'/mod/workshop/locallib.php'); -$grades = workshop_get_maxgrades(); +$grades = workshop::available_maxgrades_list(); $settings->add(new admin_setting_configselect('workshop/grade', get_string('submissiongrade', 'workshop'), get_string('configgrade', 'workshop'), 80, $grades)); @@ -50,27 +51,21 @@ $settings->add(new admin_setting_configselect('workshop/maxbytes', get_string('m get_string('configmaxbytes', 'workshop'), 0, $options)); $settings->add(new admin_setting_configselect('workshop/strategy', get_string('strategy', 'workshop'), - get_string('configstrategy', 'workshop'), 'accumulative', workshop_get_strategies())); + get_string('configstrategy', 'workshop'), 'accumulative', workshop::available_strategies_list())); -$options = workshop_get_numbers_of_assessments(); -$settings->add(new admin_setting_configselect('workshop/nsassessments', get_string('nsassessments', 'workshop'), - get_string('confignsassessments', 'workshop'), 3, $options)); - -$options = workshop_get_numbers_of_assessments(); -$options[0] = get_string('assessallexamples', 'workshop'); -$settings->add(new admin_setting_configselect('workshop/nexassessments', get_string('nexassessments', 'workshop'), - get_string('confignexassessments', 'workshop'), 0, $options)); - -$options = workshop_get_example_modes(); +$options = workshop::available_example_modes_list(); $settings->add(new admin_setting_configselect('workshop/examplesmode', get_string('examplesmode', 'workshop'), - get_string('configexamplesmode', 'workshop'), WORKSHOP_EXAMPLES_VOLUNTARY, $options)); + get_string('configexamplesmode', 'workshop'), workshop::EXAMPLES_VOLUNTARY, $options)); -$levels = array(); -foreach (workshop_get_comparison_levels() as $code => $level) { - $levels[$code] = $level->name; +// include the settings of allocation subplugins +$allocators = get_plugin_list('workshopallocation'); +foreach ($allocators as $allocator => $path) { + if (file_exists($settingsfile = $path . '/settings.php')) { + $settings->add(new admin_setting_heading('workshopallocationsetting'.$allocator, + get_string('allocation', 'workshop') . ' - ' . get_string('pluginname', 'workshopallocation_' . $allocator), '')); + include($settingsfile); + } } -$settings->add(new admin_setting_configselect('workshop/assessmentcomps', get_string('assessmentcomps', 'workshop'), - get_string('configassessmentcomps', 'workshop'), WORKSHOP_COMPARISON_NORMAL, $levels)); // include the settings of grading strategy subplugins $strategies = get_plugin_list('workshopform'); diff --git a/mod/workshop/simpletest/testlib.php b/mod/workshop/simpletest/testlib.php deleted file mode 100644 index 6ac80f0399..0000000000 --- a/mod/workshop/simpletest/testlib.php +++ /dev/null @@ -1,49 +0,0 @@ -. - -/** - * Unit tests for (some of) mod/workshop/lib.php - * - * @package mod-workshop - * @copyright 2009 David Mudrak - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); - -// Make sure the code being tested is accessible. -require_once($CFG->dirroot . '/mod/workshop/lib.php'); // Include the code to test - -/** - * Test cases for the functions in lib.php - */ -class workshop_lib_test extends UnitTestCase { - - function test_workshop_get_maxgrades() { - $this->assertIsA(workshop_get_maxgrades(), 'Array'); - $this->assertTrue(workshop_get_maxgrades()); - $values_are_integers = True; - foreach(workshop_get_maxgrades() as $key => $val) { - if (!is_int($val)) { - $values_are_integers = false; - break; - } - } - $this->assertTrue($values_are_integers, 'Array values must be integers'); - } - -} diff --git a/mod/workshop/submission.php b/mod/workshop/submission.php index 0e11cd5b21..a071624077 100644 --- a/mod/workshop/submission.php +++ b/mod/workshop/submission.php @@ -167,9 +167,6 @@ if ($isreviewer) { $canviewgrades = true; // reviewers can always see the grades they gave even they are not available yet } elseif ($ownsubmission or $canviewallassessments) { $canviewgrades = $workshop->grades_available(); // bool|null, see the function phpdoc - if (!$canviewgrades and has_capability('mod/workshop:viewgradesbeforeagreement', $PAGE->context)) { - $canviewgrades = true; - } } if ($isreviewer) { -- 2.39.5