Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
RightsModule.php
1 <?php
2 /**
3 * Rights module class file.
4 *
5 * @author Christoffer Niska <cniska@live.com>
6 * @copyright Copyright &copy; 2010 Christoffer Niska
7 * @version 1.3.0
8 *
9 * DO NOT CHANGE THE DEFAULT CONFIGURATION VALUES!
10 *
11 * You may overload the module configuration values in your rights-module
12 * configuration like so:
13 *
14 * 'modules'=>array(
15 * 'rights'=>array(
16 * 'userNameColumn'=>'name',
17 * 'flashSuccessKey'=>'success',
18 * 'flashErrorKey'=>'error',
19 * ),
20 * ),
21 */
22 class RightsModule extends CWebModule
23 {
24  /**
25  * @property string the name of the role with superuser privileges.
26  */
27  public $superuserName = 'Admin';
28  /**
29  * @property string the name of the guest role.
30  */
31  public $authenticatedName = 'Authenticated';
32  /**
33  * @property string the name of the user model class.
34  */
35  public $userClass = 'User';
36  /**
37  * @property string the name of the id column in the user table.
38  */
39  public $userIdColumn = 'id';
40  /**
41  * @property string the name of the username column in the user table.
42  */
43  public $userNameColumn = 'username';
44  /**
45  * @property boolean whether to enable business rules.
46  */
47  public $enableBizRule = true;
48  /**
49  * @property boolean whether to enable data for business rules.
50  */
51  public $enableBizRuleData = false;
52  /**
53  * @property boolean whether to display authorization items description
54  * instead of name it is set.
55  */
56  public $displayDescription = true;
57  /**
58  * @property string the flash message key to use for success messages.
59  */
60  public $flashSuccessKey = 'RightsSuccess';
61  /**
62  * @property string the flash message key to use for error messages.
63  */
64  public $flashErrorKey = 'RightsError';
65  /**
66  * @property boolean whether to install rights when accessed.
67  */
68  public $install = false;
69  /**
70  * @property string the base url to Rights. Override when module is nested.
71  */
72  public $baseUrl = '/rights';
73  /**
74  * @property string the path to the layout file to use for displaying Rights.
75  */
76  public $layout = 'rights.views.layouts.main';
77  /**
78  * @property string the path to the application layout file.
79  */
80  public $appLayout = 'application.views.layouts.main';
81  /**
82  * @property string the style sheet file to use for Rights.
83  */
84  public $cssFile;
85  /**
86  * @property boolean whether to enable debug mode.
87  */
88  public $debug = false;
89 
90  private $_assetsUrl;
91 
92  /**
93  * Initializes the "rights" module.
94  */
95  public function init()
96  {
97  // Set required classes for import.
98  $this->setImport(array(
99  'rights.components.*',
100  'rights.components.behaviors.*',
101  'rights.components.dataproviders.*',
102  'rights.controllers.*',
103  'rights.models.*',
104  'common.extensions.eauth.*',
105  'common.extensions.eauth.services.*',
106  ));
107 
108  // Set the required components.
109  $this->setComponents(array(
110  'authorizer'=>array(
111  'class'=>'RAuthorizer',
112  'superuserName'=>$this->superuserName,
113  ),
114  'generator'=>array(
115  'class'=>'RGenerator',
116  ),
117  ));
118 
119  // Normally the default controller is Assignment.
120  $this->defaultController = 'assignment';
121 
122  // Set the installer if necessary.
123  if( $this->install===true )
124  {
125  $this->setComponents(array(
126  'installer'=>array(
127  'class'=>'RInstaller',
128  'superuserName'=>$this->superuserName,
129  'authenticatedName'=>$this->authenticatedName,
130  'guestName'=>Yii::app()->user->guestName,
131  'defaultRoles'=>Yii::app()->authManager->defaultRoles,
132  ),
133  ));
134 
135  // When installing we need to set the default controller to Install.
136  $this->defaultController = 'install';
137  }
138  }
139 
140  /**
141  * Registers the necessary scripts.
142  */
143  public function registerScripts()
144  {
145  // Get the url to the module assets
146  $assetsUrl = $this->getAssetsUrl();
147 
148  // Register the necessary scripts
149  $cs = Yii::app()->getClientScript();
150  $cs->registerCoreScript('jquery');
151  $cs->registerCoreScript('jquery.ui');
152  $cs->registerScriptFile($assetsUrl.'/js/rights.js');
153  $cs->registerCssFile($assetsUrl.'/css/core.css');
154 
155  // Make sure we want to register a style sheet.
156  if( $this->cssFile!==false )
157  {
158  // Default style sheet is used unless one is provided.
159  if( $this->cssFile===null )
160  $this->cssFile = $assetsUrl.'/css/default.css';
161  else
162  $this->cssFile = Yii::app()->request->baseUrl.$this->cssFile;
163 
164  // Register the style sheet
165  $cs->registerCssFile($this->cssFile);
166  }
167  }
168 
169  /**
170  * Publishes the module assets path.
171  * @return string the base URL that contains all published asset files of Rights.
172  */
173  public function getAssetsUrl()
174  {
175  if( $this->_assetsUrl===null )
176  {
177  $assetsPath = Yii::getPathOfAlias('rights.assets');
178 
179  // We need to republish the assets if debug mode is enabled.
180  if( $this->debug===true )
181  $this->_assetsUrl = Yii::app()->getAssetManager()->publish($assetsPath, true, -1, true);
182  else
183  $this->_assetsUrl = Yii::app()->getAssetManager()->publish($assetsPath, true);
184  }
185 
186  return $this->_assetsUrl;
187  }
188 
189  /**
190  * @return RightsAuthorizer the authorizer component.
191  */
192  public function getAuthorizer()
193  {
194  return $this->getComponent('authorizer');
195  }
196 
197  /**
198  * @return RightsInstaller the installer component.
199  */
200  public function getInstaller()
201  {
202  return $this->getComponent('installer');
203  }
204 
205  /**
206  * @return RightsGenerator the generator component.
207  */
208  public function getGenerator()
209  {
210  return $this->getComponent('generator');
211  }
212 
213  /**
214  * @return the current version.
215  */
216  public function getVersion()
217  {
218  return '1.3.0';
219  }
220 }