Merge branch 'MDL-38035-master' of git://github.com/sammarshallou/moodle
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Wed, 20 Mar 2013 16:06:22 +0000 (17:06 +0100)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Wed, 20 Mar 2013 16:06:22 +0000 (17:06 +0100)
lib/conditionlib.php

index d6b5e05..a525149 100644 (file)
@@ -187,6 +187,10 @@ class condition_info extends condition_info_base {
         }
         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 @@ class condition_info_section extends condition_info_base {
             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 @@ class condition_info_section extends condition_info_base {
         $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 @@ abstract class condition_info_base {
 
         // 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 @@ abstract class condition_info_base {
 
         // 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 @@ abstract class condition_info_base {
             }
         }
     }
+
+    /**
+     * Obtains context for any necessary checks.
+     *
+     * @return context Suitable context for the item
+     */
+    protected abstract function get_context();
 }
 
 condition_info::init_global_cache();