Commit 6de94bad authored by Fergus Whyte's avatar Fergus Whyte
Browse files

Bug #920252 Make group categories appear in alphabetical order.

behatnotneeded
Change-Id: If45120ccbd387b7198a3e15b666d43f14386a9a2
parent 4a9e6f29
......@@ -23,29 +23,29 @@ $itemid = param_variable('itemid');
$data = new StdClass;
$data->title = $name;
if ($itemid == 'new') {
try {
$displayorders = get_records_array('group_category', '', '', '', 'displayorder');
$max = 0;
if ($displayorders) {
foreach ($displayorders as $r) {
$max = $r->displayorder >= $max ? $r->displayorder + 1 : $max;
}
}
$data->displayorder = $max;
$itemid = insert_record('group_category', $data, 'id', true);
}
catch (Exception $e) {
json_reply('local',get_string('savefailed','admin'));
try {
if ($itemid == 'new') {
$data->displayorder = 0; //Place holder.
$itemid = insert_record('group_category',$data,'id',true);
}
}
else {
$data->id = (int)$itemid;
try {
else {
$data->id = (int)$itemid;
update_record('group_category', $data, 'id');
}
catch (Exception $e) {
json_reply('local',get_string('savefailed','admin'));
$groupcategories = get_records_array('group_category');
usort($groupcategories, function($a, $b) {
return strnatcasecmp($a->title, $b->title);
});
foreach ($groupcategories as $key => $gcategory) {
if ($key != $gcategory->displayorder) {
$gcategory->displayorder = $key;
update_record('group_category', $gcategory);
}
}
}
catch (Exception $e) {
json_reply('local',get_string('savefailed','admin'));
}
json_reply(false, array('id' => (int)$itemid));
......@@ -4926,5 +4926,20 @@ function xmldb_core_upgrade($oldversion=0) {
execute_sql("UPDATE {framework_evidence_statuses} SET name = REPLACE(name, 'criterium', 'criterion') WHERE name LIKE '%criterium'");
}
if ($oldversion < 2017022700) {
log_debug('Put group categories in alphabetical order');
if ( $groupcategories = get_records_array('group_category') ) {
usort($groupcategories, function($a,$b) {
return strnatcasecmp($a->title, $b->title);
});
foreach ($groupcategories as $key => $gcategory) {
if ($key != $gcategory->displayorder) {
$gcategory->displayorder = $key;
update_record('group_category', $gcategory);
}
}
}
}
return $status;
}
......@@ -16,7 +16,7 @@ $config = new stdClass();
// See https://wiki.mahara.org/wiki/Developer_Area/Version_Numbering_Policy
// For upgrades on stable branches, increment the version by one. On master, use the date.
$config->version = 2017022500;
$config->version = 2017022700;
$config->series = '17.04';
$config->release = '17.04dev';
$config->minupgradefrom = 2012080604;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment