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