ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilLSItemsDB.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
12 {
16  protected $tree;
17 
21  protected $container_sorting;
22 
27 
32 
33  public function __construct(
34  ilTree $tree,
38  ) {
39  $this->tree = $tree;
40  $this->container_sorting = $container_sorting;
41  $this->post_conditions_db = $post_conditions_db;
42  $this->ls_item_online_status = $ls_item_online_status;
43  }
44 
45  public function getLSItems(int $ref_id) : array
46  {
47  $children = $this->tree->getChilds($ref_id);
48 
49  $sorting_settings = $this->container_sorting->getSortingSettings();
50  $sorting_settings->setSortMode(ilContainer::SORT_MANUAL);
51  $sorted = $this->container_sorting->sortItems(array('lsitems' => $children));
52  $children = $sorted['lsitems'];
53 
54  $conditions = $this->getConditionsForChildren($children);
55 
56  $items = [];
57  foreach ($children as $position => $child) {
58  $ref_id = (int) $child['child'];
59  $icon_path = ilObject2::_getIcon("", "big", $child['type']);
60  $items[] = new LSItem(
61  $child['type'],
62  $child['title'],
63  $child['description'] ?? "",
64  $icon_path = $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("", "big", $type);
78  }
79 
84  protected function getConditionsForChildren(array $children) : array
85  {
86  $ref_ids = array_map(
87  function ($i) {
88  return (int) $i['child'];
89  },
90  $children
91  );
92 
93  $conditions = [];
94  foreach ($this->post_conditions_db->select($ref_ids) as $condition) {
95  $conditions[$condition->getRefId()] = $condition;
96  }
97 
98  return $conditions;
99  }
100 
101  protected function storeItemsOrder(array $ls_items)
102  {
103  $type_positions = [];
104  foreach ($ls_items as $item) {
105  $type_positions[$item->getRefId()] = $item->getOrderNumber();
106  }
107  $this->container_sorting->savePost($type_positions);
108  }
109 
110  protected function storeOnlineStatus(array $ls_items)
111  {
112  foreach ($ls_items as $item) {
113  $this->ls_item_online_status->setOnlineStatus(
114  $item->getRefId(),
115  $item->isOnline()
116  );
117  }
118  }
119 
120  protected function storePostconditions(array $ls_items)
121  {
122  $conditions = [];
123  foreach ($ls_items as $item) {
124  $conditions[] = $item->getPostCondition();
125  }
126  $this->post_conditions_db->upsert($conditions);
127  }
128 
132  public function storeItems(array $ls_items)
133  {
134  $this->storeOnlineStatus($ls_items);
135  $this->storeItemsOrder($ls_items);
136  $this->storePostconditions($ls_items);
137  }
138 
139  protected function getObjectFor(int $ref_id) : ilObject
140  {
141  return ilObjectFactory::getInstanceByRefId($ref_id);
142  }
143 }
getLSItems(int $ref_id)
Definition: ilLSItemsDB.php:45
Storage for ilLSPostConditions.
getObjectFor(int $ref_id)
storeItems(array $ls_items)
Use this to apply settings made in ContentGUI.
Class ilLSItemsDB.
Definition: ilLSItemsDB.php:11
$type
storeItemsOrder(array $ls_items)
static _getIcon($a_obj_id="", $a_size="big", $a_type="", $a_offline=false)
Data holding class LSItem .
Definition: LSItem.php:11
storeOnlineStatus(array $ls_items)
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
getConditionsForChildren(array $children)
Collect all conditions at once.
Definition: ilLSItemsDB.php:84
$i
Definition: disco.tpl.php:19
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
storePostconditions(array $ls_items)
__construct(ilTree $tree, ilContainerSorting $container_sorting, ilLSPostConditionDB $post_conditions_db, LSItemOnlineStatus $ls_item_online_status)
Definition: ilLSItemsDB.php:33
getIconPathForType(string $type)
Definition: ilLSItemsDB.php:75