diff --git a/lang/en/condition.php b/lang/en/condition.php
index 5851e6e1f61..a888d8c7747 100644
--- a/lang/en/condition.php
+++ b/lang/en/condition.php
@@ -47,7 +47,10 @@ $string['completion_fail'] = 'must be complete with fail grade';
$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['contains'] = 'contains';
+$string['doesnotcontain'] = 'doesn\'t contain';
$string['enableavailability'] = 'Enable conditional access';
+$string['endswith'] = 'ends with';
$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';
@@ -62,6 +65,9 @@ $string['grade_upto'] = 'and less than';
$string['gradeitembutnolimits'] = 'You must enter an upper or lower limit, or both.';
$string['gradelimitsbutnoitem'] = 'You must choose a grade item.';
$string['gradesmustbenumeric'] = 'The minimum and maximum grades must be numeric (or blank).';
+$string['isempty'] = 'is empty';
+$string['isequalto'] = 'is equal to';
+$string['isnotempty'] = 'is not empty';
$string['none'] = '(none)';
$string['notavailableyet'] = 'Not available yet';
$string['requires_completion_0'] = 'Not available unless the activity {$a} is incomplete.';
@@ -76,13 +82,20 @@ $string['requires_grade_any'] = 'Not available until you have a grade in {$a}.';
$string['requires_grade_min'] = 'Not available until you achieve a required score in {$a}.';
$string['requires_grade_range'] = 'Not available unless you get a particular score in {$a}.';
-$string['requires_user_field_restriction'] = 'Not available unless your {$a->field} {$a->operator} {$a->value}.';
+$string['requires_user_field_contains'] = 'Not available unless your {$a->field} contains {$a->value}.';
+$string['requires_user_field_doesnotcontain'] = 'Not available if your {$a->field} contains {$a->value}.';
+$string['requires_user_field_endswith'] = 'Not available unless your {$a->field} ends with {$a->value}.';
+$string['requires_user_field_isempty'] = 'Not available unless your {$a->field} is empty.';
+$string['requires_user_field_isequalto'] = 'Not available unless your {$a->field} is equal to {$a->value}.';
+$string['requires_user_field_isnotempty'] = 'Not available if your {$a->field} is empty.';
+$string['requires_user_field_startswith'] = 'Not available unless your {$a->field} starts withs {$a->value}.';
$string['showavailability'] = 'Before activity can be accessed';
$string['showavailabilitysection'] = 'Before section can be accessed';
$string['showavailability_hide'] = 'Hide activity entirely';
$string['showavailability_show'] = 'Show activity greyed-out, with restriction information';
$string['showavailabilitysection_hide'] = 'Hide section entirely';
$string['showavailabilitysection_show'] = 'Show section greyed-out, with restriction information';
+$string['startswith'] = 'starts with';
$string['userfield'] = 'User field';
$string['userfield_help'] = 'You can restrict access based on any field from the users profile.';
$string['userrestriction_hidden'] = 'Restricted (completely hidden, no message): ‘{$a}’';
diff --git a/lib/conditionlib.php b/lib/conditionlib.php
index 650006a0288..a76a4f46dcb 100644
--- a/lib/conditionlib.php
+++ b/lib/conditionlib.php
@@ -79,6 +79,10 @@ define('OP_ENDS_WITH', 'endswith');
* OP_IS_EMPTY - comparison operator that determines whether a specified user field is empty
*/
define('OP_IS_EMPTY', 'isempty');
+/**
+ * OP_IS_NOT_EMPTY - comparison operator that determines whether a specified user field is not empty
+ */
+define('OP_IS_NOT_EMPTY', 'isnotempty');
require_once($CFG->libdir.'/completionlib.php');
@@ -583,12 +587,13 @@ abstract class condition_info_base {
*/
public static function get_condition_user_field_operators() {
return array(
- OP_CONTAINS => get_string('contains', 'filters'),
- OP_DOES_NOT_CONTAIN => get_string('doesnotcontain', 'filters'),
- OP_IS_EQUAL_TO => get_string('isequalto', 'filters'),
- OP_STARTS_WITH => get_string('startswith', 'filters'),
- OP_ENDS_WITH => get_string('endswith', 'filters'),
- OP_IS_EMPTY => get_string('isempty', 'filters')
+ OP_CONTAINS => get_string('contains', 'condition'),
+ OP_DOES_NOT_CONTAIN => get_string('doesnotcontain', 'condition'),
+ OP_IS_EQUAL_TO => get_string('isequalto', 'condition'),
+ OP_STARTS_WITH => get_string('startswith', 'condition'),
+ OP_ENDS_WITH => get_string('endswith', 'condition'),
+ OP_IS_EMPTY => get_string('isempty', 'condition'),
+ OP_IS_NOT_EMPTY => get_string('isnotempty', 'condition'),
);
}
@@ -801,9 +806,9 @@ abstract class condition_info_base {
foreach ($this->item->conditionsfield as $field => $details) {
$a = new stdclass;
$a->field = $details->fieldname;
- $a->operator = get_string($details->operator, 'filters');
+ $a->operator = get_string($details->operator, 'condition');
$a->value = $details->value;
- $information .= get_string('requires_user_field_restriction', 'condition', $a) . ' ';
+ $information .= get_string('requires_user_field', 'condition', $a) . ' ';
}
}
@@ -1008,9 +1013,8 @@ abstract class condition_info_base {
$available = false;
$a = new stdClass();
$a->field = $details->fieldname;
- $a->operator = get_string($details->operator, 'filters');
$a->value = $details->value;
- $information .= get_string('requires_user_field_restriction', 'condition', $a) . ' ';
+ $information .= get_string('requires_user_field_'.$details->operator, 'condition', $a) . ' ';
}
}
}
@@ -1224,6 +1228,11 @@ abstract class condition_info_base {
$fieldconditionmet = false;
}
break;
+ case OP_IS_NOT_EMPTY: // is not empty
+ if (empty($uservalue)) {
+ $fieldconditionmet = false;
+ }
+ break;
}
return $fieldconditionmet;
}