Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 23 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| Role | |
0.00% |
0 / 23 |
|
0.00% |
0 / 4 |
56 | |
0.00% |
0 / 1 |
| getEntityMapping | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
2 | |||
| postProcess | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 | |||
| addConditionName | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| addConditionNames | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace BO\Zmsdb\Query; |
| 4 | |
| 5 | class Role extends Base implements MappingInterface |
| 6 | { |
| 7 | /** |
| 8 | * @var string TABLE mysql table reference |
| 9 | */ |
| 10 | const TABLE = 'role'; |
| 11 | |
| 12 | public function getEntityMapping() |
| 13 | { |
| 14 | return [ |
| 15 | 'id' => 'role.id', |
| 16 | 'name' => 'role.name', |
| 17 | 'description' => 'role.description', |
| 18 | 'permissions' => self::expression( |
| 19 | '(SELECT GROUP_CONCAT(DISTINCT p.name ORDER BY p.name SEPARATOR \',\') ' |
| 20 | . 'FROM role_permission rp ' |
| 21 | . 'JOIN permission p ON p.id = rp.permission_id ' |
| 22 | . 'WHERE rp.role_id = role.id)' |
| 23 | ), |
| 24 | ]; |
| 25 | } |
| 26 | |
| 27 | public function postProcess($data) |
| 28 | { |
| 29 | $permissionsKey = $this->getPrefixed('permissions'); |
| 30 | $rawPermissions = $data[$permissionsKey] ?? null; |
| 31 | $data[$permissionsKey] = ($rawPermissions === null || $rawPermissions === '') |
| 32 | ? [] |
| 33 | : explode(',', (string) $rawPermissions); |
| 34 | return $data; |
| 35 | } |
| 36 | |
| 37 | public function addConditionName(string $name): self |
| 38 | { |
| 39 | $this->query->where('role.name', '=', $name); |
| 40 | return $this; |
| 41 | } |
| 42 | |
| 43 | public function addConditionNames(array $names): self |
| 44 | { |
| 45 | if ($names === []) { |
| 46 | throw new \InvalidArgumentException('Argument $names must not be empty.'); |
| 47 | } |
| 48 | $this->query->whereIn('role.name', $names); |
| 49 | return $this; |
| 50 | } |
| 51 | } |