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