MDL-38035 Activity settings: Support multilang names for custom user fields
This commit is contained in:
@@ -51,6 +51,7 @@ class editsection_form extends moodleform {
|
|||||||
|
|
||||||
$mform = $this->_form;
|
$mform = $this->_form;
|
||||||
$course = $this->_customdata['course'];
|
$course = $this->_customdata['course'];
|
||||||
|
$context = context_course::instance($course->id);
|
||||||
|
|
||||||
if (!empty($CFG->enableavailability)) {
|
if (!empty($CFG->enableavailability)) {
|
||||||
$mform->addElement('header', '', get_string('availabilityconditions', 'condition'));
|
$mform->addElement('header', '', get_string('availabilityconditions', 'condition'));
|
||||||
@@ -62,7 +63,6 @@ class editsection_form extends moodleform {
|
|||||||
$options[0] = get_string('none');
|
$options[0] = get_string('none');
|
||||||
if ($groupings = $DB->get_records('groupings', array('courseid' => $course->id))) {
|
if ($groupings = $DB->get_records('groupings', array('courseid' => $course->id))) {
|
||||||
foreach ($groupings as $grouping) {
|
foreach ($groupings as $grouping) {
|
||||||
$context = context_course::instance($course->id);
|
|
||||||
$options[$grouping->id] = format_string(
|
$options[$grouping->id] = format_string(
|
||||||
$grouping->name, true, array('context' => $context));
|
$grouping->name, true, array('context' => $context));
|
||||||
}
|
}
|
||||||
@@ -119,7 +119,7 @@ class editsection_form extends moodleform {
|
|||||||
|
|
||||||
// Conditions based on user fields
|
// Conditions based on user fields
|
||||||
$operators = condition_info::get_condition_user_field_operators();
|
$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);
|
asort($useroptions);
|
||||||
|
|
||||||
$useroptions = array(0 => $strcondnone) + $useroptions;
|
$useroptions = array(0 => $strcondnone) + $useroptions;
|
||||||
|
|||||||
@@ -564,7 +564,8 @@ abstract class moodleform_mod extends moodleform {
|
|||||||
|
|
||||||
// Conditions based on user fields
|
// Conditions based on user fields
|
||||||
$operators = condition_info::get_condition_user_field_operators();
|
$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);
|
asort($useroptions);
|
||||||
|
|
||||||
$useroptions = array(0 => $strnone) + $useroptions;
|
$useroptions = array(0 => $strnone) + $useroptions;
|
||||||
|
|||||||
+13
-4
@@ -599,12 +599,17 @@ abstract class condition_info_base {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
* @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;
|
global $DB;
|
||||||
|
|
||||||
$userfields = array(
|
$userfields = array(
|
||||||
@@ -630,7 +635,11 @@ abstract class condition_info_base {
|
|||||||
// Go through the custom profile fields now
|
// Go through the custom profile fields now
|
||||||
if ($user_info_fields = $DB->get_records('user_info_field')) {
|
if ($user_info_fields = $DB->get_records('user_info_field')) {
|
||||||
foreach ($user_info_fields as $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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user