function _group_filenames in Ubercart 5
Group filenames by an attribute while maintaining order.
@return: The sorted array of objects
Parameters
$files: The array of objects
1 call to _group_filenames()
- uc_file_files_table in uc_file/
uc_file.module - Table builder for file products admin
File
- uc_file/
uc_file.module, line 1445 - Allows products to be associated with downloadable files.
Code
function _group_filenames($objects) {
$output = array();
$existing = array();
foreach ($objects as $key => $object) {
$filename = $object->filename;
if (!in_array($filename, array_keys($existing))) {
$existing[$filename] = $key;
$output[] = $object;
}
else {
$inserted_index = $existing[$filename] + 1;
foreach ($existing as $filename => $index) {
$existing[$filename] = $index >= $inserted_index ? $index + 1 : $index;
}
array_splice($output, $inserted_index, 0, array(
$inserted_index => $object,
));
}
}
return $output;
}