‪TYPO3CMS  9.5
FolderRestriction.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 
21 
28 {
32  private ‪$folder;
33 
37  private ‪$recursive;
38 
39  public function ‪__construct(‪Folder ‪$folder, bool ‪$recursive)
40  {
41  $this->folder = ‪$folder;
42  $this->recursive = ‪$recursive;
43  $this->‪populateRestrictions();
44  }
45 
46  private function ‪populateRestrictions(): void
47  {
48  $storage = $this->folder->getStorage();
49  $this->‪add(new ‪StorageRestriction($storage));
50  if (!$this->recursive) {
51  $this->‪add($this->‪createFolderRestriction());
52  return;
53  }
54  if ($this->folder->getIdentifier() === $storage->getRootLevelFolder(false)->getIdentifier()) {
55  return;
56  }
57  if ($storage->hasHierarchicalIdentifiers()) {
59  } else {
60  $this->‪add($this->‪createFolderRestriction());
61  }
62  }
63 
65  {
66  return $this->recursive ? new ‪FolderIdentifierRestriction($this->folder->getIdentifier()) : new ‪FolderHashesRestriction([$this->folder->getHashedIdentifier()]);
67  }
68 
70  {
71  $hashedFolderIdentifiers[] = $this->folder->getHashedIdentifier();
72  if ($this->recursive) {
73  foreach ($this->folder->getSubfolders(0, 0, ‪Folder::FILTER_MODE_NO_FILTERS, true) as $subFolder) {
74  $hashedFolderIdentifiers[] = $subFolder->getHashedIdentifier();
75  }
76  }
77 
78  return new FolderHashesRestriction($hashedFolderIdentifiers);
79  }
80 }
‪TYPO3\CMS\Core\Resource\Search\QueryRestrictions\FolderRestriction\createHierarchicalFolderRestriction
‪createHierarchicalFolderRestriction()
Definition: FolderRestriction.php:62
‪TYPO3\CMS\Core\Resource\Search\QueryRestrictions\FolderHashesRestriction
Definition: FolderHashesRestriction.php:28
‪TYPO3\CMS\Core\Resource\Search\QueryRestrictions\StorageRestriction
Definition: StorageRestriction.php:27
‪TYPO3\CMS\Core\Database\Query\Restriction\QueryRestrictionInterface
Definition: QueryRestrictionInterface.php:25
‪TYPO3\CMS\Core\Resource\Search\QueryRestrictions\FolderIdentifierRestriction
Definition: FolderIdentifierRestriction.php:29
‪TYPO3\CMS\Core\Database\Query\Restriction\AbstractRestrictionContainer\add
‪QueryRestrictionContainerInterface add(QueryRestrictionInterface $restriction)
Definition: AbstractRestrictionContainer.php:81
‪TYPO3\CMS\Core\Resource\Folder
Definition: Folder.php:34
‪TYPO3\CMS\Core\Resource\Search\QueryRestrictions\FolderRestriction\createFolderRestriction
‪createFolderRestriction()
Definition: FolderRestriction.php:67
‪TYPO3\CMS\Core\Resource\Search\QueryRestrictions
Definition: ConsistencyRestriction.php:3
‪TYPO3\CMS\Core\Resource\Search\QueryRestrictions\FolderRestriction\__construct
‪__construct(Folder $folder, bool $recursive)
Definition: FolderRestriction.php:37
‪TYPO3\CMS\Core\Resource\Search\QueryRestrictions\FolderRestriction\$recursive
‪bool $recursive
Definition: FolderRestriction.php:35
‪TYPO3\CMS\Core\Resource\Search\QueryRestrictions\FolderRestriction\$folder
‪Folder $folder
Definition: FolderRestriction.php:31
‪TYPO3\CMS\Core\Database\Query\Restriction\AbstractRestrictionContainer
Definition: AbstractRestrictionContainer.php:26
‪TYPO3\CMS\Core\Resource\Folder\FILTER_MODE_NO_FILTERS
‪const FILTER_MODE_NO_FILTERS
Definition: Folder.php:64
‪TYPO3\CMS\Core\Resource\Search\QueryRestrictions\FolderRestriction
Definition: FolderRestriction.php:28
‪TYPO3\CMS\Core\Resource\Search\QueryRestrictions\FolderRestriction\populateRestrictions
‪populateRestrictions()
Definition: FolderRestriction.php:44