Passed
Push — development ( 435767...020ac0 )
by Ivan
07:58
created

CategoryNodeEcondaQuery::prepareQuery()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 48
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 0
dl 0
loc 48
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace SprykerEco\Zed\Econda\Persistence\Storage\Pdo\PostgreSql;
9
10
use SprykerEco\Zed\Econda\Persistence\Econda\AbstractEcondaPdoQuery;
11
12
class CategoryNodeEcondaQuery extends AbstractEcondaPdoQuery
13
{
14
    /**
15
     * @return void
16
     */
17
    protected function prepareQuery(): void
18
    {
19
        $sql = '
20
 WITH RECURSIVE
21
     tree AS
22
   (
23
     SELECT
24
       n.id_category_node,
25
       n.fk_parent_category_node,
26
       n.fk_category,
27
       n.node_order
28
     FROM spy_category_node n
29
       INNER JOIN spy_category c ON c.id_category = n.fk_category AND c.is_active = TRUE
30
     WHERE n.is_root = TRUE
31
32
     UNION
33
34
     SELECT
35
       n.id_category_node,
36
       n.fk_parent_category_node,
37
       n.fk_category,
38
       n.node_order
39
     FROM tree
40
       INNER JOIN spy_category_node n ON n.fk_parent_category_node = tree.id_category_node
41
       INNER JOIN spy_category c ON c.id_category = n.fk_category AND c.is_active = TRUE
42
   )
43
 SELECT
44
   tree.*,
45
   u.url,
46
   ca.name,
47
   ca.meta_title,
48
   ca.meta_description,
49
   ca.meta_keywords,
50
   ca.category_image_name,
51
   \'\' AS "children",
52
   \'\' AS "parents"
53
 FROM tree
54
   INNER JOIN spy_url u ON (u.fk_resource_categorynode = tree.id_category_node AND u.fk_locale = :fk_locale_1)
55
   INNER JOIN spy_category_attribute ca ON (ca.fk_category = tree.fk_category AND ca.fk_locale = :fk_locale_2)
56
';
57
        $this->criteriaBuilder
58
            ->sql($sql)
59
            ->setOrderBy([
60
                'tree.fk_parent_category_node' => 'ASC',
61
                'tree.node_order' => 'DESC',
62
            ])
63
            ->setParameter('fk_locale_1', $this->locale->getIdLocale())
64
            ->setParameter('fk_locale_2', $this->locale->getIdLocale());
65
    }
66
}
67