‪TYPO3CMS  11.5
PagesRepository.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 
26 
33 {
34  protected const ‪TABLE = 'pages';
35 
42  public function ‪doesRootLineContainHiddenPages(array $pageInfo): bool
43  {
44  $pid = (int)($pageInfo['pid'] ?? 0);
45  if ($pid === 0) {
46  return false;
47  }
48  $isHidden = (bool)($pageInfo['hidden']);
49  $extendToSubpages = (bool)($pageInfo['extendToSubpages']);
50 
51  if ($extendToSubpages === true && $isHidden === true) {
52  return true;
53  }
54 
55  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
56  ->getQueryBuilderForTable(self::TABLE);
57  $queryBuilder->getRestrictions()->removeAll();
58 
59  $row = $queryBuilder
60  ->select('uid', 'title', 'hidden', 'extendToSubpages')
61  ->from(self::TABLE)
62  ->where(
63  $queryBuilder->expr()->eq(
64  'uid',
65  $queryBuilder->createNamedParameter($pid, ‪Connection::PARAM_INT)
66  )
67  )
68  ->executeQuery()
69  ->fetchAssociative();
70 
71  if ($row !== false) {
72  return $this->‪doesRootLineContainHiddenPages($row);
73  }
74  return false;
75  }
76 
89  public function ‪getAllSubpagesForPage(
90  int $id,
91  int $depth,
92  string $permsClause,
93  bool $considerHidden = false
94  ): array {
95  $subPageIds = [];
96  if ($depth === 0) {
97  return $subPageIds;
98  }
99 
100  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
101  ->getQueryBuilderForTable(self::TABLE);
102  $queryBuilder->getRestrictions()
103  ->removeAll()
104  ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
105 
106  $result = $queryBuilder
107  ->select('uid', 'title', 'hidden', 'extendToSubpages')
108  ->from(self::TABLE)
109  ->where(
110  $queryBuilder->expr()->eq(
111  'pid',
112  $queryBuilder->createNamedParameter($id, ‪Connection::PARAM_INT)
113  ),
115  )
116  ->executeQuery();
117 
118  while ($row = $result->fetchAssociative()) {
119  $subpageId = (int)$row['uid'];
120  $isHidden = (bool)$row['hidden'];
121  if (!$isHidden || $considerHidden) {
122  $subPageIds[] = $subpageId;
123  }
124  if ($depth > 1 && (!($isHidden && $row['extendToSubpages'] == 1) || $considerHidden)) {
125  $subPageIds = array_merge($subPageIds, $this->‪getAllSubpagesForPage(
126  $subpageId,
127  $depth - 1,
128  $permsClause,
129  $considerHidden
130  ));
131  }
132  }
133  return $subPageIds;
134  }
135 
147  public function ‪getTranslationForPage(
148  int $currentPage,
149  string $permsClause,
150  bool $considerHiddenPages,
151  array $limitToLanguageIds = []
152  ): array {
153  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable(self::TABLE);
154  $queryBuilder->getRestrictions()
155  ->removeAll()
156  ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
157  if (!$considerHiddenPages) {
158  $queryBuilder->getRestrictions()->add(GeneralUtility::makeInstance(HiddenRestriction::class));
159  }
160  $constraints = [
161  $queryBuilder->expr()->eq(
162  'l10n_parent',
163  $queryBuilder->createNamedParameter($currentPage, ‪Connection::PARAM_INT)
164  ),
165  ];
166  if (!empty($limitToLanguageIds)) {
167  $constraints[] = $queryBuilder->expr()->in(
168  'sys_language_uid',
169  $queryBuilder->createNamedParameter($limitToLanguageIds, Connection::PARAM_INT_ARRAY)
170  );
171  }
172  if ($permsClause) {
173  $constraints[] = ‪QueryHelper::stripLogicalOperatorPrefix($permsClause);
174  }
175 
176  $result = $queryBuilder
177  ->select('uid', 'title', 'hidden')
178  ->from(self::TABLE)
179  ->where(...$constraints)
180  ->executeQuery();
181 
182  $translatedPages = [];
183  while ($row = $result->fetchAssociative()) {
184  $translatedPages[] = (int)$row['uid'];
185  }
186 
187  return $translatedPages;
188  }
189 }
‪TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction
Definition: HiddenRestriction.php:27
‪TYPO3\CMS\Linkvalidator\Repository\PagesRepository\getAllSubpagesForPage
‪int[] getAllSubpagesForPage(int $id, int $depth, string $permsClause, bool $considerHidden=false)
Definition: PagesRepository.php:89
‪TYPO3\CMS\Core\Database\Connection\PARAM_INT
‪const PARAM_INT
Definition: Connection.php:49
‪TYPO3\CMS\Linkvalidator\Repository\PagesRepository\getTranslationForPage
‪int[] getTranslationForPage(int $currentPage, string $permsClause, bool $considerHiddenPages, array $limitToLanguageIds=[])
Definition: PagesRepository.php:147
‪TYPO3\CMS\Linkvalidator\Repository\PagesRepository
Definition: PagesRepository.php:33
‪TYPO3\CMS\Linkvalidator\Repository\PagesRepository\doesRootLineContainHiddenPages
‪bool doesRootLineContainHiddenPages(array $pageInfo)
Definition: PagesRepository.php:42
‪TYPO3\CMS\Linkvalidator\Repository\PagesRepository\TABLE
‪const TABLE
Definition: PagesRepository.php:34
‪TYPO3\CMS\Core\Database\Query\QueryHelper
Definition: QueryHelper.php:32
‪TYPO3\CMS\Core\Database\Connection
Definition: Connection.php:38
‪TYPO3\CMS\Core\Database\Query\QueryHelper\stripLogicalOperatorPrefix
‪static string stripLogicalOperatorPrefix(string $constraint)
Definition: QueryHelper.php:171
‪TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction
Definition: DeletedRestriction.php:28
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Linkvalidator\Repository
Definition: BrokenLinkRepository.php:18