ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ObjectsManager.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
27 
32 {
33  protected int $pool_id;
38 
39  public function __construct(
40  InternalDataService $data,
41  InternalRepoService $repo,
42  InternalDomainService $domain,
43  protected ResourceStakeholder $object_info_stakeholder,
44  protected ResourceStakeholder $book_info_stakeholder,
45  int $pool_id
46  ) {
47  $this->object_repo = $repo->objects();
48  $this->object_repo->loadDataOfPool($pool_id);
49  $this->pool_id = $pool_id;
50  }
51 
52  public function getNrOfItemsForObject(int $book_obj_id): int
53  {
54  return $this->object_repo->getNrOfItemsForObject($book_obj_id);
55  }
56 
57  public function getObjectTitles(): array
58  {
59  $titles = [];
60  foreach ($this->object_repo->getObjectDataForPool($this->pool_id) as $d) {
61  $titles[$d["booking_object_id"]] = $d["title"];
62  }
63  return $titles;
64  }
65 
66  public function getObjectIds(): array
67  {
68  return array_map(static function ($d) {
69  return (int) $d["booking_object_id"];
70  }, $this->object_repo->getObjectDataForPool($this->pool_id));
71  }
72 
73  public function getColorNrForObject(int $book_obj_id): int
74  {
75  return $this->object_repo->getColorNrForObject($book_obj_id);
76  }
77 
78  public function getDataArrayFromInputString(string $input): array
79  {
80  $rows = explode("\n", $input);
81  $data = [];
82  foreach ($rows as $row) {
83  $cells = explode(";", $row);
84  if (count($cells) === 1) {
85  $cells = explode("\t", $row);
86  }
87  $data[] = [
88  "title" => trim($cells[0] ?? ""),
89  "description" => trim($cells[1] ?? ""),
90  "nr" => trim($cells[2] ?? ""),
91  ];
92  }
93  return $data;
94  }
95 
96  public function createObjectsFromBulkInputString(string $input, int $schedule_id): void
97  {
98  foreach ($this->getDataArrayFromInputString($input) as $data) {
99  $object = new \ilBookingObject();
100  $object->setTitle($data["title"]);
101  $object->setDescription($data["description"]);
102  $object->setNrOfItems((int) $data["nr"]);
103  $object->setPoolId($this->pool_id);
104  if ($schedule_id > 0) {
105  $object->setScheduleId($schedule_id);
106  }
107  $object->save();
108  }
109  }
110 
111  //
112  // Object and booking resource management
113  //
114 
115  public function importObjectInfoFromLegacyUpload(int $booking_obj_id, array $file_input): string
116  {
117  if (!isset($file_input["tmp_name"])) {
118  return "";
119  }
120  return $this->object_repo->importObjectInfoFromLegacyUpload(
121  $booking_obj_id,
122  $file_input,
123  $this->object_info_stakeholder
124  );
125  }
126 
127  public function importBookingInfoFromLegacyUpload(int $booking_obj_id, array $file_input): string
128  {
129  if (!isset($file_input["tmp_name"])) {
130  return "";
131  }
132  return $this->object_repo->importBookingInfoFromLegacyUpload(
133  $booking_obj_id,
134  $file_input,
135  $this->book_info_stakeholder
136  );
137  }
138 
139  public function hasObjectInfo(int $booking_obj_id): bool
140  {
141  return $this->object_repo->hasObjectInfo($booking_obj_id);
142  }
143 
144  public function deliverObjectInfo(int $booking_obj_id): void
145  {
146  if ($this->object_repo->hasObjectInfo($booking_obj_id)) {
147  $this->object_repo->deliverObjectInfo($booking_obj_id);
148  }
149  }
150 
151  public function hasBookingInfo(int $booking_obj_id): bool
152  {
153  return $this->object_repo->hasBookingInfo($booking_obj_id);
154  }
155 
156  public function deliverBookingInfo(int $booking_obj_id): void
157  {
158  if ($this->object_repo->hasBookingInfo($booking_obj_id)) {
159  $this->object_repo->deliverBookingInfo($booking_obj_id);
160  }
161  }
162 
163  public function getObjectInfoFilename(int $booking_obj_id): string
164  {
165  return $this->object_repo->getObjectInfoFilename($booking_obj_id);
166  }
167 
168  public function getBookingInfoFilename(int $booking_obj_id): string
169  {
170  return $this->object_repo->getBookingInfoFilename($booking_obj_id);
171  }
172 
173  public function deleteObjectInfo(int $booking_obj_id): void
174  {
175  if ($this->object_repo->hasObjectInfo($booking_obj_id)) {
176  $this->object_repo->deleteObjectInfo($booking_obj_id, $this->object_info_stakeholder);
177  }
178  }
179 
180  public function deleteBookingInfo(int $booking_obj_id): void
181  {
182  if ($this->object_repo->hasBookingInfo($booking_obj_id)) {
183  $this->object_repo->deleteBookingInfo($booking_obj_id, $this->book_info_stakeholder);
184  }
185  }
186 
187  public function cloneTo(
188  int $from_booking_obj_id,
189  int $to_booking_obj_id
190  ): void {
191  if ($this->object_repo->hasObjectInfo($from_booking_obj_id) ||
192  $this->object_repo->hasBookingInfo($from_booking_obj_id)) {
193  $this->object_repo->clone($from_booking_obj_id, $to_booking_obj_id);
194  }
195  }
196 
197  public function getObjectInfoPath(int $booking_object_id): string
198  {
199  return $this->object_repo->getObjectInfoPath($booking_object_id);
200  }
201 
202  public function getBookingInfoPath(int $booking_object_id): string
203  {
204  return $this->object_repo->getBookingInfoPath($booking_object_id);
205  }
206 
207 }
cloneTo(int $from_booking_obj_id, int $to_booking_obj_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Author: Alexander Killing killing@leifos.de
importBookingInfoFromLegacyUpload(int $booking_obj_id, array $file_input)
createObjectsFromBulkInputString(string $input, int $schedule_id)
importObjectInfoFromLegacyUpload(int $booking_obj_id, array $file_input)
__construct(InternalDataService $data, InternalRepoService $repo, InternalDomainService $domain, protected ResourceStakeholder $object_info_stakeholder, protected ResourceStakeholder $book_info_stakeholder, int $pool_id)