Bug #81541 » refsort.patch
typo3/sysext/filelist/Classes/FileList.php | ||
---|---|---|
$folders = $storage->getFoldersInFolder($this->folderObject, $foldersFrom, $foldersNum, true, false, trim($this->sort), (bool)$this->sortRev);
|
||
$files = $this->folderObject->getFiles($filesFrom, $filesNum, Folder::FILTER_MODE_USE_OWN_AND_STORAGE_FILTERS, false, trim($this->sort), (bool)$this->sortRev);
|
||
$this->totalItems = $foldersCount + $filesCount;
|
||
|
||
// HF-MOD: START - Ref sorting
|
||
if (trim($this->sort) === '_REF_') {
|
||
$filesWithRefs = [];
|
||
foreach ($files as $name => $file) {
|
||
$databaseConnection = $this->getDatabaseConnection();
|
||
$table = 'sys_refindex';
|
||
$referenceCount = $databaseConnection->exec_SELECTcountRows(
|
||
'*',
|
||
$table,
|
||
'ref_table=' . $databaseConnection->fullQuoteStr('sys_file', $table)
|
||
. ' AND ref_uid=' . (int)$file->getUid()
|
||
. ' AND deleted=0'
|
||
. ' AND tablename != ' . $databaseConnection->fullQuoteStr('sys_file_metadata', $table)
|
||
);
|
||
$filesWithRefs[$name] = [
|
||
'refs' => $referenceCount,
|
||
'file' => $file,
|
||
];
|
||
}
|
||
uasort($filesWithRefs, function ($a, $b) {
|
||
if ($a['refs'] == $b['refs']) {
|
||
return 0;
|
||
}
|
||
if ((bool) $this->sortRev) {
|
||
return ($a['refs'] < $b['refs']) ? 1 : -1;
|
||
}
|
||
return ($a['refs'] < $b['refs']) ? -1 : 1;
|
||
});
|
||
$files = [];
|
||
foreach ($filesWithRefs as $name => $file) {
|
||
$files[$name] = $file['file'];
|
||
}
|
||
}
|
||
// HF-MOD: END - Ref sorting
|
||
$this->totalItems = $foldersCount + $filesCount;
|
||
// Adds the code of files/dirs
|
||
$out = '';
|
||
$titleCol = 'file';
|