ILIAS  trunk Revision v11.0_alpha-2662-g519ff7d528f
CoreProperties.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
24 
29 {
30  private const FIELDS = [
31  'object_id' => 'int',
32  'owner' => 'int',
33  'create_date' => 'DateTimeImmutable',
34  'update_date' => 'DateTimeImmutable',
35  'import_id' => 'text',
36  'type' => 'text'
37  ];
38  private ?int $object_id = null;
39  private ?string $type = null;
40  private ?int $owner = null;
41  private ?\DateTimeImmutable $create_date = null;
42  private ?\DateTimeImmutable $update_date = null;
43  private ?string $import_id = '';
44 
49  public function __construct(
50  private TitleAndDescription $property_title_and_description,
51  private Online $property_is_online,
52  private PropertyTileImage $property_tile_image,
53  ?array $data = null
54  ) {
55  if ($this->checkDataArray($data)) {
56  $this->setValuesByArray($data);
57  }
58  }
59 
60  public function getObjectId(): ?int
61  {
62  return $this->object_id;
63  }
64 
65  public function getType(): ?string
66  {
67  return $this->type;
68  }
69 
70  public function withType(?string $type): self
71  {
72  $clone = clone $this;
73  $clone->type = $type;
74  return $clone;
75  }
76 
77  public function getOwner(): ?int
78  {
79  return $this->owner;
80  }
81 
82  public function withOwner(int $owner): self
83  {
84  $clone = clone $this;
85  $clone->owner = $owner;
86  return $clone;
87  }
88 
89  public function getCreateDate(): ?\DateTimeImmutable
90  {
91  return $this->create_date;
92  }
93 
94  public function getLastUpdateDate(): ?\DateTimeImmutable
95  {
96  return $this->update_date;
97  }
98 
99  public function getImportId(): string
100  {
101  return $this->import_id ?? '';
102  }
103 
104  public function withImportId(string $import_id): self
105  {
106  $clone = clone $this;
107  $clone->import_id = $import_id;
108  return $clone;
109  }
110 
112  {
113  return $this->property_title_and_description;
114  }
115 
116  public function withPropertyTitleAndDescription(TitleAndDescription $property_title_and_description): self
117  {
118  $clone = clone $this;
119  $clone->property_title_and_description = $property_title_and_description;
120  return $clone;
121  }
122 
123  public function getPropertyIsOnline(): Online
124  {
125  return $this->property_is_online;
126  }
127 
128  public function withPropertyIsOnline(Online $property_is_online): self
129  {
130  $clone = clone $this;
131  $clone->property_is_online = $property_is_online;
132  return $clone;
133  }
134 
135  public function getPropertyTileImage(): PropertyTileImage
136  {
137  return $this->property_tile_image;
138  }
139 
140  public function withPropertyTileImage(PropertyTileImage $property_tile_image): self
141  {
142  $clone = clone $this;
143  $clone->property_tile_image = $property_tile_image;
144  return $clone;
145  }
146 
147 
152  protected function checkDataArray(?array $data): bool
153  {
154  if ($data === null) {
155  return false;
156  }
157 
158  if (array_diff_key(self::FIELDS, $data)
159  || array_diff_key($data, self::FIELDS)) {
160  return false;
161  }
162 
163  if ($data['object_id'] === null || $data['owner'] === null) {
164  return false;
165  }
166 
167  if (!is_int($data['object_id']) || !is_int($data['owner'])) {
168  return false;
169  }
170 
171  return $this->checkTypesOfDataArray($data);
172  }
173 
178  protected function setValuesByArray(array $data): void
179  {
180  foreach ($data as $key => $value) {
181  $this->$key = $value;
182  }
183  }
184 
185  protected function checkTypesOfDataArray(array $data): bool
186  {
187  foreach (self::FIELDS as $key => $value) {
188  if ($data[$key] === null) {
189  continue;
190  }
191  if ($value === 'int' && !is_int($data[$key])) {
192  return false;
193  }
194  if ($value === 'text' && !is_string($data[$key])) {
195  return false;
196  }
197  if ($value === 'bool' && !is_bool($data[$key])) {
198  return false;
199  }
200  if ($value === 'DateTimeImmutable' && !$data[$key] instanceof \DateTimeImmutable) {
201  return false;
202  }
203  }
204  return true;
205  }
206 }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
withPropertyTileImage(PropertyTileImage $property_tile_image)
__construct(private TitleAndDescription $property_title_and_description, private Online $property_is_online, private PropertyTileImage $property_tile_image, ?array $data=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
withPropertyTitleAndDescription(TitleAndDescription $property_title_and_description)