diff --git a/course/moodleform_mod.php b/course/moodleform_mod.php index fc1c5ab2b95..9bafe21e2fc 100644 --- a/course/moodleform_mod.php +++ b/course/moodleform_mod.php @@ -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; } diff --git a/lang/en/condition.php b/lang/en/condition.php index ebce0df087d..2eab10ad5f9 100644 --- a/lang/en/condition.php +++ b/lang/en/condition.php @@ -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.