Commit 8662adc9 authored by Cecilia Vela Gurovic's avatar Cecilia Vela Gurovic

Bug 1181696: Reorder images in gallery when renaming files

Check the filename when displaying an image gallery
and show images in alphabetical order.
The same ordering function is used as the Content/files
view when displaying the files.
This can be easily undone when bug 732462 is fixed.

behatnotneeded

Change-Id: I795e4f606e570f0088a21a4404fbf8a4c5249998
parent 51be11cb
......@@ -339,6 +339,8 @@ class PluginBlocktypeGallery extends MaharaCoreBlocktype {
$artefactids = artefact_get_descendants(array(intval($configdata['artefactid'])));
}
$artefactids = $instance->order_artefacts_by_title($artefactids);
// This can be either an image or profileicon. They both implement
// render_self
foreach ($artefactids as $artefactid) {
......
......@@ -981,6 +981,26 @@ class BlockInstance {
return array('html' => $smarty->fetch('view/blocktypecontainerediting.tpl'), 'javascript' => $js, 'pieformcss' => $css);
}
public function order_artefacts_by_title($ids){
$result = array();
if ($ids) {
$artefacts = get_records_sql_array(
'SELECT a.id, a.title FROM {artefact} a WHERE a.id in ( '. join(',', array_fill(0, count($ids), '?')) . ')', $ids
);
uasort($artefacts, array("BlockInstance", "my_files_cmp"));
foreach ($artefacts as $artefact) {
$result[] = $artefact->id;
}
}
return $result;
}
public static function my_files_cmp($a, $b) {
return strnatcasecmp($a->title, $b->title);
}
/**
* To render the html of a block for viewing
*
......
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