Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 70 |
|
0.00% |
0 / 48 |
CRAP | |
0.00% |
0 / 1 |
| SolvEvent | |
0.00% |
0 / 70 |
|
0.00% |
0 / 48 |
2756 | |
0.00% |
0 / 1 |
| getSolvUid | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setSolvUid | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getDate | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setDate | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getDuration | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setDuration | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getKind | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setKind | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getDayNight | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setDayNight | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getNational | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setNational | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getRegion | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setRegion | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getType | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setType | |
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 | |||
| getLink | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setLink | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getClub | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setClub | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getMap | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setMap | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getLocation | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setLocation | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getCoordX | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setCoordX | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getCoordY | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setCoordY | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getDeadline | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setDeadline | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getEntryportal | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setEntryportal | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getStartLink | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setStartLink | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getRankLink | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setRankLink | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getLastModification | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setLastModification | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getFieldValue | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| setFieldValue | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| testOnlyGetField | |
0.00% |
0 / 1 |
|
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 | |||
| getTitleForSearch | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| getCriteriaForFilter | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getCriteriaForQuery | |
0.00% |
0 / 18 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Olz\Entity; |
| 4 | |
| 5 | use Doctrine\Common\Collections\Criteria; |
| 6 | use Doctrine\Common\Collections\Expr\Expression; |
| 7 | use Doctrine\ORM\Mapping as ORM; |
| 8 | use Olz\Entity\Common\SearchableInterface; |
| 9 | use Olz\Entity\Common\TestableInterface; |
| 10 | use Olz\Repository\SolvEventRepository; |
| 11 | use Olz\Utils\WithUtilsTrait; |
| 12 | |
| 13 | #[ORM\Table(name: 'solv_events')] |
| 14 | #[ORM\Index(name: 'date_index', columns: ['date'])] |
| 15 | #[ORM\Entity(repositoryClass: SolvEventRepository::class)] |
| 16 | class SolvEvent implements SearchableInterface, TestableInterface { |
| 17 | use WithUtilsTrait; |
| 18 | |
| 19 | #[ORM\Id] |
| 20 | #[ORM\Column(type: 'integer', nullable: false)] |
| 21 | private int $solv_uid; |
| 22 | |
| 23 | #[ORM\Column(type: 'date', nullable: false)] |
| 24 | private \DateTime $date; |
| 25 | |
| 26 | #[ORM\Column(type: 'integer', nullable: false)] |
| 27 | private int $duration; |
| 28 | |
| 29 | #[ORM\Column(type: 'text', nullable: false)] |
| 30 | private string $kind; |
| 31 | |
| 32 | #[ORM\Column(type: 'text', nullable: false)] |
| 33 | private string $day_night; |
| 34 | |
| 35 | #[ORM\Column(type: 'integer', nullable: false)] |
| 36 | private int $national; |
| 37 | |
| 38 | #[ORM\Column(type: 'text', nullable: false)] |
| 39 | private string $region; |
| 40 | |
| 41 | #[ORM\Column(type: 'text', nullable: false)] |
| 42 | private string $type; |
| 43 | |
| 44 | #[ORM\Column(type: 'text', nullable: false)] |
| 45 | private string $name; |
| 46 | |
| 47 | #[ORM\Column(type: 'text', nullable: false)] |
| 48 | private string $link; |
| 49 | |
| 50 | #[ORM\Column(type: 'text', nullable: false)] |
| 51 | private string $club; |
| 52 | |
| 53 | #[ORM\Column(type: 'text', nullable: false)] |
| 54 | private string $map; |
| 55 | |
| 56 | #[ORM\Column(type: 'text', nullable: false)] |
| 57 | private string $location; |
| 58 | |
| 59 | #[ORM\Column(type: 'integer', nullable: false)] |
| 60 | private int $coord_x; |
| 61 | |
| 62 | #[ORM\Column(type: 'integer', nullable: false)] |
| 63 | private int $coord_y; |
| 64 | |
| 65 | #[ORM\Column(type: 'date', nullable: true)] |
| 66 | private ?\DateTime $deadline; |
| 67 | |
| 68 | #[ORM\Column(type: 'integer', nullable: false)] |
| 69 | private int $entryportal; |
| 70 | |
| 71 | #[ORM\Column(type: 'text', nullable: true)] |
| 72 | private ?string $start_link; |
| 73 | |
| 74 | #[ORM\Column(type: 'text', nullable: true)] |
| 75 | private ?string $rank_link; |
| 76 | |
| 77 | #[ORM\Column(type: 'datetime', nullable: false, options: ['default' => 'CURRENT_TIMESTAMP'])] |
| 78 | private \DateTime $last_modification; |
| 79 | |
| 80 | /** @var array<string, true> */ |
| 81 | private array $valid_field_names = [ |
| 82 | 'solv_uid' => true, |
| 83 | 'date' => true, |
| 84 | 'duration' => true, |
| 85 | 'kind' => true, |
| 86 | 'day_night' => true, |
| 87 | 'national' => true, |
| 88 | 'region' => true, |
| 89 | 'type' => true, |
| 90 | 'name' => true, |
| 91 | 'link' => true, |
| 92 | 'club' => true, |
| 93 | 'map' => true, |
| 94 | 'location' => true, |
| 95 | 'coord_x' => true, |
| 96 | 'coord_y' => true, |
| 97 | 'deadline' => true, |
| 98 | 'entryportal' => true, |
| 99 | 'start_link' => true, |
| 100 | 'rank_link' => true, |
| 101 | 'last_modification' => true, |
| 102 | ]; |
| 103 | // PRIMARY KEY (`solv_uid`) |
| 104 | |
| 105 | public function getSolvUid(): int { |
| 106 | return $this->solv_uid; |
| 107 | } |
| 108 | |
| 109 | public function setSolvUid(int $new_value): void { |
| 110 | $this->solv_uid = $new_value; |
| 111 | } |
| 112 | |
| 113 | public function getDate(): \DateTime { |
| 114 | return $this->date; |
| 115 | } |
| 116 | |
| 117 | public function setDate(\DateTime $new_value): void { |
| 118 | $this->date = $new_value; |
| 119 | } |
| 120 | |
| 121 | public function getDuration(): int { |
| 122 | return $this->duration; |
| 123 | } |
| 124 | |
| 125 | public function setDuration(int $new_value): void { |
| 126 | $this->duration = $new_value; |
| 127 | } |
| 128 | |
| 129 | public function getKind(): string { |
| 130 | return $this->kind; |
| 131 | } |
| 132 | |
| 133 | public function setKind(string $new_value): void { |
| 134 | $this->kind = $new_value; |
| 135 | } |
| 136 | |
| 137 | public function getDayNight(): string { |
| 138 | return $this->day_night; |
| 139 | } |
| 140 | |
| 141 | public function setDayNight(string $new_value): void { |
| 142 | $this->day_night = $new_value; |
| 143 | } |
| 144 | |
| 145 | public function getNational(): int { |
| 146 | return $this->national; |
| 147 | } |
| 148 | |
| 149 | public function setNational(int $new_value): void { |
| 150 | $this->national = $new_value; |
| 151 | } |
| 152 | |
| 153 | public function getRegion(): string { |
| 154 | return $this->region; |
| 155 | } |
| 156 | |
| 157 | public function setRegion(string $new_value): void { |
| 158 | $this->region = $new_value; |
| 159 | } |
| 160 | |
| 161 | public function getType(): string { |
| 162 | return $this->type; |
| 163 | } |
| 164 | |
| 165 | public function setType(string $new_value): void { |
| 166 | $this->type = $new_value; |
| 167 | } |
| 168 | |
| 169 | public function getName(): string { |
| 170 | return $this->name; |
| 171 | } |
| 172 | |
| 173 | public function setName(string $new_value): void { |
| 174 | $this->name = $new_value; |
| 175 | } |
| 176 | |
| 177 | public function getLink(): string { |
| 178 | return $this->link; |
| 179 | } |
| 180 | |
| 181 | public function setLink(string $new_value): void { |
| 182 | $this->link = $new_value; |
| 183 | } |
| 184 | |
| 185 | public function getClub(): string { |
| 186 | return $this->club; |
| 187 | } |
| 188 | |
| 189 | public function setClub(string $new_value): void { |
| 190 | $this->club = $new_value; |
| 191 | } |
| 192 | |
| 193 | public function getMap(): string { |
| 194 | return $this->map; |
| 195 | } |
| 196 | |
| 197 | public function setMap(string $new_value): void { |
| 198 | $this->map = $new_value; |
| 199 | } |
| 200 | |
| 201 | public function getLocation(): string { |
| 202 | return $this->location; |
| 203 | } |
| 204 | |
| 205 | public function setLocation(string $new_value): void { |
| 206 | $this->location = $new_value; |
| 207 | } |
| 208 | |
| 209 | public function getCoordX(): int { |
| 210 | return $this->coord_x; |
| 211 | } |
| 212 | |
| 213 | public function setCoordX(int $new_value): void { |
| 214 | $this->coord_x = $new_value; |
| 215 | } |
| 216 | |
| 217 | public function getCoordY(): int { |
| 218 | return $this->coord_y; |
| 219 | } |
| 220 | |
| 221 | public function setCoordY(int $new_value): void { |
| 222 | $this->coord_y = $new_value; |
| 223 | } |
| 224 | |
| 225 | public function getDeadline(): ?\DateTime { |
| 226 | return $this->deadline; |
| 227 | } |
| 228 | |
| 229 | public function setDeadline(?\DateTime $new_value): void { |
| 230 | $this->deadline = $new_value; |
| 231 | } |
| 232 | |
| 233 | public function getEntryportal(): int { |
| 234 | return $this->entryportal; |
| 235 | } |
| 236 | |
| 237 | public function setEntryportal(int $new_value): void { |
| 238 | $this->entryportal = $new_value; |
| 239 | } |
| 240 | |
| 241 | public function getStartLink(): ?string { |
| 242 | return $this->start_link; |
| 243 | } |
| 244 | |
| 245 | public function setStartLink(?string $new_value): void { |
| 246 | $this->start_link = $new_value; |
| 247 | } |
| 248 | |
| 249 | public function getRankLink(): ?string { |
| 250 | return $this->rank_link; |
| 251 | } |
| 252 | |
| 253 | public function setRankLink(?string $new_value): void { |
| 254 | $this->rank_link = $new_value; |
| 255 | } |
| 256 | |
| 257 | public function getLastModification(): \DateTime { |
| 258 | return $this->last_modification; |
| 259 | } |
| 260 | |
| 261 | public function setLastModification(\DateTime $new_value): void { |
| 262 | $this->last_modification = $new_value; |
| 263 | } |
| 264 | |
| 265 | public function getFieldValue(string $field_name): mixed { |
| 266 | if (!isset($this->valid_field_names[$field_name])) { |
| 267 | throw new \Exception("getFieldValue: Invalid field name: {$field_name}", 1); |
| 268 | } |
| 269 | return $this->{$field_name}; |
| 270 | } |
| 271 | |
| 272 | public function setFieldValue(string $field_name, mixed $new_value): void { |
| 273 | if (!isset($this->valid_field_names[$field_name])) { |
| 274 | throw new \Exception("setFieldValue: Invalid field name: {$field_name}", 1); |
| 275 | } |
| 276 | $this->{$field_name} = $new_value; |
| 277 | } |
| 278 | |
| 279 | // --- |
| 280 | |
| 281 | public function testOnlyGetField(string $field_name): mixed { |
| 282 | return $this->{$field_name}; |
| 283 | } |
| 284 | |
| 285 | public static function getIdFieldNameForSearch(): string { |
| 286 | return 'solv_uid'; |
| 287 | } |
| 288 | |
| 289 | public function getIdForSearch(): int { |
| 290 | return $this->getSolvUid(); |
| 291 | } |
| 292 | |
| 293 | public function getTitleForSearch(): string { |
| 294 | $pretty_date = $this->getDate()->format('Y-m-d'); |
| 295 | return "{$pretty_date}: {$this->getName()}"; |
| 296 | } |
| 297 | |
| 298 | public static function getCriteriaForFilter(string $key, string $value): Expression { |
| 299 | throw new \Exception("No such SolvEvent filter: {$key}"); |
| 300 | } |
| 301 | |
| 302 | public static function getCriteriaForQuery(string $query): Expression { |
| 303 | if (preg_match('/^[0-9]{4}\-[0-9]{2}\-[0-9]{2}$/', $query)) { |
| 304 | return Criteria::expr()->orX( |
| 305 | Criteria::expr()->eq('date', new \DateTime($query)), |
| 306 | Criteria::expr()->contains('name', $query), |
| 307 | ); |
| 308 | } |
| 309 | if (intval($query) > 1900) { |
| 310 | $this_year = strval(intval($query)); |
| 311 | $next_year = strval(intval($query) + 1); |
| 312 | return Criteria::expr()->orX( |
| 313 | Criteria::expr()->andX( |
| 314 | Criteria::expr()->gte('date', new \DateTime("{$this_year}-01-01 00:00:00")), |
| 315 | Criteria::expr()->lt('date', new \DateTime("{$next_year}-01-01 00:00:00")), |
| 316 | ), |
| 317 | Criteria::expr()->contains('name', $query), |
| 318 | ); |
| 319 | } |
| 320 | return Criteria::expr()->orX( |
| 321 | Criteria::expr()->contains('name', $query), |
| 322 | ); |
| 323 | } |
| 324 | } |