Permalink
Browse files

MDL-38035 Conditional availability: Support multilang custom user fields

  • Loading branch information...
sammarshallou committed Mar 20, 2013
1 parent 3a09f4d commit acfee0d4baba4c214dabcdcd94ed8eb7a2d62c79
Showing with 20 additions and 3 deletions.
  1. +20 −3 lib/conditionlib.php
View
@@ -187,6 +187,10 @@ public static function completion_value_used_as_condition($course, $cm) {
}
return array_key_exists($cm->id, $CONDITIONLIB_PRIVATE->usedincondition[$course->id]);
}
+
+ protected function get_context() {
+ return context_module::instance($this->item->id);
+ }
}
@@ -285,7 +289,7 @@ public function is_available(&$information, $grabthelot=false, $userid=0, $modin
if (!$userid) {
$userid = $USER->id;
}
- $context = context_course::instance($this->item->course);
+ $context = $this->get_context();
if ($userid != $USER->id) {
// We are requesting for a non-current user so check it individually
@@ -353,6 +357,10 @@ public static function update_section_from_form($section, $fromform, $wipefirst=
$ci = new condition_info_section($section, CONDITION_MISSING_EVERYTHING);
parent::update_from_form($ci, $fromform, $wipefirst);
}
+
+ protected function get_context() {
+ return context_course::instance($this->item->course);
+ }
}
@@ -816,10 +824,11 @@ public function get_full_information($modinfo=null) {
// User field conditions
if (count($this->item->conditionsfield) > 0) {
+ $context = $this->get_context();
// Need the array of operators
foreach ($this->item->conditionsfield as $field => $details) {
$a = new stdclass;
- $a->field = $details->fieldname;
+ $a->field = format_string($details->fieldname, true, array('context' => $context));
$a->value = $details->value;
$information .= html_writer::start_tag('li');
$information .= get_string('requires_user_field_'.$details->operator, 'condition', $a) . ' ';
@@ -1044,13 +1053,14 @@ public function is_available(&$information, $grabthelot=false, $userid=0, $modin
// Check if user field condition
if (count($this->item->conditionsfield) > 0) {
+ $context = $this->get_context();
foreach ($this->item->conditionsfield as $field => $details) {
$uservalue = $this->get_cached_user_profile_field($userid, $field);
if (!$this->is_field_condition_met($details->operator, $uservalue, $details->value)) {
// Set available to false
$available = false;
$a = new stdClass();
- $a->field = $details->fieldname;
+ $a->field = format_string($details->fieldname, true, array('context' => $context));
$a->value = $details->value;
$information .= html_writer::start_tag('li');
$information .= get_string('requires_user_field_'.$details->operator, 'condition', $a) . ' ';
@@ -1451,6 +1461,13 @@ protected static function update_from_form(condition_info_base $ci, $fromform, $
}
}
}
+
+ /**
+ * Obtains context for any necessary checks.
+ *
+ * @return context Suitable context for the item
+ */
+ protected abstract function get_context();
}
condition_info::init_global_cache();

0 comments on commit acfee0d

Please sign in to comment.