Quellcode durchsuchen

add the OtPageRepository::getPagesByPid method

Olivier Massot vor 4 Jahren
Ursprung
Commit
a5560b4d68
1 geänderte Dateien mit 21 neuen und 12 gelöschten Zeilen
  1. 21 12
      ot_core/Classes/Page/OtPageRepository.php

+ 21 - 12
ot_core/Classes/Page/OtPageRepository.php

@@ -50,6 +50,26 @@ class OtPageRepository
         $this->siteFinder = $siteFinder;
     }
 
+    /**
+     * Returns all the subpages of the given page
+     *
+     * @param int $pid The uid of the parent page
+     * @param bool $withRestrictions Set to true to add the standard restrictions (deleted, forbidden...etc.)
+     * @return array
+     */
+    public function getPagesByPid($pid, bool $withRestrictions=false) {
+        $queryBuilder = $this->connectionPool->getQueryBuilderForTable('pages');
+        if (!$withRestrictions) {
+            $queryBuilder->getRestrictions()->removeAll();
+        }
+        return $queryBuilder
+            ->select('*')
+            ->from('pages')
+            ->where($queryBuilder->expr()->eq('pid', $pid))
+            ->execute()
+            ->fetchAll();
+    }
+
     /**
      * Returns the root page of the given page website,
      * or the page itself if the given page is
@@ -60,7 +80,6 @@ class OtPageRepository
      * @return array
      */
     public function getRootPageFor($pageUid) {
-//        $pageService = GeneralUtility::makeInstance(ObjectManager::class)->get(PageService::class);
         $rootLine = $this->pageService->getRootLine($pageUid);
 
         for (end($rootLine); key($rootLine)!==null; prev($rootLine)){
@@ -83,17 +102,7 @@ class OtPageRepository
     public function getAllSubpagesForPage(int $pageUid, bool $withRestrictions=false) {
         $subpages = [];
 
-        $queryBuilder = $this->connectionPool->getQueryBuilderForTable('pages');
-
-        if (!$withRestrictions) {
-            $queryBuilder->getRestrictions()->removeAll();
-        }
-        $stack = $queryBuilder
-            ->select('*')
-            ->from('pages')
-            ->where($queryBuilder->expr()->eq('pid', $pageUid))
-            ->execute()
-            ->fetchAll();
+        $stack = $this->getPagesByPid($pageUid, $withRestrictions);
 
         foreach ($stack as $page) {
             $subpages[] = $page;