CategoriesController   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 125
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 4
dl 0
loc 125
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
B filters() 0 35 6
A actionIndex() 0 47 1
B actionRss() 0 24 2
1
<?php
2
3
class CategoriesController extends CiiController
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
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)
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal category_id = does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
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);
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal category_id = does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
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