Passed
Push — typo3_11 ( 273487...f34284 )
by Torben
08:59 queued 06:04
created

PageUtility::extendPidListByChildren()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 9
c 1
b 0
f 0
nc 4
nop 2
dl 0
loc 16
rs 9.9666
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Extension "sf_event_mgt" for TYPO3 CMS.
7
 *
8
 * For the full copyright and license information, please read the
9
 * LICENSE.txt file that was distributed with this source code.
10
 */
11
12
namespace DERHANSEN\SfEventMgt\Utility;
13
14
use TYPO3\CMS\Core\Utility\GeneralUtility;
15
16
/**
17
 * Page
18
 */
19
class PageUtility
20
{
21
    /**
22
     * Find all ids from given ids and level
23
     *
24
     * @param string $pidList comma separated list of ids
25
     * @param int $recursive recursive levels
26
     * @return string comma separated list of ids
27
     */
28
    public static function extendPidListByChildren(string $pidList = '', int $recursive = 0): string
29
    {
30
        if ($recursive <= 0) {
31
            return $pidList;
32
        }
33
34
        $recursiveStoragePids = $pidList;
35
        $storagePids = GeneralUtility::intExplode(',', $pidList);
36
        foreach ($storagePids as $startPid) {
37
            $pids = self::getTreeList($startPid, $recursive);
38
            if (strlen((string)$pids) > 0) {
39
                $recursiveStoragePids .= ',' . $pids;
40
            }
41
        }
42
43
        return $recursiveStoragePids;
44
    }
45
46
    /**
47
     * Recursively fetch all descendants of a given page
48
     *
49
     * @param int $id uid of the page
50
     * @param int $depth
51
     * @param int $begin
52
     * @param string $permClause
53
     * @return string comma separated list of descendant pages
54
     */
55
    protected static function getTreeList(int $id, int $depth, int $begin = 0, $permClause = '')
56
    {
57
        if ($id < 0) {
58
            $id = abs($id);
59
        }
60
        if ($begin === 0) {
61
            $theList = $id;
62
        } else {
63
            $theList = '';
64
        }
65
        if ($id && $depth > 0) {
66
            $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
0 ignored issues
show
Bug introduced by
The type DERHANSEN\SfEventMgt\Utility\ConnectionPool was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
67
            $queryBuilder->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
0 ignored issues
show
Bug introduced by
The type DERHANSEN\SfEventMgt\Utility\DeletedRestriction was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
68
            $queryBuilder->select('uid')
69
                ->from('pages')
70
                ->where(
71
                    $queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($id, \PDO::PARAM_INT)),
72
                    $queryBuilder->expr()->eq('sys_language_uid', 0)
73
                )
74
                ->orderBy('uid');
75
            if ($permClause !== '') {
76
                $queryBuilder->andWhere(QueryHelper::stripLogicalOperatorPrefix($permClause));
0 ignored issues
show
Bug introduced by
The type DERHANSEN\SfEventMgt\Utility\QueryHelper was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
77
            }
78
            $statement = $queryBuilder->execute();
79
            while ($row = $statement->fetch()) {
80
                if ($begin <= 0) {
81
                    $theList .= ',' . $row['uid'];
82
                }
83
                if ($depth > 1) {
84
                    $theSubList = self::getTreeList((int)$row['uid'], $depth - 1, $begin - 1, $permClause);
85
                    if (!empty($theList) && !empty($theSubList) && ($theSubList[0] !== ',')) {
86
                        $theList .= ',';
87
                    }
88
                    $theList .= $theSubList;
89
                }
90
            }
91
        }
92
        return $theList;
93
    }
94
}
95