NewsController.php
7.39 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
<?php
class NewsController extends NodeSiteController
{
/** @var NewsRoot */
public $newsRoot;
public function init()
{
parent::init();
$this->newsRoot = NewsRoot::model()->findByPk($this->getNode()->data_id);
$this->headerGalleryId = $this->newsRoot->header_gallery_id;
}
public function actionIndex()
{
$criteria = new CDbCriteria(array(
'order' => 'date desc',
'condition' => 'not newsCategory.hidden and not t.hidden and newsCategory.news_root_id = ' . $this->getNode()->data_id
));
$criteria->with = array('newsCategory');
$pages = new CPagination(News::model()->count());
$pages->pageSize = 10;
$pages->applyLimit($criteria);
$news = News::model()->with(array('i18n', 'newsCategory'))->findAll($criteria);
$this->pageName = $this->newsRoot->i18n->page_name;
$this->setSEOParams($this->newsRoot->i18n->title, $this->newsRoot->i18n->keywords, $this->newsRoot->i18n->description);
$this->setContacts(explode(',', $this->newsRoot->contacts_data));
$this->render('index', array(
'news' => $news,
'pages' => $pages,
));
}
public function actionCategory($link)
{
/** @var $category NewsCategory */
$category = NewsCategory::model()->findByAttributes(array(
'link' => $link,
'news_root_id' => $this->getNode()->data_id,
));
if (empty($category)) throw new CHttpException(404);
$this->sectionGalleryId = $category->gallery_id;
$criteria = new CDbCriteria(array(
'order' => 'date desc',
'condition' => 'not t.hidden and t.news_category_id=' . $category->id
));
$pages = new CPagination(News::model()->count($criteria));
$pages->pageSize = 10;
$pages->applyLimit($criteria);
$news = News::model()->with(array('i18n', 'newsCategory'))->findAll($criteria);
$this->setContacts(explode(',', $category->contacts_data));
$this->setContacts(explode(',', $this->newsRoot->contacts_data));
$this->pageName = $category->i18n->page_name;
$this->setSEOParams($category->i18n->title, $category->i18n->keywords, $category->i18n->description);
$this->render('index', array(
'category' => $category,
'news' => $news,
'pages' => $pages,
));
}
public function actionPublications($link)
{
/** @var $category NewsCategory */
$category = NewsCategory::model()->findByAttributes(array(
'link' => $link,
'news_root_id' => $this->getNode()->data_id,
));
if (empty($category)) throw new CHttpException(404);
$this->sectionGalleryId = $category->gallery_id;
$criteria = new CDbCriteria(array(
'order' => 'date desc',
'condition' => 'not t.hidden and t.news_category_id=' . $category->id
));
$pages = new CPagination(Publication::model()->count($criteria));
$pages->pageSize = 10;
$pages->applyLimit($criteria);
$publications = Publication::model()->with(array('i18n', 'newsCategory'))->findAll($criteria);
$this->setContacts(explode(',', $category->contacts_data));
$this->setContacts(explode(',', $this->newsRoot->contacts_data));
$this->pageName = $category->i18n->page_name;
$this->setSEOParams($category->i18n->title, $category->i18n->keywords, $category->i18n->description);
$this->render('publications', array(
'category' => $category,
'publications' => $publications,
'pages' => $pages,
));
}
public function actionPublication($link)
{
/** @var $publication News */
$publication = Publication::model()->findByAttributes(array(
'link' => $link,
));
if (empty($publication))
throw new CHttpException(404);
$this->sectionGalleryId = $publication->newsCategory->gallery_id;
$this->setContacts(explode(',', $publication->contacts_data));
$this->setContacts(explode(',', $publication->newsCategory->contacts_data));
$this->setContacts(explode(',', $this->newsRoot->contacts_data));
$this->pageName = $publication->i18n->page_name;
$this->setSEOParams($publication->i18n->title, $publication->i18n->keywords, $publication->i18n->description);
$this->render('publication', array(
'publication' => $publication,
'category' => $publication->newsCategory,
));
}
public function actionView($link)
{
/** @var $news News */
$news = News::model()->findByAttributes(array(
'link' => $link,
));
if (empty($news))
throw new CHttpException(404);
$this->sectionGalleryId = $news->newsCategory->gallery_id;
$this->setContacts(explode(',', $news->contacts_data));
$this->setContacts(explode(',', $news->newsCategory->contacts_data));
$this->setContacts(explode(',', $this->newsRoot->contacts_data));
$this->pageName = $news->i18n->page_name;
$this->setSEOParams($news->i18n->title, $news->i18n->keywords, $news->i18n->description);
$news->views += 1;
$news->save(false);
$this->render('view', array(
'news' => $news,
'category' => $news->newsCategory,
));
}
/** @return NewsCategory[] */
public function getNewsCategories()
{
return NewsCategory::model()->with('i18n')->findAll(array(
'order' => 'rank asc',
'condition' => 'not t.hidden',
));
}
/** @return News */
public function getPhotoFact()
{
return News::model()->with('i18n', 'newsCategory')->find(array('order' => 'rand()', 'condition' => 'newsCategory.type=3'));
}
/**
* @param int $limit
* @return News[]
*/
public function getPopularNews($limit = 3)
{
return News::model()->with('i18n', 'newsCategory')->findAll(array(
'order' => 'views desc',
'condition' => 'not t.hidden and not newsCategory.hidden and (newsCategory.type=1 or newsCategory.type=3)', 'limit' => $limit));
}
public function actionShow($link)
{
/** @var $category NewsCategory */
$category = NewsCategory::model()->findByAttributes(array(
'link' => $link,
'news_root_id' => $this->getNode()->data_id,
));
if (empty($category)) throw new CHttpException(404);
$this->sectionGalleryId = $category->gallery_id;
$criteria = new CDbCriteria(array(
'order' => 'date desc',
'condition' => 'news_category_id=' . $category->id
));
$pages = new CPagination(Show::model()->count($criteria));
$pages->pageSize = 8;
$pages->applyLimit($criteria);
$videos = Show::model()->with(array('i18n', 'newsCategory'))->findAll($criteria);
$this->setContacts(explode(',', $category->contacts_data));
$this->setContacts(explode(',', $this->newsRoot->contacts_data));
$this->pageName = $category->i18n->page_name;
$this->setSEOParams($category->i18n->title, $category->i18n->keywords, $category->i18n->description);
$this->render('show', array(
'category' => $category,
'videos' => $videos,
'pages' => $pages,
));
}
}