ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
class.ilItemGroupItems.php
Go to the documentation of this file.
1<?php
2
26{
27 protected ilDBInterface $db;
30 protected ilLogger $log;
32 public ilTree $tree;
34 public int $item_group_id = 0;
35 public int $item_group_ref_id = 0;
36 public array $items = array();
37
38 public function __construct(
39 int $a_item_group_ref_id = 0
40 ) {
41 global $DIC;
42
43 $this->obj_data_cache = $DIC["ilObjDataCache"];
44 $this->log = $DIC["ilLog"];
45 $this->db = $DIC->database();
46 $this->lng = $DIC->language();
47 $this->tree = $DIC->repositoryTree();
48 $this->obj_def = $DIC["objDefinition"];
49 $this->access = $DIC->access();
50
51 $this->setItemGroupRefId($a_item_group_ref_id);
52 if ($this->getItemGroupRefId() > 0) {
53 $this->setItemGroupId(ilObject::_lookupObjId($a_item_group_ref_id));
54 }
55
56 if ($this->getItemGroupId() > 0) {
57 $this->read();
58 }
59 }
60
61 public function setItemGroupId(int $a_val): void
62 {
63 $this->item_group_id = $a_val;
64 }
65
66 public function getItemGroupId(): int
67 {
69 }
70
71 public function setItemGroupRefId(int $a_val): void
72 {
73 $this->item_group_ref_id = $a_val;
74 }
75
76 public function getItemGroupRefId(): int
77 {
79 }
80
84 public function setItems(array $a_val): void
85 {
86 $this->items = $a_val;
87 }
88
89 public function getItems(): array
90 {
91 return $this->items;
92 }
93
94 public function addItem(int $a_item_ref_id): void
95 {
96 if (!in_array($a_item_ref_id, $this->items)) {
97 $this->items[] = $a_item_ref_id;
98 }
99 }
100
101 public function delete(): void
102 {
103 $query = "DELETE FROM item_group_item " .
104 "WHERE item_group_id = " . $this->db->quote($this->getItemGroupId(), 'integer');
105 $this->db->manipulate($query);
106 }
107
108 public function update(): void
109 {
110 $this->delete();
111
112 foreach ($this->items as $item) {
113 $query = "INSERT INTO item_group_item (item_group_id,item_ref_id) " .
114 "VALUES( " .
115 $this->db->quote($this->getItemGroupId(), 'integer') . ", " .
116 $this->db->quote($item, 'integer') . " " .
117 ")";
118 $this->db->manipulate($query);
119 }
120 }
121
122 public function read(): void
123 {
124 $this->items = array();
125 $set = $this->db->query(
126 "SELECT * FROM item_group_item " .
127 " WHERE item_group_id = " . $this->db->quote($this->getItemGroupId(), "integer")
128 );
129 while ($rec = $this->db->fetchAssoc($set)) {
130 $this->items[] = $rec["item_ref_id"];
131 }
132 }
133
134 public function getAssignableItems(): array
135 {
136 if ($this->getItemGroupRefId() <= 0) {
137 return array();
138 }
139
140 $parent_node = $this->tree->getNodeData(
141 $this->tree->getParentId($this->getItemGroupRefId())
142 );
143
144 $materials = array();
145 $nodes = $this->tree->getChilds($parent_node["child"]);
146
147 foreach ($nodes as $node) {
148 // filter side blocks and session, item groups and role folder
149 if ($node['child'] == $parent_node["child"] ||
150 $this->obj_def->isSideBlock($node['type']) ||
151 in_array($node['type'], array('sess', 'itgr', 'rolf', 'adm'))) {
152 continue;
153 }
154
155 // filter hidden files
156 // see http://www.ilias.de/mantis/view.php?id=10269
157 if ($node['type'] == "file" &&
158 ilObjFileAccess::_isFileHidden((string) $node['title'])) {
159 continue;
160 }
161
162 if ($this->obj_def->isInactivePlugin((string) $node['type'])) {
163 continue;
164 }
165
166 if (!$this->access->checkAccess('visible', '', $node['ref_id'])) {
167 continue;
168 }
169
170 $materials[] = $node;
171 }
172
173 $materials = ilArrayUtil::sortArray($materials, "title", "asc");
174
175 return $materials;
176 }
177
178 public function getValidItems(): array
179 {
180 $items = $this->getItems();
181 $ass_items = $this->getAssignableItems();
182 $valid_items = array();
183 foreach ($ass_items as $aitem) {
184 if (in_array($aitem["ref_id"], $items)) {
185 $valid_items[] = $aitem["ref_id"];
186 }
187 }
188 return $valid_items;
189 }
190
191 public function cloneItems(
192 int $a_source_id,
193 int $a_copy_id
194 ): void {
195 $ilLog = $this->log;
196
197 $ilLog->write(__METHOD__ . ': Begin cloning item group materials ... -' . $a_source_id . '-');
198
199 $cwo = ilCopyWizardOptions::_getInstance($a_copy_id);
200 $mappings = $cwo->getMappings();
201
202 $new_items = array();
203 // check: is this a ref id!?
204 $source_ig = new ilItemGroupItems($a_source_id);
205 foreach ($source_ig->getItems() as $item_ref_id) {
206 if (isset($mappings[$item_ref_id]) and $mappings[$item_ref_id]) {
207 $ilLog->write(__METHOD__ . ': Clone item group item nr. ' . $item_ref_id);
208 $new_items[] = $mappings[$item_ref_id];
209 } else {
210 $ilLog->write(__METHOD__ . ': No mapping found for item group item nr. ' . $item_ref_id);
211 }
212 }
213 $this->setItems($new_items);
214 $this->update();
215 $ilLog->write(__METHOD__ . ': Finished cloning item group items ...');
216 }
217
218 public static function _getItemsOfContainer(int $a_ref_id): array
219 {
220 global $DIC;
221
222 $ilDB = $DIC->database();
223 $tree = $DIC->repositoryTree();
224
225 $itgr_ids = [];
226 $itgr_nodes = $tree->getChildsByType($a_ref_id, 'itgr');
227 foreach ($itgr_nodes as $node) {
228 $itgr_ids[] = $node['obj_id'];
229 }
230 $query = "SELECT item_ref_id FROM item_group_item " .
231 "WHERE " . $ilDB->in('item_group_id', $itgr_ids, false, 'integer');
232
233
234 $res = $ilDB->query($query);
235 $items = [];
236 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
237 $items[] = $row->item_ref_id;
238 }
239 return $items;
240 }
241}
static sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)
static _getInstance(int $a_copy_id)
const FETCHMODE_OBJECT
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
cloneItems(int $a_source_id, int $a_copy_id)
ilObjectDefinition $obj_def
__construct(int $a_item_group_ref_id=0)
static _getItemsOfContainer(int $a_ref_id)
ilObjectDataCache $obj_data_cache
addItem(int $a_item_ref_id)
language handling
Component logger with individual log levels by component id.
static _isFileHidden(string $a_file_name)
Returns true, if a file with the specified name, is usually hidden from the user.
class ilObjectDataCache
parses the objects.xml it handles the xml-description of all ilias objects
static _lookupObjId(int $ref_id)
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
getChildsByType(int $a_node_id, string $a_type)
get child nodes of given node by object type
Interface ilAccessHandler This interface combines all available interfaces which can be called via gl...
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:26