Permalink
Browse files

MDL-34285 condition: Added is not empty option for user profile condi…

…tions and moved strings.

As part of this change I added a new condition for user fields: is not equal.
I also copied the strings being used from the filters lang file to the condition
lang file and changed the uses in code.

AMOS BEGIN
  CPY [contains,filters],[contains,condition]
  CPY [doesnotcontain,filters],[doesnotcontain,condition]
  CPY [isequalto,filters],[isequalto,condition]
  CPY [startswith,filters],[startswith,condition]
  CPY [endswith,filters],[endswith,condition]
  CPY [isempty,filters],[isempty,condition]
AMOS END
  • Loading branch information...
Sam Hemelryk
Sam Hemelryk committed Jul 13, 2012
1 parent 3294034 commit 21a4e24cab5977cf69f1fea3b84c5b8d3d660d05
Showing with 33 additions and 11 deletions.
  1. +14 −1 lang/en/condition.php
  2. +19 −10 lib/conditionlib.php
View
@@ -47,7 +47,10 @@
$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['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 <strong>{$a}</strong> is incomplete.';
@@ -76,13 +82,20 @@
$string['requires_grade_max'] = 'Not available unless you get an appropriate score in <strong>{$a}</strong>.';
$string['requires_grade_min'] = 'Not available until you achieve a required score in <strong>{$a}</strong>.';
$string['requires_grade_range'] = 'Not available unless you get a particular score in <strong>{$a}</strong>.';
-$string['requires_user_field_restriction'] = 'Not available unless your <strong>{$a->field}</strong> {$a->operator} <strong>{$a->value}</strong>.';
+$string['requires_user_field_contains'] = 'Not available unless your <strong>{$a->field}</strong> contains <strong>{$a->value}</strong>.';
+$string['requires_user_field_doesnotcontain'] = 'Not available if your <strong>{$a->field}</strong> contains <strong>{$a->value}</strong>.';
+$string['requires_user_field_endswith'] = 'Not available unless your <strong>{$a->field}</strong> ends with <strong>{$a->value}</strong>.';
+$string['requires_user_field_isempty'] = 'Not available unless your <strong>{$a->field}</strong> is empty.';
+$string['requires_user_field_isequalto'] = 'Not available unless your <strong>{$a->field}</strong> is equal to <strong>{$a->value}</strong>.';
+$string['requires_user_field_isnotempty'] = 'Not available if your <strong>{$a->field}</strong> is empty.';
+$string['requires_user_field_startswith'] = 'Not available unless your <strong>{$a->field}</strong> starts withs <strong>{$a->value}</strong>.';
$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): &lsquo;{$a}&rsquo;';
View
@@ -79,6 +79,10 @@
* 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 @@ protected function get_full_item() {
*/
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 @@ public function get_full_information($modinfo=null) {
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 @@ public function is_available(&$information, $grabthelot=false, $userid=0, $modin
$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 @@ private function is_field_condition_met($operator, $uservalue, $value) {
$fieldconditionmet = false;
}
break;
+ case OP_IS_NOT_EMPTY: // is not empty
+ if (empty($uservalue)) {
+ $fieldconditionmet = false;
+ }
+ break;
}
return $fieldconditionmet;
}

0 comments on commit 21a4e24

Please sign in to comment.