diff --git a/mod/workshop/allocation/random/lib.php b/mod/workshop/allocation/random/lib.php index 31c473c0349..5f1617b3527 100644 --- a/mod/workshop/allocation/random/lib.php +++ b/mod/workshop/allocation/random/lib.php @@ -256,7 +256,7 @@ class workshop_random_allocator implements workshop_allocator { throw new moodle_exception('unabletoallocateauthorwithoutsubmission', 'workshop'); } $submission = $submissions[$authorid]; - $status = $this->workshop->add_allocation($submission, $reviewerid, true); + $status = $this->workshop->add_allocation($submission, $reviewerid, 1, true); // todo configurable weight? if (workshop::ALLOCATION_EXISTS == $status) { debugging('newallocations array contains existing allocation, this should not happen'); } diff --git a/mod/workshop/exsubmission.php b/mod/workshop/exsubmission.php index 169d68c8c7d..667d1f55b3e 100644 --- a/mod/workshop/exsubmission.php +++ b/mod/workshop/exsubmission.php @@ -78,7 +78,7 @@ if ($id and $assess and $canmanage) { // such assessment require_sesskey(); if (!$refasid) { - $refasid = $workshop->add_allocation($example, $USER->id, false, 1); + $refasid = $workshop->add_allocation($example, $USER->id, 1); } redirect($workshop->exassess_url($refasid)); } @@ -89,7 +89,7 @@ if ($id and $assess and $canassess) { $asid = $DB->get_field('workshop_assessments', 'id', array('submissionid' => $example->id, 'weight' => 0, 'reviewerid' => $USER->id)); if (!$asid) { - $asid = $workshop->add_allocation($example, $USER->id, false, 0); + $asid = $workshop->add_allocation($example, $USER->id, 0); } redirect($workshop->exassess_url($asid)); } diff --git a/mod/workshop/locallib.php b/mod/workshop/locallib.php index 2cba4b435bd..7ed5f8e7cda 100644 --- a/mod/workshop/locallib.php +++ b/mod/workshop/locallib.php @@ -673,17 +673,25 @@ class workshop { * * @param stdclass $submission Submission object with at least id property * @param int $reviewerid User ID - * @param bool $bulk repeated inserts into DB expected * @param int $weight of the new assessment, from 0 to 16 + * @param bool $bulk repeated inserts into DB expected * @return int ID of the new assessment or an error code */ - public function add_allocation(stdclass $submission, $reviewerid, $bulk=false, $weight=1) { + public function add_allocation(stdclass $submission, $reviewerid, $weight=1, $bulk=false) { global $DB; if ($DB->record_exists('workshop_assessments', array('submissionid' => $submission->id, 'reviewerid' => $reviewerid))) { return self::ALLOCATION_EXISTS; } + $weight = (int)$weight; + if ($weight < 0) { + $weight = 0; + } + if ($weight > 16) { + $weight = 16; + } + $now = time(); $assessment = new stdclass(); $assessment->submissionid = $submission->id; diff --git a/mod/workshop/view.php b/mod/workshop/view.php index 14c7e4a32aa..5e6e3895e2b 100644 --- a/mod/workshop/view.php +++ b/mod/workshop/view.php @@ -112,7 +112,7 @@ case workshop::PHASE_SUBMISSION: // make sure the current user has all examples allocated foreach ($examples as $exampleid => $example) { if (is_null($example->assessmentid)) { - $examples[$exampleid]->assessmentid = $workshop->add_allocation($example, $USER->id, false, 0); + $examples[$exampleid]->assessmentid = $workshop->add_allocation($example, $USER->id, 0); } if (is_null($example->grade)) { $todo++;