Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 38 |
|
0.00% |
0 / 33 |
CRAP | |
0.00% |
0 / 1 |
Role | |
0.00% |
0 / 38 |
|
0.00% |
0 / 33 |
1122 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getUsername | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setUsername | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getOldUsername | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setOldUsername | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getDescription | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setDescription | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getGuide | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setGuide | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getPermissions | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setPermissions | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getParentRoleId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setParentRoleId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getUsers | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
addUser | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
removeUser | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getIndexWithinParent | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setIndexWithinParent | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getFeaturedIndex | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setFeaturedIndex | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getCanHaveChildRoles | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setCanHaveChildRoles | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
__toString | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
getIdFieldNameForSearch | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getIdForSearch | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getCriteriaForQuery | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
getTitleForSearch | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getEntityNameForStorage | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getEntityIdForStorage | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace Olz\Entity\Roles; |
4 | |
5 | use Doctrine\Common\Collections\ArrayCollection; |
6 | use Doctrine\Common\Collections\Collection; |
7 | use Doctrine\Common\Collections\Criteria; |
8 | use Doctrine\Common\Collections\Expr\Expression; |
9 | use Doctrine\ORM\Mapping as ORM; |
10 | use Olz\Entity\Common\DataStorageInterface; |
11 | use Olz\Entity\Common\DataStorageTrait; |
12 | use Olz\Entity\Common\OlzEntity; |
13 | use Olz\Entity\Common\SearchableInterface; |
14 | use Olz\Entity\Users\User; |
15 | use Olz\Repository\Roles\RoleRepository; |
16 | |
17 | #[ORM\Table(name: 'roles')] |
18 | #[ORM\Entity(repositoryClass: RoleRepository::class)] |
19 | class Role extends OlzEntity implements DataStorageInterface, SearchableInterface { |
20 | use DataStorageTrait; |
21 | |
22 | #[ORM\Id] |
23 | #[ORM\Column(type: 'integer', nullable: false)] |
24 | #[ORM\GeneratedValue] |
25 | public int $id; |
26 | |
27 | #[ORM\Column(type: 'text', nullable: false)] |
28 | public string $username; |
29 | |
30 | #[ORM\Column(type: 'text', nullable: true)] |
31 | public ?string $old_username; |
32 | |
33 | #[ORM\Column(type: 'text', nullable: false)] |
34 | public string $name; |
35 | |
36 | #[ORM\Column(type: 'text', nullable: false, options: ['comment' => 'public'])] |
37 | public string $description; |
38 | |
39 | #[ORM\Column(type: 'text', nullable: false)] |
40 | public string $permissions; |
41 | |
42 | #[ORM\Column(type: 'text', nullable: false, options: ['comment' => 'restricted access'])] |
43 | public string $guide; |
44 | |
45 | #[ORM\Column(type: 'integer', nullable: true)] |
46 | public ?int $parent_role; |
47 | |
48 | #[ORM\Column(type: 'integer', nullable: true, options: ['comment' => 'negative value: hide role'])] |
49 | public ?int $index_within_parent; |
50 | |
51 | #[ORM\Column(type: 'integer', nullable: true)] |
52 | public ?int $featured_index; |
53 | |
54 | #[ORM\Column(type: 'boolean', options: ['default' => 0])] |
55 | public bool $can_have_child_roles; |
56 | |
57 | /** @var Collection<int|string, User>&iterable<User> */ |
58 | #[ORM\JoinTable(name: 'users_roles')] |
59 | #[ORM\ManyToMany(targetEntity: User::class, mappedBy: 'roles')] |
60 | private Collection $users; |
61 | |
62 | public function __construct() { |
63 | $this->users = new ArrayCollection(); |
64 | } |
65 | |
66 | public function getId(): ?int { |
67 | return $this->id ?? null; |
68 | } |
69 | |
70 | public function setId(int $new_id): void { |
71 | $this->id = $new_id; |
72 | } |
73 | |
74 | public function getUsername(): string { |
75 | return $this->username; |
76 | } |
77 | |
78 | public function setUsername(string $new_username): void { |
79 | $this->username = $new_username; |
80 | } |
81 | |
82 | public function getOldUsername(): ?string { |
83 | return $this->old_username; |
84 | } |
85 | |
86 | public function setOldUsername(?string $new_old_username): void { |
87 | $this->old_username = $new_old_username; |
88 | } |
89 | |
90 | public function getName(): string { |
91 | return $this->name; |
92 | } |
93 | |
94 | public function setName(string $new_name): void { |
95 | $this->name = $new_name; |
96 | } |
97 | |
98 | public function getDescription(): string { |
99 | return $this->description; |
100 | } |
101 | |
102 | public function setDescription(string $new_value): void { |
103 | $this->description = $new_value; |
104 | } |
105 | |
106 | public function getGuide(): string { |
107 | return $this->guide; |
108 | } |
109 | |
110 | public function setGuide(string $new_value): void { |
111 | $this->guide = $new_value; |
112 | } |
113 | |
114 | public function getPermissions(): string { |
115 | return $this->permissions; |
116 | } |
117 | |
118 | public function setPermissions(string $new_value): void { |
119 | $this->permissions = $new_value; |
120 | } |
121 | |
122 | public function getParentRoleId(): ?int { |
123 | return $this->parent_role; |
124 | } |
125 | |
126 | public function setParentRoleId(?int $new_value): void { |
127 | $this->parent_role = $new_value; |
128 | } |
129 | |
130 | /** @return Collection<int|string, User>&iterable<User> */ |
131 | public function getUsers(): Collection { |
132 | return $this->users; |
133 | } |
134 | |
135 | public function addUser(User $user): void { |
136 | $this->users->add($user); |
137 | } |
138 | |
139 | public function removeUser(User $user): void { |
140 | $this->users->removeElement($user); |
141 | } |
142 | |
143 | public function getIndexWithinParent(): ?int { |
144 | return $this->index_within_parent; |
145 | } |
146 | |
147 | public function setIndexWithinParent(?int $new_value): void { |
148 | $this->index_within_parent = $new_value; |
149 | } |
150 | |
151 | public function getFeaturedIndex(): ?int { |
152 | return $this->featured_index; |
153 | } |
154 | |
155 | public function setFeaturedIndex(?int $new_value): void { |
156 | $this->featured_index = $new_value; |
157 | } |
158 | |
159 | public function getCanHaveChildRoles(): bool { |
160 | return $this->can_have_child_roles; |
161 | } |
162 | |
163 | public function setCanHaveChildRoles(bool $new_value): void { |
164 | $this->can_have_child_roles = $new_value; |
165 | } |
166 | |
167 | // --- |
168 | |
169 | public function __toString() { |
170 | $username = $this->getUsername(); |
171 | $id = $this->getId(); |
172 | return "{$username} (Role ID: {$id})"; |
173 | } |
174 | |
175 | public static function getIdFieldNameForSearch(): string { |
176 | return 'id'; |
177 | } |
178 | |
179 | public function getIdForSearch(): int { |
180 | return $this->getId() ?? 0; |
181 | } |
182 | |
183 | public static function getCriteriaForQuery(string $query): Expression { |
184 | return Criteria::expr()->orX( |
185 | Criteria::expr()->contains('name', $query), |
186 | Criteria::expr()->contains('username', $query), |
187 | ); |
188 | } |
189 | |
190 | public function getTitleForSearch(): string { |
191 | return $this->getName(); |
192 | } |
193 | |
194 | public static function getEntityNameForStorage(): string { |
195 | return 'roles'; |
196 | } |
197 | |
198 | public function getEntityIdForStorage(): string { |
199 | return "{$this->getId()}"; |
200 | } |
201 | } |