| 1 | <?php |
||
| 20 | class Row extends \Bluz\Db\Row |
||
| 21 | { |
||
| 22 | use Validator; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Before Insert/Update |
||
| 26 | * @return void |
||
| 27 | */ |
||
| 28 | protected function beforeInsert() |
||
| 29 | { |
||
| 30 | $this->addValidator( |
||
| 31 | 'name', |
||
| 32 | v::required()->latin(), |
||
| 33 | v::callback(function ($name) { |
||
| 34 | return !Table::getInstance()->findRowWhere(['name'=>$name]); |
||
| 35 | })->setError('Role name "{{input}}" already exists') |
||
| 36 | ); |
||
| 37 | } |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Before Update |
||
| 41 | * @return void |
||
| 42 | */ |
||
| 43 | protected function beforeUpdate() |
||
| 44 | { |
||
| 45 | $this->addValidator( |
||
| 46 | 'name', |
||
| 47 | v::required()->latin(), |
||
| 48 | v::callback(function ($name) { |
||
| 49 | return !in_array(strtolower($name), Table::getInstance()->getBasicRoles()); |
||
| 50 | })->setError('Role "{{input}}" is basic and can\'t be editable'), |
||
| 51 | v::callback(function ($name) { |
||
| 52 | return $this->clean['name'] != $name; |
||
| 53 | })->setError('Role name "{{input}}" the same as original'), |
||
| 54 | v::callback(function ($name) { |
||
| 55 | return !Table::getInstance()->findRowWhere(['name'=>$name]); |
||
| 56 | })->setError('Role name "{{input}}" already exists') |
||
| 57 | ); |
||
| 58 | } |
||
| 59 | |||
| 60 | /** |
||
| 61 | * isBasic |
||
| 62 | * |
||
| 63 | * @return boolean |
||
| 64 | */ |
||
| 65 | 1 | public function isBasic() |
|
| 69 | } |
||
| 70 |