‪TYPO3CMS  9.5
FileSearchResult.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
22 
28 {
32  private ‪$searchDemand;
33 
37  private ‪$result;
38 
42  private ‪$resultCount;
43 
45  {
46  $this->searchDemand = ‪$searchDemand;
47  }
48 
53  public function ‪count(): int
54  {
55  if ($this->resultCount !== null) {
56  return ‪$this->resultCount;
57  }
58 
59  $this->resultCount = (int)‪FileSearchQuery::createCountForSearchDemand($this->searchDemand)->‪execute()->fetchColumn(0);
60 
61  return ‪$this->resultCount;
62  }
63 
68  public function ‪current(): ‪File
69  {
70  $this->‪initialize();
71  return ‪current($this->result);
72  }
73 
78  public function ‪key(): int
79  {
80  $this->‪initialize();
81  return ‪key($this->result);
82  }
83 
87  public function ‪next(): void
88  {
89  $this->‪initialize();
90  ‪next($this->result);
91  }
92 
96  public function ‪rewind(): void
97  {
98  $this->‪initialize();
99  reset($this->result);
100  }
101 
106  public function ‪valid(): bool
107  {
108  $this->‪initialize();
109  return ‪current($this->result) !== false;
110  }
111 
115  private function ‪initialize(): void
116  {
117  if ($this->result !== null) {
118  return;
119  }
120  $this->result = ‪FileSearchQuery::createForSearchDemand($this->searchDemand)->‪execute()->fetchAll();
121  $this->resultCount = ‪count($this->result);
122  $this->result = array_map(
123  function (array $fileRow) {
124  return ‪ResourceFactory::getInstance()->‪getFileObject($fileRow['uid'], $fileRow);
125  },
127  );
128  }
129 }
‪TYPO3\CMS\Core\Resource\Search\FileSearchQuery
Definition: FileSearchQuery.php:34
‪TYPO3\CMS\Core\Resource\Search\Result\FileSearchResult\initialize
‪initialize()
Definition: FileSearchResult.php:112
‪TYPO3\CMS\Core\Resource\Search\Result\FileSearchResult\current
‪File current()
Definition: FileSearchResult.php:65
‪TYPO3\CMS\Core\Resource\Search\Result\FileSearchResult\$result
‪array $result
Definition: FileSearchResult.php:35
‪TYPO3\CMS\Core\Resource\Search\FileSearchQuery\createForSearchDemand
‪static FileSearchQuery createForSearchDemand(FileSearchDemand $searchDemand, QueryBuilder $queryBuilder=null)
Definition: FileSearchQuery.php:63
‪TYPO3\CMS\Core\Resource\Search\Result\FileSearchResult\__construct
‪__construct(FileSearchDemand $searchDemand)
Definition: FileSearchResult.php:41
‪TYPO3\CMS\Core\Resource\ResourceFactory\getInstance
‪static ResourceFactory getInstance()
Definition: ResourceFactory.php:39
‪TYPO3\CMS\Core\Resource\Search\Result\FileSearchResult\rewind
‪rewind()
Definition: FileSearchResult.php:93
‪TYPO3\CMS\Core\Resource\Search\Result
Definition: DriverFilteredSearchResult.php:3
‪TYPO3\CMS\Core\Resource\Search\Result\FileSearchResult\next
‪next()
Definition: FileSearchResult.php:84
‪TYPO3\CMS\Core\Resource\Search\Result\FileSearchResult\$resultCount
‪int $resultCount
Definition: FileSearchResult.php:39
‪TYPO3\CMS\Core\Resource\Search\FileSearchQuery\execute
‪execute()
Definition: FileSearchQuery.php:167
‪TYPO3\CMS\Core\Resource\Search\FileSearchQuery\createCountForSearchDemand
‪static FileSearchQuery createCountForSearchDemand(FileSearchDemand $searchDemand, QueryBuilder $queryBuilder=null)
Definition: FileSearchQuery.php:132
‪TYPO3\CMS\Core\Resource\Search\Result\FileSearchResult
Definition: FileSearchResult.php:28
‪TYPO3\CMS\Core\Resource\Search\FileSearchDemand
Definition: FileSearchDemand.php:24
‪TYPO3\CMS\Core\Resource\ResourceFactory
Definition: ResourceFactory.php:33
‪TYPO3\CMS\Core\Resource\File
Definition: File.php:23
‪TYPO3\CMS\Core\Resource\Search\Result\FileSearchResult\key
‪int key()
Definition: FileSearchResult.php:75
‪TYPO3\CMS\Core\Resource\Search\Result\FileSearchResult\$searchDemand
‪FileSearchQuery $searchDemand
Definition: FileSearchResult.php:31
‪TYPO3\CMS\Core\Resource\Search\Result\FileSearchResultInterface
Definition: FileSearchResultInterface.php:23
‪TYPO3\CMS\Core\Resource\Search\Result\FileSearchResult\count
‪int count()
Definition: FileSearchResult.php:50
‪TYPO3\CMS\Core\Resource\ResourceFactory\getFileObject
‪File getFileObject($uid, array $fileData=[])
Definition: ResourceFactory.php:399
‪TYPO3\CMS\Core\Resource\Search\Result\FileSearchResult\valid
‪bool valid()
Definition: FileSearchResult.php:103