Passed
Push — master ( e7cae8...5047e3 )
by Peter
02:30
created

PageCategoryAuthLoader::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Website\Databases\Queries;
6
7
use AbterPhp\Framework\Databases\Queries\IAuthLoader;
8
use Opulence\Databases\ConnectionPools\ConnectionPool;
9
use Opulence\QueryBuilders\MySql\QueryBuilder;
10
11
class PageCategoryAuthLoader implements IAuthLoader
12
{
13
    /** @var ConnectionPool */
14
    protected $connectionPool;
15
16
    /**
17
     * BlockCache constructor.
18
     *
19
     * @param ConnectionPool $connectionPool
20
     */
21
    public function __construct(ConnectionPool $connectionPool)
22
    {
23
        $this->connectionPool = $connectionPool;
24
    }
25
26
    /**
27
     * @return array|bool
28
     */
29
    public function loadAll()
30
    {
31
        $query = (new QueryBuilder())
32
            ->select('ug.identifier AS v0', 'pc.identifier AS v1')
33
            ->from('user_groups_page_categories', 'ugpc')
34
            ->innerJoin('page_categories', 'pc', 'ugpc.page_category_id = pc.id AND pc.deleted = 0')
35
            ->innerJoin('user_groups', 'ug', 'ugpc.user_group_id = ug.id AND ug.deleted = 0')
36
        ;
37
38
        $connection = $this->connectionPool->getReadConnection();
39
        $statement  = $connection->prepare($query->getSql());
40
        $statement->bindValues($query->getParameters());
41
        if (!$statement->execute()) {
42
            return true;
43
        }
44
45
        return $statement->fetchAll(\PDO::FETCH_ASSOC);
46
    }
47
}
48