1 <?php
2 3 4 5 6 7 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 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 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 47 48
49 public function nameIsAvailable($attribute, $params)
50 {
51
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 58 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 68 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 78 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
87