‪TYPO3CMS  10.4
FileSearchResult.php
Go to the documentation of this file.
1 <?php
2 
3 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 
19 
25 
31 {
35  private ‪$searchDemand;
36 
40  private ‪$result;
41 
45  private ‪$resultCount;
46 
48  {
49  $this->searchDemand = ‪$searchDemand;
50  }
51 
56  public function ‪count(): int
57  {
58  if ($this->resultCount !== null) {
59  return ‪$this->resultCount;
60  }
61 
62  $this->resultCount = (int)‪FileSearchQuery::createCountForSearchDemand($this->searchDemand)->‪execute()->fetchColumn(0);
63 
64  return ‪$this->resultCount;
65  }
66 
71  public function ‪current(): ‪File
72  {
73  $this->‪initialize();
74  return ‪current($this->result);
75  }
76 
81  public function ‪key(): int
82  {
83  $this->‪initialize();
84  return ‪key($this->result);
85  }
86 
90  public function ‪next(): void
91  {
92  $this->‪initialize();
93  ‪next($this->result);
94  }
95 
99  public function ‪rewind(): void
100  {
101  $this->‪initialize();
102  reset($this->result);
103  }
104 
109  public function ‪valid(): bool
110  {
111  $this->‪initialize();
112  return ‪current($this->result) !== false;
113  }
114 
118  private function ‪initialize(): void
119  {
120  if ($this->result !== null) {
121  return;
122  }
123  $this->result = ‪FileSearchQuery::createForSearchDemand($this->searchDemand)->‪execute()->fetchAll();
124  $this->resultCount = ‪count($this->result);
125  $this->result = array_map(
126  function (array $fileRow) {
127  return GeneralUtility::makeInstance(ResourceFactory::class)->getFileObject($fileRow['uid'], $fileRow);
128  },
130  );
131  }
132 }
‪TYPO3\CMS\Core\Resource\Search\FileSearchQuery
Definition: FileSearchQuery.php:37
‪TYPO3\CMS\Core\Resource\Search\Result\FileSearchResult\initialize
‪initialize()
Definition: FileSearchResult.php:115
‪TYPO3\CMS\Core\Resource\Search\Result\FileSearchResult\current
‪File current()
Definition: FileSearchResult.php:68
‪TYPO3\CMS\Core\Resource\Search\Result\FileSearchResult\$result
‪array $result
Definition: FileSearchResult.php:38
‪TYPO3\CMS\Core\Resource\Search\FileSearchQuery\createForSearchDemand
‪static FileSearchQuery createForSearchDemand(FileSearchDemand $searchDemand, QueryBuilder $queryBuilder=null)
Definition: FileSearchQuery.php:66
‪TYPO3\CMS\Core\Resource\Search\Result\FileSearchResult\$searchDemand
‪FileSearchDemand $searchDemand
Definition: FileSearchResult.php:34
‪TYPO3\CMS\Core\Resource\Search\Result\FileSearchResult\__construct
‪__construct(FileSearchDemand $searchDemand)
Definition: FileSearchResult.php:44
‪TYPO3\CMS\Core\Resource\Search\Result\FileSearchResult\rewind
‪rewind()
Definition: FileSearchResult.php:96
‪TYPO3\CMS\Core\Resource\Search\Result
Definition: DriverFilteredSearchResult.php:18
‪TYPO3\CMS\Core\Resource\Search\Result\FileSearchResult\next
‪next()
Definition: FileSearchResult.php:87
‪TYPO3\CMS\Core\Resource\Search\Result\FileSearchResult\$resultCount
‪int $resultCount
Definition: FileSearchResult.php:42
‪TYPO3\CMS\Core\Resource\Search\FileSearchQuery\execute
‪execute()
Definition: FileSearchQuery.php:172
‪TYPO3\CMS\Core\Resource\Search\FileSearchQuery\createCountForSearchDemand
‪static FileSearchQuery createCountForSearchDemand(FileSearchDemand $searchDemand, QueryBuilder $queryBuilder=null)
Definition: FileSearchQuery.php:136
‪TYPO3\CMS\Core\Resource\Search\Result\FileSearchResult
Definition: FileSearchResult.php:31
‪TYPO3\CMS\Core\Resource\Search\FileSearchDemand
Definition: FileSearchDemand.php:26
‪TYPO3\CMS\Core\Resource\ResourceFactory
Definition: ResourceFactory.php:41
‪TYPO3\CMS\Core\Resource\File
Definition: File.php:24
‪TYPO3\CMS\Core\Resource\Search\Result\FileSearchResult\key
‪int key()
Definition: FileSearchResult.php:78
‪TYPO3\CMS\Core\Resource\Search\Result\FileSearchResultInterface
Definition: FileSearchResultInterface.php:25
‪TYPO3\CMS\Core\Resource\Search\Result\FileSearchResult\count
‪int count()
Definition: FileSearchResult.php:53
‪TYPO3\CMS\Core\Resource\Search\Result\FileSearchResult\valid
‪bool valid()
Definition: FileSearchResult.php:106
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46