WorkController.php
7.75 KB
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<?php
class WorkController extends NodeSiteController
{
/** @var WorkRoot */
public $workRoot;
/** @var WorkBrand[] */
private $_brands;
/** @var WorkModel[] */
private $_models;
/** @var FeedbackForm */
public $feedbackForm;
/** @return WorkBrand[] */
public function getBrands()
{
if (!isset($this->_brands))
$this->_brands = WorkBrand::model()->with('i18n')->findAll(array(
'index'=>'id',
'order'=>'rank asc',
'condition'=>'not t.hidden and work_root_id = '.$this->getNode()->data_id,
));
return $this->_brands;
}
/** @return WorkModel[] */
public function getModels()
{
if (!isset($this->_models))
$this->_models = WorkModel::model()->with('i18n')->findAll(array(
'index'=>'id',
'condition'=>'not t.hidden',
));
return $this->_models;
}
public function init()
{
parent::init();
/** @var $sectionData StaticData */
$this->workRoot = WorkRoot::model()->with('i18n')->findByPk($this->getNode()->data_id);
$this->headerGalleryId = $this->workRoot->header_gallery_id;
$this->feedbackForm = new FeedbackForm();
if (isset($_POST['FeedbackForm'])) {
Yii::app()->request->validateCsrfToken(null);
$this->feedbackForm->setAttributes($_POST['FeedbackForm']);
if ($this->feedbackForm->validate()&&empty($this->feedbackForm->link)) {
/** @var $mailer Swift_Mailer */
$mailer = Yii::app()->swiftMailer->getMailer();
$message = Swift_Message::newInstance();
$message->setReplyTo($this->feedbackForm->email);
$message->setFrom('site@auto-life.ua');
$message->setTo($this->workRoot->feedback_email);
$message->setSubject('Вопрос, c раздела “наши работи” сайта Авто-лайф');
$message->setBody(
"Имя: {$this->feedbackForm->name}\r\n" .
"E-Mail: {$this->feedbackForm->email}\r\n" .
"Контактный номер: {$this->feedbackForm->phone}\r\n" .
"Текст вопроса: {$this->feedbackForm->body}\r\n");
$mailer->send($message);
Yii::app()->user->setFlash('contact', Yii::t('site', 'Спасибо что написали. Мы свяжесся с вами как только сможем'));
$this->refresh();
}
}
}
public function actionIndex()
{
$this->pageName = $this->workRoot->i18n->page_name;
$this->setSEOParams($this->workRoot->i18n->title, $this->workRoot->i18n->keywords, $this->workRoot->i18n->description);
$brands = WorkBrand::model()->with('workModels', 'i18n')->findAll(array(
'index'=>'id',
'order'=>'rank asc',
'condition'=>'not t.hidden and work_root_id = '.$this->getNode()->data_id,
));
$this->_brands = $brands;
/** @var $page StaticPage */
$this->setContacts(explode(',',$this->workRoot->contacts_data));
$this->render('index', array(
'brands' => $brands,
));
}
public function actionBrand($brand)
{
/** @var $currentBrand WorkBrand */
$currentBrand = WorkBrand::model()->with('i18n')->findByAttributes(array(
'link' => $brand,
));
if (empty($currentBrand))
throw new CHttpException(404);
$this->sectionGalleryId = $currentBrand->gallery_id;
$this->pageName = $currentBrand->i18n->page_name;
$this->setSEOParams($currentBrand->i18n->title, $currentBrand->i18n->keywords, $currentBrand->i18n->description);
$this->setContacts(explode(',',$currentBrand->contacts_data));
$this->setContacts(explode(',',$this->workRoot->contacts_data));
// $models = $currentBrand->workModels;
$models= WorkModel::model()->findAll(array(
'condition'=>'not t.hidden and work_brand_id = :brand_id',
'params'=>array(
':brand_id'=>$currentBrand->id,
)
));
$this->render('brand', array(
'currentBrand' => $currentBrand,
'models' => $models,
));
}
public function actionModel($brand, $model)
{
/** @var $currentBrand WorkBrand */
$currentBrand = WorkBrand::model()->with('i18n')->findByAttributes(array(
'link' => $brand,
));
if (empty($currentBrand))
throw new CHttpException(404);
$this->sectionGalleryId = $currentBrand->gallery_id;
/** @var $currentModel WorkModel */
$currentModel = WorkModel::model()->with('i18n')->findByAttributes(array(
'link' => $model,
'work_brand_id' => $currentBrand->id,
));
if (empty($currentModel))
throw new CHttpException(404);
if($currentModel->headerGalleryBehavior->getGalleryPhotoCount()>0){
$this->sectionGalleryId = $currentModel->header_gallery_id;
}
$this->pageName = $currentModel->i18n->page_name;
$this->setSEOParams($currentModel->i18n->title, $currentModel->i18n->keywords, $currentModel->i18n->description);
$this->setContacts(explode(',',$currentModel->contacts_data));
$this->setContacts(explode(',',$currentBrand->contacts_data));
$this->setContacts(explode(',',$this->workRoot->contacts_data));
// $works = $currentModel->works;
$works= Work::model()->findAll(array(
'condition'=>'not t.hidden and work_model_id = :model_id',
'order'=>'date desc',
'params'=>array(
':model_id'=>$currentModel->id,
)
));
$this->render('model', array(
'currentModel' => $currentModel,
'currentBrand' => $currentBrand,
'works' => $works,
));
}
public function actionView($brand, $model, $set)
{
/** @var $currentBrand WorkBrand */
$currentBrand = WorkBrand::model()->with('i18n')->findByAttributes(array(
'link' => $brand,
));
if (empty($currentBrand))
throw new CHttpException(404);
$this->sectionGalleryId = $currentBrand->gallery_id;
/** @var $currentModel WorkModel */
$currentModel = WorkModel::model()->with('i18n')->findByAttributes(array(
'link' => $model,
'work_brand_id' => $currentBrand->id,
));
if (empty($currentModel))
throw new CHttpException(404);
/** @var $currentWork Work */
$currentWork = Work::model()->with('i18n')->findByAttributes(array(
'link' => $set,
'work_model_id' => $currentModel->id,
));
if (empty($currentWork))
throw new CHttpException(404);
$this->pageName = $currentWork->i18n->page_name;
$this->setSEOParams($currentWork->i18n->title, $currentWork->i18n->keywords, $currentWork->i18n->description);
$this->setContacts(explode(',',$currentWork->contacts_data));
$this->setContacts(explode(',',$currentModel->contacts_data));
$this->setContacts(explode(',',$currentBrand->contacts_data));
$this->setContacts(explode(',',$this->workRoot->contacts_data));
$this->render('view', array(
'currentWork' => $currentWork,
'currentModel' => $currentModel,
'currentBrand' => $currentBrand,
));
}
/** @return TuningService[] */
public function getServices()
{
return array(); //TuningService::model()->with('i18n')->findAll(array('order' => 'rank asc'));
}
}