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