TuningController.php
9.54 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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
<?php
class TuningController extends NodeSiteController
{
/** @var TuningBrand[] */
private $_brands;
/** @var TuningRoot */
public $tuningRoot;
/** @var FeedbackForm */
public $feedbackForm;
/** @return TuningBrand[] */
public function getBrands()
{
if (!isset($this->_brands))
$this->_brands = TuningBrand::model()->with('i18n')->findAll(array(
'order' => 'rank asc',
'condition' => 'not t.hidden and tuning_root_id = ' . $this->getNode()->data_id,
));
return $this->_brands;
}
public function init()
{
parent::init();
$this->tuningRoot = TuningRoot::model()->with('i18n')->findByPk($this->getNode()->data_id);
$this->headerGalleryId = $this->tuningRoot->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->tuningRoot->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()
{
$brands = TuningBrand::model()->with('tuningModels', 'i18n')->findAll(array(
'order' => 'rank asc',
'condition' => 'not t.hidden and tuning_root_id = ' . $this->getNode()->data_id,
));
$this->_brands = $brands;
//$pageData = $this->loadStaticPage($this->id, $this->action->id);
$this->pageName = $this->tuningRoot->i18n->page_name;
$this->setSEOParams($this->tuningRoot->i18n->title, $this->tuningRoot->i18n->keywords, $this->tuningRoot->i18n->description);
// $this->setContacts($pageData['contacts']);
$this->setContacts(explode(',', $this->tuningRoot->contacts_data));
$this->render('index', array(
'brands' => $brands,
));
}
public function actionBrand($brand)
{
/** @var $currentBrand TuningBrand */
$currentBrand = TuningBrand::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->tuningRoot->contacts_data));
$models = TuningModel::model()->findAll(array(
'condition' => 'not t.hidden and t.tuning_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 TuningBrand */
$currentBrand = TuningBrand::model()->with('i18n')->findByAttributes(array(
'link' => $brand,
));
if (empty($currentBrand))
throw new CHttpException(404);
$this->sectionGalleryId = $currentBrand->gallery_id;
/** @var $currentModel TuningModel */
$currentModel = TuningModel::model()->with('i18n')->findByAttributes(array(
'link' => $model,
'tuning_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->tuningRoot->contacts_data));
$sets = TuningSet::model()->findAll(array(
'order'=>'t.rank asc, t.id desc',
'condition' => 'not t.hidden and t.tuning_model_id = :model_id',
'params' => array(
':model_id' => $currentModel->id
),
));
$currentModel->tuningSets;
$this->render('model', array(
'currentModel' => $currentModel,
'currentBrand' => $currentBrand,
'sets' => $sets,
));
}
public function actionView($brand, $model, $set)
{
/** @var $currentBrand TuningBrand */
$currentBrand = TuningBrand::model()->with('i18n')->findByAttributes(array(
'link' => $brand,
));
if (empty($currentBrand))
throw new CHttpException(404);
$this->sectionGalleryId = $currentBrand->gallery_id;
/** @var $currentModel TuningModel */
$currentModel = TuningModel::model()->with('i18n')->findByAttributes(array(
'link' => $model,
'tuning_brand_id' => $currentBrand->id,
));
if (empty($currentModel))
throw new CHttpException(404);
/** @var $currentSet TuningSet */
$currentSet = TuningSet::model()->with('i18n')->findByAttributes(array(
'link' => $set,
'tuning_model_id' => $currentModel->id,
));
if (empty($currentSet))
throw new CHttpException(404);
$this->pageName = $currentSet->i18n->page_name;
$this->setSEOParams($currentSet->i18n->title, $currentSet->i18n->keywords, $currentSet->i18n->description);
$this->setContacts(explode(',', $currentSet->contacts_data));
$this->setContacts(explode(',', $currentModel->contacts_data));
$this->setContacts(explode(',', $currentBrand->contacts_data));
$this->setContacts(explode(',', $this->tuningRoot->contacts_data));
$criteria = new CDbCriteria(array(
'alias' => 't',
'with' => array('i18n', 'tuningModel', 'tuningModel.tuningBrand'),
'order' => 't.rank desc, t.id asc',
'condition' => 'not t.hidden and t.id>:id and t.tuning_model_id = :model_id',
'limit' => '2',
'params' => array(':id' => $currentSet->id, ':model_id' => $currentModel->id),
));
$next = TuningSet::model()->findAll($criteria);
if (count($next) < 2) {
$criteria->limit = 2 - count($next);
$criteria->condition = 't.id<:id and t.tuning_model_id = :model_id';
$next += TuningSet::model()->findAll($criteria);
}
$criteria->order = 't.rank asc, t.id desc';
$criteria->condition = 'not t.hidden and t.id<:id and t.tuning_model_id = :model_id';
$criteria->limit = 2;
$prev = TuningSet::model()->findAll($criteria);
if (count($prev) < 2) {
$criteria->limit = 2 - count($prev);
$criteria->condition = 'not t.hidden and t.id>:id and t.tuning_model_id = :model_id';
$prev += TuningSet::model()->findAll($criteria);
}
if (count($next) > 0 && count($prev) > 0 && $next[0]->id == $prev[0]->id) $prev = array();
$this->render('view', array(
'currentSet' => $currentSet,
'currentModel' => $currentModel,
'currentBrand' => $currentBrand,
'prev' => $prev,
'next' => $next,
));
}
public function actionService($link)
{
/** @var $service TuningService */
$service = TuningService::model()->with('i18n')->findByAttributes(array(
'link' => $link,
));
if (empty($service))
throw new CHttpException(404);
$this->sectionGalleryId = $service->gallery_id;
$this->setContacts(explode(',', $service->contacts_data));
$this->setContacts(explode(',', $this->tuningRoot->contacts_data));
$this->pageName = $service->i18n->page_name;
$this->setSEOParams($service->i18n->title, $service->i18n->keywords, $service->i18n->description);
$this->render('service', array(
'service' => $service,
));
}
/** @return TuningService[] */
public function getServices()
{
return TuningService::model()->with('i18n')->findAll(array(
'order' => 'rank asc',
'condition'=>'not t.hidden',
));
}
}