ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ObjectsManager.php
Go to the documentation of this file.
1 <?php declare(strict_types=1);
2 
17 
21 
26 {
27  protected int $pool_id;
32 
33  public function __construct(
34  InternalDataService $data,
35  InternalRepoService $repo,
36  InternalDomainService $domain,
37  int $pool_id
38  ) {
39  $this->object_repo = $repo->objects();
40  $this->object_repo->loadDataOfPool($pool_id);
41  $this->pool_id = $pool_id;
42  }
43 
44  public function getNrOfItemsForObject(int $book_obj_id) : int
45  {
46  return $this->object_repo->getNrOfItemsForObject($book_obj_id);
47  }
48 
49  public function getObjectTitles() : array
50  {
51  $titles = [];
52  foreach ($this->object_repo->getObjectDataForPool($this->pool_id) as $d) {
53  $titles[$d["booking_object_id"]] = $d["title"];
54  }
55  return $titles;
56  }
57 
58  public function getObjectIds() : array
59  {
60  return array_map(static function ($d) {
61  return (int) $d["booking_object_id"];
62  }, $this->object_repo->getObjectDataForPool($this->pool_id));
63  }
64 
65  public function getColorNrForObject(int $book_obj_id) : int
66  {
67  return $this->object_repo->getColorNrForObject($book_obj_id);
68  }
69 
70  public function getDataArrayFromInputString(string $input) : array
71  {
72  $rows = explode("\n", $input);
73  $data = [];
74  foreach ($rows as $row) {
75  $cells = explode(";", $row);
76  if (count($cells) === 1) {
77  $cells = explode("\t", $row);
78  }
79  $data[] = [
80  "title" => trim($cells[0] ?? ""),
81  "description" => trim($cells[1] ?? ""),
82  "nr" => trim($cells[2] ?? ""),
83  ];
84  }
85  return $data;
86  }
87 
88  public function createObjectsFromBulkInputString(string $input, int $schedule_id) : void
89  {
90  foreach ($this->getDataArrayFromInputString($input) as $data) {
91  $object = new \ilBookingObject();
92  $object->setTitle($data["title"]);
93  $object->setDescription($data["description"]);
94  $object->setNrOfItems((int) $data["nr"]);
95  $object->setPoolId($this->pool_id);
96  if ($schedule_id > 0) {
97  $object->setScheduleId($schedule_id);
98  }
99  $object->save();
100  }
101  }
102 
103 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(InternalDataService $data, InternalRepoService $repo, InternalDomainService $domain, int $pool_id)
createObjectsFromBulkInputString(string $input, int $schedule_id)