Passed
Branch main (a47c5a)
by AOEPeople
15:53 queued 02:59
created

getContentElementsPIDs()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 10
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 18
rs 9.9332
1
<?php
2
3
/***************************************************************
4
 *  Copyright notice
5
 *
6
 *  (c) 2020 AOE GmbH <[email protected]>
7
 *
8
 *  All rights reserved
9
 *
10
 *  This script is part of the TYPO3 project. The TYPO3 project is
11
 *  free software; you can redistribute it and/or modify
12
 *  it under the terms of the GNU General Public License as published by
13
 *  the Free Software Foundation; either version 3 of the License, or
14
 *  (at your option) any later version.
15
 *
16
 *  The GNU General Public License can be found at
17
 *  http://www.gnu.org/copyleft/gpl.html.
18
 *
19
 *  This script is distributed in the hope that it will be useful,
20
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
21
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
 *  GNU General Public License for more details.
23
 *
24
 *  This copyright notice MUST APPEAR in all copies of the script!
25
 ***************************************************************/
26
27
use TYPO3\CMS\Core\Database\Connection;
28
use TYPO3\CMS\Core\Database\ConnectionPool;
29
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
30
use TYPO3\CMS\Core\Utility\GeneralUtility;
31
32
/**
33
 * Class Tx_FeatureFlag_System_Db_FeatureFlagData
34
 */
35
class Tx_FeatureFlag_System_Db_FeatureFlagData
36
{
37
    /**
38
     * @var string
39
     */
40
    const TABLE_MAPPING = 'tx_featureflag_domain_model_mapping';
41
42
    /**
43
     * @var string
44
     */
45
    const TABLE_FLAGS = 'tx_featureflag_domain_model_featureflag';
46
47
    /**
48
     * @param string $table
49
     * @param integer $behavior
50
     * @param integer $enabled
51
     *
52
     * @return array
53
     */
54
    public function getContentElements($table, $behavior, $enabled)
55
    {
56
        /** @var QueryBuilder $queryBuilder */
57
        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
58
            ->getQueryBuilderForTable($table);
59
60
        $queryBuilder->getRestrictions()->removeAll();
61
62
        $queryBuilder
63
            ->select($table . '.uid')
64
            ->from($table)
65
            ->from(self::TABLE_MAPPING)
66
            ->from(self::TABLE_FLAGS)
67
            ->where(
68
                $queryBuilder->expr()->andX(
69
                    $queryBuilder->expr()->eq(
70
                        self::TABLE_MAPPING . '.feature_flag',
71
                        self::TABLE_FLAGS . '.uid'
72
                    ),
73
                    $queryBuilder->expr()->eq(
74
                        $table . '.uid',
75
                        self::TABLE_MAPPING . '.foreign_table_uid'
76
                    ),
77
                    $queryBuilder->expr()->eq(
78
                        self::TABLE_FLAGS . '.enabled',
79
                        $queryBuilder->createNamedParameter($enabled, Connection::PARAM_INT)
80
                    ),
81
                    $queryBuilder->expr()->eq(
82
                        self::TABLE_MAPPING . '.foreign_table_name',
83
                        $queryBuilder->createNamedParameter($table, Connection::PARAM_STR)
84
                    ),
85
                    $queryBuilder->expr()->eq(
86
                        self::TABLE_MAPPING . '.behavior',
87
                        $queryBuilder->createNamedParameter($behavior, Connection::PARAM_INT)
88
                    )
89
                )
90
            );
91
92
        return $queryBuilder->execute()->fetchAll();
93
    }
94
95
    /**
96
     * @param string $table
97
     * @param array $uids
98
     * @param bool $isVisible
99
     */
100
    public function updateContentElements($table, array $uids, $isVisible)
101
    {
102
        /** @var QueryBuilder $queryBuilder */
103
        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
104
            ->getQueryBuilderForTable($table);
105
106
        $queryBuilder->getRestrictions()->removeAll();
107
108
        $query = $queryBuilder
109
            ->update($table)
110
            ->set('hidden', $isVisible === true ? 0 : 1)
111
            ->add('where', $queryBuilder->expr()->in('uid', $uids));
112
113
        $query->execute();
114
    }
115
116
    /**
117
     * @param string $table
118
     * @param integer $uid
119
     *
120
     * @return string
121
     */
122
    public function getContentElementsPIDs($table, $uid)
123
    {
124
        /** @var QueryBuilder $queryBuilder */
125
        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
126
            ->getQueryBuilderForTable($table);
127
128
        $queryBuilder->getRestrictions()->removeAll();
129
130
        $query = $queryBuilder
131
            ->select($table . '.pid')
132
            ->from($table)
133
            ->where(
134
                $queryBuilder->expr()->eq(
135
                    $table . '.uid', $queryBuilder->createNamedParameter($uid, Connection::PARAM_INT)
136
                )
137
            );
138
139
        return $query->execute()->fetchColumn(0);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $query->execute()->fetchColumn(0) could also return false which is incompatible with the documented return type string. Did you maybe forget to handle an error condition?

If the returned type also contains false, it is an indicator that maybe an error condition leading to the specific return statement remains unhandled.

Loading history...
140
    }
141
}
142