ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ResourceCollection.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
25
33{
34 public const NO_SPECIFIC_OWNER = -1;
35 private array $resource_identifications = [];
39 private string $title = 'default';
40
41 public function __construct(private ResourceCollectionIdentification $identification, private int $owner, string $title)
42 {
43 }
44
46 {
47 return $this->identification;
48 }
49
50 public function hasSpecificOwner(): bool
51 {
52 return $this->owner !== self::NO_SPECIFIC_OWNER;
53 }
54
55 public function getOwner(): int
56 {
57 return $this->owner;
58 }
59
60 public function getTitle(): string
61 {
62 return $this->title;
63 }
64
65 public function add(ResourceIdentification $identification): void
66 {
67 if ($this->isIn($identification)) {
68 return;
69 }
70 $this->resource_identifications[] = $identification;
71 }
72
73 public function remove(ResourceIdentification $identification): void
74 {
75 $this->resource_identifications = array_filter(
76 $this->resource_identifications,
77 fn(ResourceIdentification $i): bool => $i->serialize() !== $identification->serialize()
78 );
79 }
80
81 public function isIn(ResourceIdentification $identification): bool
82 {
83 foreach ($this->resource_identifications as $i) {
84 if ($i->serialize() === $identification->serialize()) {
85 return true;
86 }
87 }
88 return false;
89 }
90
94 public function getResourceIdentifications(): array
95 {
97 }
98
99 public function count(): int
100 {
101 return count($this->resource_identifications);
102 }
103
104 public function clear(): void
105 {
106 $this->resource_identifications = [];
107 }
108}
add(ResourceIdentification $identification)
isIn(ResourceIdentification $identification)
__construct(private ResourceCollectionIdentification $identification, private int $owner, string $title)