[ 'type' => Schema::DT_BOOL, 'nullable' => false, 'default' => 1, 'index' => true ], 'name' => [ 'type' => Schema::DT_VARCHAR128, 'nullable' => false, 'default' => '' ], 'label' => [ 'type' => Schema::DT_VARCHAR128, 'nullable' => false, 'default' => '' ], 'style' => [ 'type' => Schema::DT_VARCHAR128, 'nullable' => false, 'default' => '' ], 'corporationRights' => [ 'has-many' => ['Model\CorporationRightModel', 'roleId'] ] ]; protected static $tableData = [ [ 'id' => 1, 'name' => 'MEMBER', 'label' => 'member', 'style' => 'default' ], [ 'id' => 2, 'name' => 'SUPER', 'label' => 'admin', 'style' => 'danger' ], [ 'id' => 3, 'name' => 'CORPORATION', 'label' => 'manager', 'style' => 'info' ] ]; /** * get role data * @return \stdClass */ public function getData(){ $roleData = (object) []; $roleData->name = $this->name; $roleData->label = $this->label; return $roleData; } /** * get default role * @return self|null */ public static function getDefaultRole(){ return self::getRoleById(1); } /** * get admin role * @return self|null */ public static function getAdminRole(){ return self::getRoleById(2); } /** * get corporation admin role * @return self|null */ public static function getCorporationManagerRole(){ return self::getRoleById(3); } /** * get role by id * @param int $roleId * @return self|null */ public static function getRoleById(int $roleId = 1){ $role = (new self())->getById($roleId); return $role->dry() ? null : $role; } /** * get all corporations * @return \DB\CortexCollection */ public static function getAll(){ $query = [ 'active = :active', ':active' => 1 ]; return (new self())->find($query); } }