1 <?php
2 /**
3 * Rights base controller class file.
4 *
5 * @author Christoffer Niska <cniska@live.com>
6 * @copyright Copyright © 2010 Christoffer Niska
7 * @since 0.6
8 */
9 class RController extends CController
10 {
11 /**
12 * @property string the default layout for the controller view. Defaults to '//layouts/column1',
13 * meaning using a single column layout. See 'protected/views/layouts/column1.php'.
14 */
15 public $layout='//layouts/column1';
16 /**
17 * @property array context menu items. This property will be assigned to {@link CMenu::items}.
18 */
19 public $menu=array();
20 /**
21 * @property array the breadcrumbs of the current page. The value of this property will
22 * be assigned to {@link CBreadcrumbs::links}. Please refer to {@link CBreadcrumbs::links}
23 * for more details on how to specify this property.
24 */
25 public $breadcrumbs=array();
26
27 /**
28 * The filter method for 'rights' access filter.
29 * This filter is a wrapper of {@link CAccessControlFilter}.
30 * @param CFilterChain $filterChain the filter chain that the filter is on.
31 */
32 public function filterRights($filterChain)
33 {
34 $filter = new RightsFilter;
35 $filter->allowedActions = $this->allowedActions();
36 $filter->filter($filterChain);
37 }
38
39 /**
40 * @return string the actions that are always allowed separated by commas.
41 */
42 public function allowedActions()
43 {
44 return '';
45 }
46
47 /**
48 * Denies the access of the user.
49 * @param string $message the message to display to the user.
50 * This method may be invoked when access check fails.
51 * @throws CHttpException when called unless login is required.
52 */
53 public function accessDenied($message=null)
54 {
55 if( $message===null )
56 $message = Rights::t('core', 'You are not authorized to perform this action.');
57
58 $user = Yii::app()->getUser();
59 if( $user->isGuest===true )
60 $user->loginRequired();
61 else
62 throw new CHttpException(403, $message);
63 }
64 }
65