MDL-29538 core_condition: validate whether a field has been declared before for that activity
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user