mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 00:12:56 +02:00
MDL-38035 Conditional availability: Support multilang custom user fields
This commit is contained in:
parent
3a09f4dc64
commit
acfee0d4ba
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user