Sort by filename - Where to put my code ?

Hello,
I need to sort files by original_filename in my omeka installation. Updating application/models/Item.php getFiles() function from :

return $this->getTable('File')->findByItem($this->id);

to :

return $this->getTable('File')->findByItem($this->id, null, "filename");

will do the trick but I prefer not doing that inside the core and would like to put it inside a custom plugin I have that already includes customizations.

But I wonder which hook I should fire to override this getFiles function.

Thanks.

Where do you need to sort the files? I do this with a custom function in my theme, for item pages.

function filename_compare ($a, $b) {
    return strcmp($a->original_filename, $b->original_filename);
}

and then just add this to items/show.php

<?php usort($files, 'filename_compare'); ?>

Another approach might be to dig up the files directly if you have the item.

$files = get_db()->getTable('File')->findByItem($item->id, null, "filename");

That will let the database query do the ordering.

@sheepeeh @patrickmj, in my omeka install, I have added a custom plugin that will display a different thumbnail for each item. The thumbnail is not always the first file of the item but depends on the value of a custom field of the items. For an item where the first 2 files are blank pages (or almost), my colleagues put 3 in the specific field and the plugin will use the 3rd file when displaying thumbnails (see it live).

The specific place where I need the files to be sorted so that my colleagues can easily pick the good one is on admin/items/show/XXX. I am using the default theme where the gallery is displayed using item_image_gallery and it doesn't seem that I can transmit the sorted $files list to this function.

Is there a way to sort the files associated to the item before calling item_image_gallery ? I should do that at the beginning of show.php in the default admin, but my preferred solution would be to be able to reach my goal by adding code to our plugin, so that I can easily update our omeka instance, keeping the default theme untouched and just leaving this plugin to keep the same behaviour.