components.class.php 4.13 KB
Newer Older
Яков's avatar
first  
Яков committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?php
class catalogComponents extends sfComponents
{
    public function executeCatChildren(sfWebRequest $request)
    {
        if ($this->parentId)
        {
            $parentId = $this->parentId;
            $this->alias = $request->getParameter('alias');
            $this->childrens = Doctrine::getTable('Cat')->findByParentId($parentId);
        }
        else
        {
            return sfView::NONE;
        }

    }


    public function executeLeftMenu(sfWebRequest $request)
    {
        $this->path = $request->getPathInfo();

        $leftMenu = Doctrine_Query::create()
            ->from('cat c')
            //->leftJoin('c.Children ch')
            //->leftJoin('ch.Children ch_ch')
            //->leftJoin('ch_ch.Children ch_ch_ch')
            //->leftJoin('ch_ch_ch.Children ch_ch_ch_ch')
            ->where('c.parent_id is null')
            ->fetchArray();

        $this->menu = $leftMenu;

        $this->open = array();
        $alias = $request->getParameter('alias', null);

        $id = null;
        if ($alias != null)
        {
            $idByAlias = Doctrine::getTable('Cat')->findOneByAlias($alias);
            if ($idByAlias)
            {
                $id = $idByAlias->getId();
            }
        }

        if ($id == null && $alias != null)
        {
            $product = $product = Doctrine::getTable('Product')->findOneByAlias($alias);

            if ($product)
            {
                if (count($product->getCatProducts()) > 0)
                {
                    $id = $product->getCatProducts()->getFirst()->getId();
                }

            }

        }

        if ($id != null)
        {
            $relations = Doctrine_Query::create()
                ->from('catParent cp')
                ->where('cp.cat_id = ?', $id)
                ->fetchArray();

            $ids[] = $id;
            if ($relations)
            {
                foreach ($relations as $relation)
                {
                    $ids[] = $relation['parent_id'];
                }

            }

            $this->open = $ids;
        }



    }
    public function executeLkLeftMenu(sfWebRequest $request)
    {
        $this->path = $request->getPathInfo();

        if ($request->hasParameter('orderId'))
        {
            $this->path = '/personal/profile/';
        }

        $this->links = array(
            array(
                'url' => url_for('@personal_profile'),
                'anchor' => 'История заказов'
            ),

            array(
                'url' => url_for('@personal_profile_settings'),
                'anchor' => 'Настройки профиля'
            ),

            array(
                'url' => url_for('@personal_profile_feedback'),
                'anchor' => 'Обратная связь'
            )
        );


    }
    public function executeFilter(sfWebRequest $request)
    {
        if($this->cat->getIsFilter() && count($this->product_ids) > 0){
            $this->culture = $this->getUser()->getCulture();
            $this->lists = Doctrine_Query::create()
                ->select("v.id, v.product_id, v.prop_id, v.value, p.id, p.isList, pt.*, l.id, l.product_prop_id, lt.*")
                ->from("ProductProp p")
                ->innerJoin("p.Translation pt WITH pt.lang = '" . $this->culture . "'")
                ->innerJoin("p.ProductPropList l")
                ->innerJoin("l.Translation lt WITH lt.lang = '" . $this->culture . "'")
                ->innerJoin("p.ProductPropValue v")
                ->whereIn("v.product_id", $this->product_ids)
                ->andWhere("p.isList = 1")
                ->andWhere("l.id = v.value")
                ->fetchArray();
            $this->values = Doctrine_Query::create()
                ->select("v.id, v.product_id, v.prop_id, v.value, MIN(v.value) AS min, MAX(v.value) AS max, p.id, p.isList, t.*")
                ->from("ProductPropValue v")
                ->innerJoin("v.ProductProp p")
                ->innerJoin("p.Translation t WITH t.lang = '" . $this->culture . "'")
                ->whereIn("v.id", $this->product_ids)
                ->groupBy("v.prop_id")
                ->fetchArray();
        }
    }
}