HCE Project DC service web UI  0.2
Hierarchical Cluster Engine DC service web UI
 All Classes Namespaces Files Functions Variables Pages
AuthItemForm.php
Go to the documentation of this file.
1 <?php
10 class AuthItemForm extends CFormModel
11 {
12  public $name;
13  public $description;
14  public $type;
15  public $bizRule;
16  public $data;
17 
21  public function rules()
22  {
23  return array(
24  array('name, description', 'required'),
25  array('name', 'nameIsAvailable', 'on' => 'create'),
26  array('name', 'newNameIsAvailable', 'on' => 'update'),
27  array('name', 'isSuperuser', 'on' => 'update'),
28  array('data', 'bizRuleNotEmpty'),
29  array('bizRule, data', 'safe'),
30  );
31  }
32 
36  public function attributeLabels()
37  {
38  return array(
39  'name' => Rights::t('core', 'Name'),
40  'description' => Rights::t('core', 'Description'),
41  'bizRule' => Rights::t('core', 'Business rule'),
42  'data' => Rights::t('core', 'Data'),
43  );
44  }
45 
50  public function nameIsAvailable($attribute, $params)
51  {
52  // Make sure that an authorization item with the name does not already exist
53  if (Rights::getAuthorizer()->authManager->getAuthItem($this->name) !== null) {
54  $this->addError('name', Rights::t('core', 'An item with this name already exists.', array(':name' => $this->name)));
55  }
56  }
57 
62  public function newNameIsAvailable($attribute, $params)
63  {
64  if (strtolower(urldecode($_GET['name'])) !== strtolower($this->name)) {
65  $this->nameIsAvailable($attribute, $params);
66  }
67  }
68 
73  public function isSuperuser($attribute, $params)
74  {
75  if (strtolower($_GET['name']) !== strtolower($this->name) && strtolower($_GET['name']) === strtolower(Rights::module()->superuserName)) {
76  $this->addError('name', Rights::t('core', 'Name of the superuser cannot be changed.'));
77  }
78  }
79 
84  public function bizRuleNotEmpty($attribute, $params)
85  {
86  if (empty($this->data) === false && empty($this->bizRule) === true) {
87  $this->addError('data', Rights::t('core', 'Business rule cannot be empty.'));
88  }
89  }
90 }