Skip to content

Commit

Permalink
Worked on #2
Browse files Browse the repository at this point in the history
  • Loading branch information
Tizian Schmidlin committed Jan 20, 2017
1 parent a3cf5f4 commit 8fd60f3
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions Classes/Xclass/Folder.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ class Folder extends \TYPO3\CMS\Core\Resource\Folder {
* @var boolean
*/
protected $overrideRecursion = false;

/**
* The search words.
* @var string
*/
protected $searchWords = '';

/**
* The search category.
* @var integer
Expand Down Expand Up @@ -104,15 +104,21 @@ public function setSearchCategory($searchCategory) {
* @param integer $numberOfItems The number of items to return
* @param integer $filterMode The filter mode to use for the file list.
* @param boolean $recursive
* @param string $sort Property name used to sort the items.
* Among them may be: '' (empty, no sorting), name,
* fileext, size, tstamp and rw.
* If a driver does not support the given property, it
* should fall back to "name".
* @param bool $sortRev TRUE to indicate reverse sorting (last to first)
* @return \TYPO3\CMS\Core\Resource\File[]
*/
public function getFiles($start = 0, $numberOfItems = 0, $filterMode = self::FILTER_MODE_USE_OWN_AND_STORAGE_FILTERS, $recursive = FALSE) {
public function getFiles($start = 0, $numberOfItems = 0, $filterMode = self::FILTER_MODE_USE_OWN_AND_STORAGE_FILTERS, $recursive = FALSE, $sort = '', $sortRev = false) {
if ($this->overrideRecursion) {
$files = array();

$resourceFactory = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\ResourceFactory');
$driver = $resourceFactory->getDriverObject($this->getStorage()->getDriverType(), $this->getStorage()->getConfiguration());

// Fallback for compatibility with the old method signature variable $useFilters that was used instead of $filterMode
if ($filterMode === FALSE) {
$useFilters = FALSE;
Expand All @@ -124,27 +130,27 @@ public function getFiles($start = 0, $numberOfItems = 0, $filterMode = self::FIL
$filters[] = $filter;
}
}

$words = $GLOBALS['TYPO3_DB']->fullQuoteArray(array_map(function ($value) { return '%' . $value . '%'; }, GeneralUtility::trimExplode(' ', $this->searchWords, true)), 'sys_file');
$wordsMatch = '';
if (count($words)) {
$wordsMatch = ' AND (sys_file.name LIKE ' . implode(' AND sys_file.name LIKE ', $words) . ')';
}

$categoryUtility = GeneralUtility::makeInstance('Cabag\\Falsearch\\Utility\\CategoryUtility');
$categories = array();
if ($this->searchCategory > 0) {
$categories = array_keys($categoryUtility->getIndexForCategory($this->searchCategory));
}

$resource = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
'sys_file.*',
'sys_file' . (count($categories) > 0 ? ' LEFT JOIN sys_file_metadata ON sys_file_metadata.file = sys_file.uid LEFT JOIN sys_category_record_mm ON sys_file_metadata.uid = sys_category_record_mm.uid_foreign' : ''),
'sys_file.missing = 0 AND sys_file.storage = ' . $this->getStorage()->getUid() . ' AND sys_file.identifier LIKE ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($this->getIdentifier() . '%', 'sys_file') . $wordsMatch . (count($categories) > 0 ? ' AND sys_category_record_mm.tablenames = \'sys_file_metadata\' AND sys_category_record_mm.fieldname = \'categories\' AND sys_category_record_mm.uid_local IN (' . implode(',', $categories) . ')' : ''),
(count($categories) > 0 ? 'sys_file.uid' : ''),
'sys_file.identifier ASC'
);

$indexer = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\Index\\Indexer', $this->getStorage());
$count = 0;
$resultCount = 0;
Expand All @@ -154,13 +160,13 @@ public function getFiles($start = 0, $numberOfItems = 0, $filterMode = self::FIL
$badFilters++;
continue;
}

if ($start <= $count) {
if ($numberOfItems !== 0 && $numberOfItems >= $resultCount) {
break;
}
$file = $resourceFactory->getFileObject($row['uid'], $row);

// make sure the missing information is up to date
try {
$indexer->updateIndexEntry($file);
Expand All @@ -172,16 +178,16 @@ public function getFiles($start = 0, $numberOfItems = 0, $filterMode = self::FIL
if ($file->isMissing()) {
continue;
}

$files[] = $file;
$resultCount++;
}
$count++;
}

return $files;
}
return parent::getFiles($start, $numberOfItems, $filterMode, $recursive);
return parent::getFiles($start, $numberOfItems, $filterMode, $recursive, $sort, $sortRev);
}

/**
Expand Down Expand Up @@ -210,7 +216,7 @@ protected function applyFilterMethodsToDirectoryItem(array $filterMethods, $item
}
return TRUE;
}

/**
* Returns the full path of this folder, from the root.
*
Expand Down

0 comments on commit 8fd60f3

Please sign in to comment.