Introduced check before sorting to ensure core_collator class exists as it was only introduced in 2.6

This commit is contained in:
Mark Nelson 2013-07-26 16:28:09 +08:00
parent cef1d2c7d8
commit cee65c6c37
2 changed files with 15 additions and 2 deletions

View file

@ -36,7 +36,7 @@ class customcert_element_userfield extends customcert_element_base {
public function render_form_elements($mform) {
// Get the user fields.
$userfields = condition_info::get_condition_user_fields();
core_collator::asort($userfields);
customcert_perform_asort($userfields);
// Create the select box where the user field is selected.
$mform->addElement('select', 'userfield', get_string('userfield', 'customcertelement_userfield'), $userfields);

15
lib.php
View file

@ -403,7 +403,7 @@ function customcert_get_elements() {
}
}
core_collator::asort($options);
customcert_perform_asort($options);
return $options;
}
@ -969,3 +969,16 @@ function customcert_generate_report_file($customcert, $users, $type) {
// Close the workbook.
$workbook->close();
}
/**
* Perform asort on a given array.
*
* @param array $fields
*/
function customcert_perform_asort(&$fields) {
if (class_exists('core_collator')) {
core_collator::asort($fields);
} else {
collatorlib::asort($fields);
}
}