Permalink
Browse files

MDL-38035 Activity settings: Support multilang names for custom user …

…fields
  • Loading branch information...
1 parent 5c8860f commit 0e79c3ee747c70f08d44fa562f429d418b28362f @sammarshallou sammarshallou committed Feb 19, 2013
Showing with 17 additions and 7 deletions.
  1. +2 −2 course/editsection_form.php
  2. +2 −1 course/moodleform_mod.php
  3. +13 −4 lib/conditionlib.php
@@ -51,6 +51,7 @@ public function definition_after_data() {
$mform = $this->_form;
$course = $this->_customdata['course'];
+ $context = context_course::instance($course->id);
if (!empty($CFG->enableavailability)) {
$mform->addElement('header', '', get_string('availabilityconditions', 'condition'));
@@ -62,7 +63,6 @@ public function definition_after_data() {
$options[0] = get_string('none');
if ($groupings = $DB->get_records('groupings', array('courseid' => $course->id))) {
foreach ($groupings as $grouping) {
- $context = context_course::instance($course->id);
$options[$grouping->id] = format_string(
$grouping->name, true, array('context' => $context));
}
@@ -119,7 +119,7 @@ public function definition_after_data() {
// Conditions based on user fields
$operators = condition_info::get_condition_user_field_operators();
- $useroptions = condition_info::get_condition_user_fields();
+ $useroptions = condition_info::get_condition_user_fields(array('context' => $context));
asort($useroptions);
$useroptions = array(0 => $strcondnone) + $useroptions;
@@ -564,7 +564,8 @@ function standard_coursemodule_elements(){
// Conditions based on user fields
$operators = condition_info::get_condition_user_field_operators();
- $useroptions = condition_info::get_condition_user_fields();
+ $useroptions = condition_info::get_condition_user_fields(
+ array('context' => $this->context));
asort($useroptions);
$useroptions = array(0 => $strnone) + $useroptions;
View
@@ -599,12 +599,17 @@ public static function get_condition_user_field_operators() {
}
/**
- * The user fields we can compare
+ * Returns list of user fields that can be compared.
*
- * @global moodle_database $DB
+ * If you specify $formatoptions, then format_string will be called on the
+ * custom field names. This is necessary for multilang support to work so
+ * you should include this parameter unless you are going to format the
+ * text later.
+ *
+ * @param array $formatoptions Passed to format_string if provided
* @return array Associative array from user field constants to display name
*/
- public static function get_condition_user_fields() {
+ public static function get_condition_user_fields($formatoptions = null) {
global $DB;
$userfields = array(
@@ -630,7 +635,11 @@ public static function get_condition_user_fields() {
// Go through the custom profile fields now
if ($user_info_fields = $DB->get_records('user_info_field')) {
foreach ($user_info_fields as $field) {
- $userfields[$field->id] = $field->name;
+ if ($formatoptions) {
+ $userfields[$field->id] = format_string($field->name, true, $formatoptions);
+ } else {
+ $userfields[$field->id] = $field->name;
+ }
}
}

0 comments on commit 0e79c3e

Please sign in to comment.