Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
AuthItemForm.php
1 <?php
2 /**
3 * Authorization item form class file.
4 *
5 * @author Christoffer Niska <cniska@live.com>
6 * @copyright Copyright &copy; 2010 Christoffer Niska
7 * @since 0.5
8 */
9 class AuthItemForm extends CFormModel
10 {
11  public $name;
12  public $description;
13  public $type;
14  public $bizRule;
15  public $data;
16 
17  /**
18  * Declares the validation rules.
19  */
20  public function rules()
21  {
22  return array(
23  array('name, description', 'required'),
24  array('name', 'nameIsAvailable', 'on'=>'create'),
25  array('name', 'newNameIsAvailable', 'on'=>'update'),
26  array('name', 'isSuperuser', 'on'=>'update'),
27  array('data', 'bizRuleNotEmpty'),
28  array('bizRule, data', 'safe'),
29  );
30  }
31 
32  /**
33  * Declares attribute labels.
34  */
35  public function attributeLabels()
36  {
37  return array(
38  'name' => Rights::t('core', 'Name'),
39  'description' => Rights::t('core', 'Description'),
40  'bizRule' => Rights::t('core', 'Business rule'),
41  'data' => Rights::t('core', 'Data'),
42  );
43  }
44 
45  /**
46  * Makes sure that the name is available.
47  * This is the 'nameIsAvailable' validator as declared in rules().
48  */
49  public function nameIsAvailable($attribute, $params)
50  {
51  // Make sure that an authorization item with the name does not already exist
52  if( Rights::getAuthorizer()->authManager->getAuthItem($this->name)!==null )
53  $this->addError('name', Rights::t('core', 'An item with this name already exists.', array(':name'=>$this->name)));
54  }
55 
56  /**
57  * Makes sure that the new name is available if the name been has changed.
58  * This is the 'newNameIsAvailable' validator as declared in rules().
59  */
60  public function newNameIsAvailable($attribute, $params)
61  {
62  if( strtolower(urldecode($_GET['name']))!==strtolower($this->name) )
63  $this->nameIsAvailable($attribute, $params);
64  }
65 
66  /**
67  * Makes sure that the superuser roles name is not changed.
68  * This is the 'isSuperuser' validator as declared in rules().
69  */
70  public function isSuperuser($attribute, $params)
71  {
72  if( strtolower($_GET['name'])!==strtolower($this->name) && strtolower($_GET['name'])===strtolower(Rights::module()->superuserName) )
73  $this->addError('name', Rights::t('core', 'Name of the superuser cannot be changed.'));
74  }
75 
76  /**
77  * Makes sure that the business rule is not empty when data is specified.
78  * This is the 'bizRuleNotEmpty' validator as declared in rules().
79  */
80  public function bizRuleNotEmpty($attribute, $params)
81  {
82  if( empty($this->data)===false && empty($this->bizRule)===true )
83  $this->addError('data', Rights::t('core', 'Business rule cannot be empty.'));
84  }
85 }
86