1
|
|
|
<?php
|
2
|
|
|
|
3
|
|
|
class CategoriesController extends CiiController
|
|
|
|
|
4
|
|
|
{
|
5
|
|
|
/**
|
6
|
|
|
* Base filter, allows logged in and non-logged in users to cache the page
|
7
|
|
|
*/
|
8
|
|
|
public function filters()
|
9
|
|
|
{
|
10
|
|
|
$id = Yii::app()->getRequest()->getQuery('id');
|
11
|
|
|
|
12
|
|
|
if ($id == NULL || $id === false)
|
13
|
|
|
throw new CHttpException(400, Yii::t('ciims.controllers.Categories', 'Invalid routing'));
|
14
|
|
|
|
15
|
|
|
return CMap::mergeArray(parent::filters(), array(
|
16
|
|
|
array(
|
17
|
|
|
'CHttpCacheFilter + index',
|
18
|
|
|
'cacheControl'=>Cii::get(Yii::app()->user->id) == NULL ? 'public' : 'private' .', no-cache, must-revalidate',
|
19
|
|
|
'etagSeed'=>$id
|
20
|
|
|
),
|
21
|
|
|
array(
|
22
|
|
|
'COutputCache + list',
|
23
|
|
|
'duration' => YII_DEBUG ? 1 : 86400,
|
24
|
|
|
'varyByParam' => array('page'),
|
25
|
|
|
'varyByLanguage' => true,
|
26
|
|
|
'dependency' => array(
|
27
|
|
|
'class'=>'CDbCacheDependency',
|
28
|
|
|
'sql'=>'SELECT MAX(updated) FROM content WHERE category_id = :id',
|
29
|
|
|
'params' => array(':id' => $id)
|
30
|
|
|
)
|
31
|
|
|
),
|
32
|
|
|
array(
|
33
|
|
|
'COutputCache + rss',
|
34
|
|
|
'duration' => YII_DEBUG ? 1 : 86400,
|
35
|
|
|
'dependency' => array(
|
36
|
|
|
'class'=>'CDbCacheDependency',
|
37
|
|
|
'sql'=>'SELECT MAX(updated) FROM content WHERE category_id = :id',
|
38
|
|
|
'params' => array(':id' => $id)
|
39
|
|
|
)
|
40
|
|
|
)
|
41
|
|
|
));
|
42
|
|
|
}
|
43
|
|
|
|
44
|
|
|
/**
|
45
|
|
|
* Handles all incoming requests for the entire site that are not previous defined in CUrlManager
|
46
|
|
|
* Requests come in, are verified, and then pulled from the database dynamically
|
47
|
|
|
* Shows all blog posts for a particular category_id
|
48
|
|
|
* @param $id - The content ID that we want to pull from the database
|
49
|
|
|
**/
|
50
|
|
|
public function actionIndex($id=NULL)
|
51
|
|
|
{
|
52
|
|
|
// Run a pre check of our data
|
53
|
|
|
$this->beforeCiiAction($id);
|
54
|
|
|
|
55
|
|
|
// Retrieve the data
|
56
|
|
|
$category = Categories::model()->findByPk($id);
|
57
|
|
|
|
58
|
|
|
// Set the layout
|
59
|
|
|
$this->setLayout('default');
|
60
|
|
|
|
61
|
|
|
$this->setPageTitle(Yii::t('ciims.controllers.Categories', '{{app_name}} | {{label}}', array(
|
62
|
|
|
'{{app_name}}' => Cii::getConfig('name', Yii::app()->name),
|
63
|
|
|
'{{label}}' => $category->name
|
64
|
|
|
)));
|
65
|
|
|
|
66
|
|
|
$pageSize = Cii::getConfig('categoryPaginationSize', 10);
|
67
|
|
|
|
68
|
|
|
$criteria = Content::model()
|
69
|
|
|
->getBaseCriteria()
|
70
|
|
|
->addCondition('type_id >= 2')
|
71
|
|
|
->addCondition("category_id = " . $id)
|
|
|
|
|
72
|
|
|
->addCondition('password = ""');
|
73
|
|
|
|
74
|
|
|
$criteria->limit = $pageSize;
|
75
|
|
|
$criteria->order = 'created DESC';
|
76
|
|
|
|
77
|
|
|
$itemCount = Content::model()->count($criteria);
|
78
|
|
|
$pages=new CPagination($itemCount);
|
79
|
|
|
$pages->pageSize=$pageSize;
|
80
|
|
|
|
81
|
|
|
|
82
|
|
|
$criteria->offset = $criteria->limit*($pages->getCurrentPage());
|
83
|
|
|
$data = Content::model()->findAll($criteria);
|
84
|
|
|
|
85
|
|
|
$pages->applyLimit($criteria);
|
86
|
|
|
|
87
|
|
|
$this->render('index', array(
|
88
|
|
|
'id' => $id,
|
89
|
|
|
'category' => $category,
|
90
|
|
|
'data' => $data,
|
91
|
|
|
'itemCount' => $itemCount,
|
92
|
|
|
'pages' => $pages,
|
93
|
|
|
'meta' => array(
|
94
|
|
|
'description' => $category->getDescription()
|
95
|
|
|
)));
|
96
|
|
|
}
|
97
|
|
|
|
98
|
|
|
/**
|
99
|
|
|
* Displays either all posts or all posts for a particular category_id if an $id is set in RSS Format
|
100
|
|
|
* So that RSS Readers can access the website
|
101
|
|
|
* @param int $id
|
102
|
|
|
*/
|
103
|
|
|
public function actionRss($id=NULL)
|
104
|
|
|
{
|
105
|
|
|
Yii::app()->log->routes[0]->enabled = false;
|
106
|
|
|
ob_end_clean();
|
107
|
|
|
header('Content-type: text/xml; charset=utf-8');
|
108
|
|
|
$url = 'http://'.Yii::app()->request->serverName . Yii::app()->baseUrl;
|
109
|
|
|
$this->setLayout(null);
|
110
|
|
|
$criteria = Content::model()
|
111
|
|
|
->getBaseCriteria()
|
112
|
|
|
->addCondition('type_id >= 2')
|
113
|
|
|
->addCondition('password = ""');
|
114
|
|
|
|
115
|
|
|
if ($id !== NULL)
|
116
|
|
|
$criteria->addCondition("category_id = " . $id);
|
|
|
|
|
117
|
|
|
|
118
|
|
|
$criteria->order = 'created DESC';
|
119
|
|
|
$data = Content::model()->findAll($criteria);
|
120
|
|
|
|
121
|
|
|
$this->renderPartial('application.views.site/rss', array(
|
122
|
|
|
'data' => $data,
|
123
|
|
|
'url' => $url
|
124
|
|
|
));
|
125
|
|
|
return;
|
126
|
|
|
}
|
127
|
|
|
}
|
128
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.