Skip to content

Commit

Permalink
Merge branch 'MDL-48165-28-dimgrades' of git://github.com/mudrd8mz/mo…
Browse files Browse the repository at this point in the history
…odle into MOODLE_28_STABLE
  • Loading branch information
danpoltawski committed Sep 21, 2015
2 parents 0c73e53 + fa36f1d commit 0dbd259
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
27 changes: 27 additions & 0 deletions mod/workshop/form/edit_form.php
Expand Up @@ -80,6 +80,23 @@ public function definition() {
$mform->closeHeaderBefore('buttonar');
}

/**
* Validate the submitted form data.
*
* Grading strategy plugins can provide their own validation rules by
* overriding the {@link self::validation_inner()} method.
*
* @param array $data
* @param array $files
* @return array
*/
final public function validation($data, $files) {
return array_merge(
parent::validation($data, $files),
$this->validation_inner($data, $files)
);
}

/**
* Add any strategy specific form fields.
*
Expand All @@ -89,4 +106,14 @@ protected function definition_inner(&$mform) {
// By default, do nothing.
}

/**
* Add strategy specific validation rules.
*
* @param array $data
* @param array $files
* @return array
*/
protected function validation_inner($data, $files) {
return array();
}
}
44 changes: 44 additions & 0 deletions mod/workshop/form/rubric/edit_form.php
Expand Up @@ -103,4 +103,48 @@ protected function definition_inner(&$mform) {
$mform->setDefault('config_layout', 'list');
$this->set_data($current);
}

/**
* Provide validation rules for the rubric editor form.
*
* @param array $data
* @param array $files
* @return array
*/
protected function validation_inner($data, $files) {

$errors = array();

// Iterate over all submitted dimensions (criteria).
for ($i = 0; isset($data['dimensionid__idx_'.$i]); $i++) {

$dimgrades = array();

if (0 == strlen(trim($data['description__idx_'.$i.'_editor']['text']))) {
// The description text is empty and this criterion will be deleted.
continue;
}

// Make sure the levels grades are unique within the criterion.
for ($j = 0; isset($data['levelid__idx_'.$i.'__idy_'.$j]); $j++) {
if (0 == strlen(trim($data['definition__idx_'.$i.'__idy_'.$j]))) {
// The level definition is empty and will not be saved.
continue;
}

$levelgrade = $data['grade__idx_'.$i.'__idy_'.$j];

if (isset($dimgrades[$levelgrade])) {
// This grade has already been set for another level.
$k = $dimgrades[$levelgrade];
$errors['level__idx_'.$i.'__idy_'.$j] = $errors['level__idx_'.$i.'__idy_'.$k] = get_string('mustbeunique',
'workshopform_rubric');
} else {
$dimgrades[$levelgrade] = $j;
}
}
}

return $errors;
}
}
1 change: 1 addition & 0 deletions mod/workshop/form/rubric/lang/en/workshopform_rubric.php
Expand Up @@ -33,5 +33,6 @@
$string['layoutlist'] = 'List';
$string['levelgroup'] = 'Level grade and definition';
$string['levels'] = 'Levels';
$string['mustbeunique'] = 'Level grades must be unique within a criterion';
$string['mustchooseone'] = 'You have to select one of these items';
$string['pluginname'] = 'Rubric';

0 comments on commit 0dbd259

Please sign in to comment.