}
// check that all required examples have been assessed by the user
-if ($assessmenteditable and $workshop->useexamples and $workshop->examplesmode == workshop::EXAMPLES_BEFORE_ASSESSMENT
- and !has_capability('mod/workshop:manageexamples', $workshop->context)) {
- // the reviewer must have submitted their own submission
- $reviewersubmission = $workshop->get_submission_by_author($assessment->reviewerid);
- $output = $PAGE->get_renderer('mod_workshop');
- if (!$reviewersubmission) {
- // no money, no love
- $assessmenteditable = false;
+if ($assessmenteditable) {
+
+ list($assessed, $notice) = $workshop->check_examples_assessed_before_assessment($assessment->reviewerid);
+ if (!$assessed) {
echo $output->header();
echo $output->heading(format_string($workshop->name));
- notice(get_string('exampleneedsubmission', 'workshop'), new moodle_url('/mod/workshop/view.php', array('id' => $cm->id)));
+ notice(get_string($notice, 'workshop'), new moodle_url('/mod/workshop/view.php', array('id' => $cm->id)));
echo $output->footer();
exit;
- } else {
- $examples = $workshop->get_examples_for_reviewer($assessment->reviewerid);
- foreach ($examples as $exampleid => $example) {
- if (is_null($example->grade)) {
- $assessmenteditable = false;
- echo $output->header();
- echo $output->heading(format_string($workshop->name));
- notice(get_string('exampleneedassessed', 'workshop'), new moodle_url('/mod/workshop/view.php', array('id' => $cm->id)));
- echo $output->footer();
- exit;
- }
- }
}
}
if (is_null($result['assessingexamplesallowed'])) {
$result['assessingexamplesallowed'] = false;
}
- $result['examplesassessed'] = $workshop->check_examples_assessed($USER->id);
+ $result['examplesassessedbeforesubmission'] = $workshop->check_examples_assessed_before_submission($USER->id);
+ list($result['examplesassessedbeforeassessment'], $code) = $workshop->check_examples_assessed_before_assessment($USER->id);
$result['warnings'] = array();
return $result;
'Is the user allowed to create/edit his assessments?'),
'assessingexamplesallowed' => new external_value(PARAM_BOOL,
'Are reviewers allowed to create/edit their assessments of the example submissions?.'),
- 'examplesassessed' => new external_value(PARAM_BOOL,
- 'Whether the given user has assessed all his required examples (always true if there are no examples to assess).'),
+ 'examplesassessedbeforesubmission' => new external_value(PARAM_BOOL,
+ 'Whether the given user has assessed all his required examples before submission
+ (always true if there are not examples to assess or not configured to check before submission).'),
+ 'examplesassessedbeforeassessment' => new external_value(PARAM_BOOL,
+ 'Whether the given user has assessed all his required examples before assessment
+ (always true if there are not examples to assessor not configured to check before assessment).'),
'warnings' => new external_warnings()
);
// Check if we can submit now.
$canaddsubmission = $workshop->creating_submission_allowed($USER->id);
- $canaddsubmission = $canaddsubmission && $workshop->check_examples_assessed($USER->id);
+ $canaddsubmission = $canaddsubmission && $workshop->check_examples_assessed_before_submission($USER->id);
if (!$canaddsubmission) {
throw new moodle_exception('nopermissions', 'error', '', 'add submission');
}
// Check if we can update the submission.
$canupdatesubmission = $submission->authorid == $USER->id;
$canupdatesubmission = $canupdatesubmission && $workshop->modifying_submission_allowed($USER->id);
- $canupdatesubmission = $canupdatesubmission && $workshop->check_examples_assessed($USER->id);
+ $canupdatesubmission = $canupdatesubmission && $workshop->check_examples_assessed_before_submission($USER->id);
if (!$canupdatesubmission) {
throw new moodle_exception('nopermissions', 'error', '', 'update submission');
}
}
/**
- * Check whether the given user has assessed all his required examples.
+ * Check whether the given user has assessed all his required examples before submission.
*
* @param int $userid the user to check
* @return bool false if there are examples missing assessment, true otherwise.
* @since Moodle 3.4
*/
- public function check_examples_assessed($userid) {
+ public function check_examples_assessed_before_submission($userid) {
if ($this->useexamples and $this->examplesmode == self::EXAMPLES_BEFORE_SUBMISSION
and !has_capability('mod/workshop:manageexamples', $this->context)) {
return true;
}
+ /**
+ * Check that all required examples have been assessed by the given user.
+ *
+ * @param stdClass $userid the user (reviewer) to check
+ * @return mixed bool|state false and notice code if there are examples missing assessment, true otherwise.
+ * @since Moodle 3.4
+ */
+ public function check_examples_assessed_before_assessment($userid) {
+
+ if ($this->useexamples and $this->examplesmode == self::EXAMPLES_BEFORE_ASSESSMENT
+ and !has_capability('mod/workshop:manageexamples', $this->context)) {
+
+ // The reviewer must have submitted their own submission.
+ $reviewersubmission = $this->get_submission_by_author($userid);
+ if (!$reviewersubmission) {
+ // No money, no love.
+ return array(false, 'exampleneedsubmission');
+ } else {
+ $examples = $this->get_examples_for_reviewer($userid);
+ foreach ($examples as $exampleid => $example) {
+ if (is_null($example->grade)) {
+ return array(false, 'exampleneedassessed');
+ }
+ }
+ }
+ }
+ return array(true, null);
+ }
+
/**
* Trigger module viewed event and set the module viewed for completion.
*
$canviewall = $canviewall && $workshop->check_group_membership($submission->authorid);
-$editable = $editable && $workshop->check_examples_assessed($USER->id);
+$editable = ($editable && $workshop->check_examples_assessed_before_submission($USER->id));
$edit = ($editable and $edit);
if (!$candeleteall and $ownsubmission and $editable) {
$this->assertFalse($result['modifyingsubmissionallowed']);
$this->assertFalse($result['assessingallowed']);
$this->assertFalse($result['assessingexamplesallowed']);
- $this->assertTrue($result['examplesassessed']);
+ $this->assertTrue($result['examplesassessedbeforesubmission']);
+ $this->assertTrue($result['examplesassessedbeforeassessment']);
// Switch phase.
$workshop = new workshop($this->workshop, $this->cm, $this->course);
$this->assertTrue($result['modifyingsubmissionallowed']);
$this->assertFalse($result['assessingallowed']);
$this->assertFalse($result['assessingexamplesallowed']);
- $this->assertTrue($result['examplesassessed']);
+ $this->assertTrue($result['examplesassessedbeforesubmission']);
+ $this->assertTrue($result['examplesassessedbeforeassessment']);
// Switch to next (to assessment).
$workshop = new workshop($this->workshop, $this->cm, $this->course);
$this->assertFalse($result['modifyingsubmissionallowed']);
$this->assertTrue($result['assessingallowed']);
$this->assertFalse($result['assessingexamplesallowed']);
- $this->assertTrue($result['examplesassessed']);
+ $this->assertTrue($result['examplesassessedbeforesubmission']);
+ $this->assertTrue($result['examplesassessedbeforeassessment']);
}
/**