Skip to content

Commit

Permalink
MDL-58408 completion: can not require grade if grading is not available
Browse files Browse the repository at this point in the history
Part of MDL-58138 epic
  • Loading branch information
marinaglancy authored and snake committed Apr 19, 2017
1 parent 22002ed commit 6445f17
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
34 changes: 34 additions & 0 deletions completion/classes/bulkedit_form.php
Expand Up @@ -123,4 +123,38 @@ public function definition() {
$this->set_data($data);
}
}

/**
* Form validation
*
* @param array $data array of ("fieldname"=>value) of submitted data
* @param array $files array of uploaded files "element_name"=>tmp_file_path
* @return array of "element_name"=>"error_description" if there are errors,
* or an empty array if everything is OK (true allowed for backwards compatibility too).
*/
public function validation($data, $files) {
global $CFG;
$errors = parent::validation($data, $files);

// Completion: Don't let them choose automatic completion without turning
// on some conditions.
if (array_key_exists('completion', $data) &&
$data['completion'] == COMPLETION_TRACKING_AUTOMATIC && !empty($data['completionusegrade'])) {
require_once($CFG->libdir.'/gradelib.php');
$moduleswithoutgradeitem = [];
foreach ($this->cms as $cm) {
$item = grade_item::fetch(array('courseid' => $cm->course, 'itemtype' => 'mod',
'itemmodule' => $cm->modname, 'iteminstance' => $cm->instance,
'itemnumber' => 0));
if (!$item) {
$moduleswithoutgradeitem[] = $cm->get_formatted_name();
}
}
if ($moduleswithoutgradeitem) {
$errors['completionusegrade'] = get_string('nogradeitem', 'completion', join(', ', $moduleswithoutgradeitem));
}
}

return $errors;
}
}
1 change: 1 addition & 0 deletions lang/en/completion.php
Expand Up @@ -164,6 +164,7 @@
$string['modifybulkactions'] = 'Modify the actions you wish to bulk edit';
$string['moredetails'] = 'More details';
$string['nocriteriaset'] = 'No completion criteria set for this course';
$string['nogradeitem'] = 'Require grade can not be enabled for <b>{$a}</b> because grades are not available there';
$string['notcompleted'] = 'Not completed';
$string['notenroled'] = 'You are not enrolled in this course';
$string['nottracked'] = 'You are currently not being tracked by completion in this course';
Expand Down

0 comments on commit 6445f17

Please sign in to comment.