HCE Project DC service web UI  0.2
Hierarchical Cluster Engine DC service web UI
 All Classes Namespaces Files Functions Variables Pages
AccountTypesLimits.php
Go to the documentation of this file.
1 <?php
2 
12 class AccountTypesLimits extends CActiveRecord
13 {
17  public function tableName()
18  {
19  return 'account_types_limits';
20  }
21 
25  public function rules()
26  {
27  // NOTE: you should only define rules for those attributes that
28  // will receive user inputs.
29  return array(
30  array('Id, AccountTypeId, LimitsKey', 'required'),
31  array('Id, AccountTypeId', 'length', 'max' => 20),
32  array('LimitsKey', 'length', 'max' => 32),
33  array('LimitsList', 'safe'),
34  // The following rule is used by search().
35  // @todo Please remove those attributes that should not be searched.
36  array('Id, AccountTypeId, LimitsKey, LimitsList', 'safe', 'on' => 'search'),
37  );
38  }
39 
43  public function relations()
44  {
45  // NOTE: you may need to adjust the relation name and the related
46  // class name for the relations automatically generated below.
47  return array(
48  'AccountTypes' => array(self::BELONGS_TO, 'AccountTypes', 'AccountTypeId'),
49  );
50  }
51 
55  public function attributeLabels()
56  {
57  return array(
58  'Id' => 'ID',
59  'AccountTypeId' => 'Account Type',
60  'LimitsKey' => 'Limits Key',
61  'LimitsList' => 'Limits List',
62  );
63  }
64 
77  public function search()
78  {
79  // @todo Please modify the following code to remove attributes that should not be searched.
80 
81  $criteria = new CDbCriteria();
82 
83  $criteria->compare('Id', $this->Id, true);
84  $criteria->compare('AccountTypeId', $this->AccountTypeId, true);
85  $criteria->compare('LimitsKey', $this->LimitsKey, true);
86  $criteria->compare('LimitsList', $this->LimitsList, true);
87 
88  return new CActiveDataProvider($this, array(
89  'criteria' => $criteria,
90  ));
91  }
92 
101  public static function model($className = __CLASS__)
102  {
103  return parent::model($className);
104  }
105 
106  protected function beforeDelete()
107  {
108  $primaryKey = $this->primaryKey;
109  if (!empty($primaryKey)) {
110  AccountUsers::model()->setAllUsersDefaultAccountTypeByAccountTypeId($primaryKey);
111  }
112  return parent::beforeDelete();
113  }
114 
124  public function getAccountTypesLimitsList($userId, $limitsKey, $jsonFormat = false)
125  {
126  if (Rights::getAuthorizer()->isSuperuser($userId)) {
127  $accountTypesLimits = json_encode(array());
128  } else {
129  $AccountTypesLimits = $this->__getAccountTypesLimitsData($userId, $limitsKey);
130  $accountTypesLimits = $AccountTypesLimits->LimitsList;
131  }
132  if (empty($jsonFormat)) {
133  $accountTypesLimits = json_decode($accountTypesLimits, true);
134  }
135 
136  return $accountTypesLimits;
137  }
138 
147  private function __getAccountTypesLimitsData($userId, $limitsKey)
148  {
149  if (empty($userId) || empty($limitsKey)) {
150  return false;
151  }
152  $User = AccountUsers::model()->findByAttributes(array(
153  'UserId' => $userId,
154  ));
155  if (empty($User)) {
156  return false;
157  }
158 
159  return $this->findByAttributes(array(
160  'AccountTypeId' => $User->AccountTypeId,
161  'LimitsKey' => $limitsKey,
162  ));
163  }
164 }