MDL-29538 core_condition: validate whether a field has been declared before for that activity

This commit is contained in:
Mark Nelson
2012-06-26 15:18:52 +08:00
parent a8f84c287c
commit a6b538a862
2 changed files with 16 additions and 0 deletions
+15
View File
@@ -358,6 +358,21 @@ abstract class moodleform_mod extends moodleform {
}
}
// Conditions: Verify that the user profile field has not been declared more than one
if (array_key_exists('conditionfieldgroup', $data)) {
// Array to store the existing fields
$arrcurrentfields = array();
// Error message displayed if any condition is declared more than once
$stralreadydeclaredwarning = get_string('fielddeclaredmultipletimes', 'condition');
foreach ($data['conditionfieldgroup'] as $i => $fielddata) {
if (in_array($fielddata['conditionfield'], $arrcurrentfields)) {
$errors["conditionfieldgroup[{$i}]"] = $stralreadydeclaredwarning;
}
// Add the field to the array
$arrcurrentfields[] = $fielddata['conditionfield'];
}
}
return $errors;
}
+1
View File
@@ -48,6 +48,7 @@ $string['completion_incomplete'] = 'must not be marked complete';
$string['completion_pass'] = 'must be complete with pass grade';
$string['configenableavailability'] = 'When enabled, this lets you set conditions (based on date, grade, or completion) that control whether an activity or resource can be accessed.';
$string['enableavailability'] = 'Enable conditional access';
$string['fielddeclaredmultipletimes'] = 'You can not declare the same field more than once per activity.';
$string['grade_atleast'] = 'must be at least';
$string['gradecondition'] = 'Grade condition';
$string['gradecondition_help'] = 'This setting determines any grade conditions which must be met in order to access the activity.