ILIAS  release_8 Revision v8.23
ilLSItemsDB.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
25 {
26  protected ilTree $tree;
30 
31  public function __construct(
32  ilTree $tree,
33  ilContainerSorting $container_sorting,
34  ilLSPostConditionDB $post_conditions_db,
35  LSItemOnlineStatus $ls_item_online_status
36  ) {
37  $this->tree = $tree;
38  $this->container_sorting = $container_sorting;
39  $this->post_conditions_db = $post_conditions_db;
40  $this->ls_item_online_status = $ls_item_online_status;
41  }
42 
46  public function getLSItems(int $ref_id): array
47  {
48  $children = $this->tree->getChilds($ref_id);
49 
50  $sorting_settings = $this->container_sorting->getSortingSettings();
51  $sorting_settings->setSortMode(ilContainer::SORT_MANUAL);
52  $sorted = $this->container_sorting->sortItems(['lsitems' => $children]);
53  $children = $sorted['lsitems'];
54 
55  $conditions = $this->getConditionsForChildren($children);
56 
57  $items = [];
58  foreach ($children as $position => $child) {
59  $ref_id = (int) $child['child'];
60  $items[] = new LSItem(
61  $child['type'],
62  $child['title'],
63  $child['description'] ?? "",
64  $this->getIconPathForType($child['type']),
65  $this->ls_item_online_status->getOnlineStatus($ref_id),
66  $position,
67  $conditions[$ref_id],
68  $ref_id
69  );
70  }
71 
72  return $items;
73  }
74 
75  protected function getIconPathForType(string $type): string
76  {
77  return ilObject2::_getIcon(0, "big", $type);
78  }
79 
84  protected function getConditionsForChildren(array $children): array
85  {
86  $ref_ids = array_map(
87  fn ($i) => (int) $i['child'],
88  $children
89  );
90 
91  $conditions = [];
92  foreach ($this->post_conditions_db->select($ref_ids) as $condition) {
93  $conditions[$condition->getRefId()] = $condition;
94  }
95 
96  return $conditions;
97  }
98 
99  protected function storeItemsOrder(array $ls_items): void
100  {
101  $type_positions = [];
102  foreach ($ls_items as $item) {
103  $type_positions[$item->getRefId()] = $item->getOrderNumber();
104  }
105  $this->container_sorting->savePost($type_positions);
106  }
107 
108  protected function storeOnlineStatus(array $ls_items): void
109  {
110  foreach ($ls_items as $item) {
111  $this->ls_item_online_status->setOnlineStatus(
112  $item->getRefId(),
113  $item->isOnline()
114  );
115  }
116  }
117 
118  protected function storePostconditions(array $ls_items): void
119  {
120  $conditions = [];
121  foreach ($ls_items as $item) {
122  $conditions[] = $item->getPostCondition();
123  }
124  $this->post_conditions_db->upsert($conditions);
125  }
126 
130  public function storeItems(array $ls_items): void
131  {
132  $this->storeOnlineStatus($ls_items);
133  $this->storeItemsOrder($ls_items);
134  $this->storePostconditions($ls_items);
135  }
136 
137  // The typehint on ilObject is intentional, we expect this to return some object
138  // or need to error instead.
139  protected function getObjectFor(int $ref_id): \ilObject
140  {
141  return ilObjectFactory::getInstanceByRefId($ref_id);
142  }
143 }
getLSItems(int $ref_id)
Definition: ilLSItemsDB.php:46
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getObjectFor(int $ref_id)
storeItems(array $ls_items)
Use this to apply settings made in ContentGUI.
static _getIcon(int $obj_id=0, string $size="big", string $type="", bool $offline=false)
Get icon for repository item.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: ilLSItemsDB.php:24
$type
ilContainerSorting $container_sorting
Definition: ilLSItemsDB.php:27
storeItemsOrder(array $ls_items)
Definition: ilLSItemsDB.php:99
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: LSItem.php:24
$ref_id
Definition: ltiauth.php:67
LSItemOnlineStatus $ls_item_online_status
Definition: ilLSItemsDB.php:29
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
storeOnlineStatus(array $ls_items)
ilTree $tree
Definition: ilLSItemsDB.php:26
getConditionsForChildren(array $children)
Collect all conditions at once.
Definition: ilLSItemsDB.php:84
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilLSPostConditionDB $post_conditions_db
Definition: ilLSItemsDB.php:28
storePostconditions(array $ls_items)
__construct(ilTree $tree, ilContainerSorting $container_sorting, ilLSPostConditionDB $post_conditions_db, LSItemOnlineStatus $ls_item_online_status)
Definition: ilLSItemsDB.php:31
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getIconPathForType(string $type)
Definition: ilLSItemsDB.php:75
$i
Definition: metadata.php:41