I am looking for a way to sort files from given items by their original file name.
<?php
set_current_collection(get_collection_by_id($collectionID));
while (loop_items_in_collection(total_items_in_collection())):
if (item_has_files()):
while(loop_files_for_item()):
//I would like files sorted before this loop starts
endwhile;
endif;
endwhile;
?>
Is there a way to accomplish this? I couldn't find the proper sorting for loop_files_for_item, loop_items_in_collection, set_current_collection, or get_collection_by_id.
I don't think that there are good options for that in Omeka 1.x (which it looks like you are using from the code example). In Omeka 2.3 there are ways to get at that, though. (There are lots of other good reasons to upgrade if at all possible, including security fixes)
Thanks Patrick, I cannot upgrade this particular install. I think I can make it work using the below code.
<?php
$arrayOfFiles = array();
set_current_collection(get_collection_by_id($collectionID));
while (loop_items_in_collection(total_items_in_collection())):
if (item_has_files()):
while(loop_files_for_item()):
$arrayOfFiles[] = array('id' => item_file('id'), 'of' => item_file('original filename'));
endwhile;
// Obtain a list of columns
foreach ($arrayOfFiles as $key => $row) {
$id[$key] = $row['id'];
$of[$key] = $row['of'];
}
// Sort by $of (orginal filename) ascending
array_multisort($of, SORT_ASC, $arrayOfFiles);
foreach ($arrayOfFiles as $key => $row) {
//do what you need to with the sorted array here
echo $row['id'] . " -> " . $row['of'] . "<br>";
}
$arrayOfFiles = array();
endif;
endwhile;
?>