Passed
Push — master ( d021a5...a13070 )
by Sam
03:47 queued 12s
created

AdminOnlyController::filters()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php
2
3
/**
4
 * Base controller which only grants access to actions for administrators
5
 *
6
 * @author Sam Stenvall <[email protected]>
7
 * @copyright Copyright &copy; Sam Stenvall 2013-
8
 * @license https://www.gnu.org/licenses/gpl.html The GNU General Public License v3.0
9
 */
10
abstract class AdminOnlyController extends ModelController
11
{
12
	
13
	/**
14
	 * Initializes the controller
15
	 */
16
	public function init()
17
	{
18
		parent::init();
19
20
		$this->defaultAction = 'admin';
21
	}
22
23
	/**
24
	 * Returns the filters for this controller. In addition to parent filters 
25
	 * we want access control.
26
	 * @return array
27
	 */
28
	public function filters()
29
	{
30
		return array_merge(parent::filters(), array(
31
			'accessControl',
32
		));
33
	}
34
35
	/**
36
	 * Returns the access control rules
37
	 * @return array
38
	 */
39
	public function accessRules()
40
	{
41
		return array(
42
			array('allow',
43
				'expression'=>function() {
44
					return Yii::app()->user->role == User::ROLE_ADMIN;
45
				},
46
			),
47
			array('deny'),
48
		);
49
	}
50
51
}