3 declare(strict_types=0);
23 $this->tree = $DIC->repositoryTree();
24 $this->objDefinition = $DIC[
'objDefinition'];
31 bool $a_full_data =
false 35 $cache_idx = $a_ref_id .
"__" . $a_full_data;
36 if (!isset(self::$possible_items[$cache_idx])) {
37 $all_possible = array();
39 if (!$this->tree->isDeleted($a_ref_id)) {
41 $data = $this->tree->getRbacSubtreeInfo($a_ref_id);
43 $node = $this->tree->getNodeData($a_ref_id);
44 $data = $this->tree->getSubTree($node);
46 foreach (
$data as $node) {
48 $item_ref_id = (
int) $node[
'child'];
50 $item_ref_id = (
int) $node[
'ref_id'];
60 switch ($node[
'type']) {
81 $all_possible[] = $item_ref_id;
83 $all_possible[$item_ref_id] = array(
84 'ref_id' => (
int) $item_ref_id,
85 'obj_id' => (
int) $node[
'obj_id'],
86 'title' => (
string) $node[
'title'],
87 'description' => (
string) $node[
'description'],
88 'type' => (
string) $node[
'type']
94 case $this->objDefinition->isPluginTypeName(
106 $all_possible[] = $item_ref_id;
108 $all_possible[$item_ref_id] = array(
109 'ref_id' => (
int) $item_ref_id,
110 'obj_id' => (
int) $node[
'obj_id'],
111 'title' => (
string) $node[
'title'],
112 'description' => (
string) $node[
'description'],
113 'type' => (
string) $node[
'type']
122 self::$possible_items[$cache_idx] = $all_possible;
125 return self::$possible_items[$cache_idx];
132 if ($a_item_type ==
'tst') {
136 if ($olp->isAnonymized()) {
145 parent::cloneCollection($a_target_id, $a_copy_id);
148 $mappings = $cwo->getMappings();
151 $target_collection =
new static($target_obj_id,
$this->mode);
155 ) as $grouping_id => $group) {
156 $target_item_ids = array();
157 foreach ($group[
"items"] as $item) {
158 if (!isset($mappings[$item]) or !$mappings[$item]) {
162 $target_item_ids[] = $mappings[$item];
166 if ($grouping_id &&
sizeof($target_item_ids) > 1) {
168 $num_obligatory = min(
169 sizeof($target_item_ids),
170 $group[
"num_obligatory"]
173 $target_collection->createNewGrouping(
179 foreach ($target_item_ids as $item_id) {
186 protected function read(
int $a_obj_id): void
194 $res = $this->db->query(
195 "SELECT utc.item_id, obd.type" .
196 " FROM ut_lp_collections utc" .
197 " JOIN object_reference obr ON item_id = ref_id" .
198 " JOIN object_data obd ON obr.obj_id = obd.obj_id" .
199 " WHERE utc.obj_id = " . $this->db->quote($a_obj_id,
"integer") .
200 " AND active = " . $this->db->quote(1,
"integer") .
204 if (in_array($row->item_id, $possible) &&
222 $query =
"INSERT INTO ut_lp_collections" .
223 " (obj_id, lpmode, item_id, grouping_id, num_obligatory, active)" .
224 " VALUES (" . $this->db->quote($this->obj_id,
"integer") .
225 ", " . $this->db->quote($this->mode,
"integer") .
226 ", " . $this->db->quote($a_item_id,
"integer") .
227 ", " . $this->db->quote(0,
"integer") .
228 ", " . $this->db->quote(0,
"integer") .
229 ", " . $this->db->quote(1,
"integer") .
231 $this->db->manipulate($query);
232 $this->items[] = $a_item_id;
239 $query =
"DELETE FROM ut_lp_collections " .
240 " WHERE obj_id = " . $this->db->quote($this->obj_id,
"integer") .
241 " AND item_id = " . $this->db->quote($a_item_id,
"integer") .
242 " AND grouping_id = " . $this->db->quote(0,
"integer");
243 $this->db->manipulate($query);
251 $ilDB = $DIC[
'ilDB'];
252 $query =
"SELECT item_id FROM ut_lp_collections" .
253 " WHERE obj_id = " .
$ilDB->quote($a_obj_id,
"integer") .
254 " AND grouping_id > " .
$ilDB->quote(0,
"integer");
256 return $res->numRows() ? true :
false;
261 $grouped_item_ids = [];
263 $query =
"SELECT item_id FROM ut_lp_collections" .
267 $res = $this->db->query($query);
268 while ($row =
$res->fetchObject()) {
269 $grouped_item_ids[] = $row->item_id;
272 return array_diff($a_item_ids, $grouped_item_ids);
279 $query =
"SELECT grouping_id FROM ut_lp_collections" .
283 $res = $this->db->query($query);
284 while ($row =
$res->fetchObject()) {
285 $grouping_ids[] = $row->grouping_id;
288 return $grouping_ids;
293 parent::deactivateEntries($a_item_ids);
297 $query =
"UPDATE ut_lp_collections" .
298 " SET active = " . $this->db->quote(0,
"integer") .
299 " WHERE " . $this->db->in(
305 " AND obj_id = " . $this->db->quote($this->obj_id,
"integer");
306 $this->db->manipulate($query);
314 parent::activateEntries($non_grouped_ids);
318 $query =
"UPDATE ut_lp_collections" .
319 " SET active = " . $this->db->quote(1,
"integer") .
320 " WHERE " . $this->db->in(
326 " AND obj_id = " . $this->db->quote($this->obj_id,
"integer");
327 $this->db->manipulate($query);
333 int $a_num_obligatory = 1
337 $all_item_ids = array();
339 $query =
"SELECT item_id FROM ut_lp_collections" .
340 " WHERE obj_id = " . $this->db->quote($this->obj_id,
"integer") .
341 " AND " . $this->db->in(
347 $res = $this->db->query($query);
349 $all_item_ids[] = $row->item_id;
352 $all_item_ids = array_unique(array_merge($all_item_ids, $a_item_ids));
357 $query =
"SELECT MAX(grouping_id) grp FROM ut_lp_collections" .
358 " WHERE obj_id = " . $this->db->quote($this->obj_id,
"integer") .
360 $res = $this->db->query($query);
365 $query =
"UPDATE ut_lp_collections SET" .
366 " grouping_id = " . $this->db->quote($grp_id,
"integer") .
367 ", num_obligatory = " . $this->db->quote(
371 ", active = " . $this->db->quote(1,
"integer") .
372 " WHERE obj_id = " . $this->db->quote($this->obj_id,
"integer") .
373 " AND " . $this->db->in(
"item_id", $all_item_ids,
false,
"integer");
374 $this->db->manipulate($query);
381 $query =
"UPDATE ut_lp_collections" .
382 " SET grouping_id = " . $this->db->quote(0,
"integer") .
383 ", num_obligatory = " . $this->db->quote(0,
"integer") .
384 " WHERE obj_id = " . $this->db->quote($this->obj_id,
"integer") .
385 " AND " . $this->db->in(
391 $this->db->manipulate($query);
396 foreach ($a_obl as $grouping_id => $num) {
397 $query =
"SELECT count(obj_id) num FROM ut_lp_collections" .
398 " WHERE obj_id = " . $this->db->quote(
402 " AND grouping_id = " . $this->db->quote(
407 $res = $this->db->query($query);
409 if ($num <= 0 || $num >= $row->num) {
414 foreach ($a_obl as $grouping_id => $num) {
415 $query =
"UPDATE ut_lp_collections" .
416 " SET num_obligatory = " . $this->db->quote($num,
"integer") .
417 " WHERE obj_id = " . $this->db->quote(
421 " AND grouping_id = " . $this->db->quote(
425 $this->db->manipulate($query);
435 foreach (
$items as $item_id => $item) {
436 if (in_array($item_id, $done)) {
443 $table_item[
'grouped'] = array();
445 if (count((array) ($grouped_items[
'items'] ?? [])) > 1) {
446 foreach ($grouped_items[
'items'] as $grouped_item_id) {
447 if ($grouped_item_id == $item_id ||
448 !is_array(
$items[$grouped_item_id] ??
false)) {
456 $table_item[
'num_obligatory'] = $grouped_items[
'num_obligatory'];
457 $table_item[
'grouping_id'] = $grouped_items[
'grouping_id'];
459 $done[] = $grouped_item_id;
462 $data[] = $table_item;
469 $table_item = $a_item;
470 $table_item[
'id'] = $a_id;
474 $table_item[
'mode_id'] = $olp->getCurrentMode();
475 $table_item[
'mode'] = $olp->getModeText($table_item[
'mode_id']);
476 $table_item[
'anonymized'] = $olp->isAnonymized();
484 $query =
"SELECT grouping_id FROM ut_lp_collections" .
485 " WHERE obj_id = " . $this->db->quote($this->obj_id,
"integer") .
486 " AND item_id = " . $this->db->quote($item_id,
"integer");
487 $res = $this->db->query($query);
490 $grouping_id = (
int) $row->grouping_id;
492 if ($grouping_id > 0) {
493 $query =
"SELECT item_id, num_obligatory FROM ut_lp_collections" .
494 " WHERE obj_id = " . $this->db->quote(
498 " AND grouping_id = " . $this->db->quote(
502 $res = $this->db->query($query);
505 $items[
'num_obligatory'] = (
int) $row->num_obligatory;
506 $items[
'grouping_id'] = (
int) $grouping_id;
515 $query =
" SELECT * FROM ut_lp_collections" .
516 " WHERE obj_id = " . $this->db->quote($this->obj_id,
"integer") .
517 " AND active = " . $this->db->quote(1,
"integer");
518 $res = $this->db->query($query);
522 if (in_array($row->item_id,
$items)) {
523 $grouped[$row->grouping_id][
'items'][] = (
int) $row->item_id;
524 $grouped[$row->grouping_id][
'num_obligatory'] = (
int) $row->num_obligatory;
releaseGrouping(array $a_item_ids)
ilObjectDefinition $objDefinition
createNewGrouping(array $a_item_ids, int $a_num_obligatory=1)
getGroupingIds(array $a_item_ids)
getGroupedItemsForLPStatus()
static _getAllReferences(int $id)
get all reference ids for object ID
isAssignedEntry(int $a_item_id)
saveObligatoryMaterials(array $a_obl)
getTableGUIData(int $a_parent_ref_id)
static _lookupObjId(int $ref_id)
LP collection of repository objects.
parses the objects.xml it handles the xml-description of all ilias objects
__construct(int $a_obj_id, int $a_mode)
getNonGroupedItems(array $a_item_ids)
getTableGUItemGroup(int $item_id)
cloneCollection(int $a_target_id, int $a_copy_id)
static array $possible_items
deactivateEntries(array $a_item_ids)
static hasGroupedItems(int $a_obj_id)
LP collection base class.
activateEntries(array $a_item_ids)
static isTypePluginWithLP(string $a_type, bool $a_active_status=true)
validateEntry(int $a_item_id)
static _getInstance(int $a_copy_id)
parseTableGUIItem(int $a_id, array $a_item)
static _lookupType(int $id, bool $reference=false)
static getInstance(int $obj_id)
getPossibleItems(int $a_ref_id, bool $a_full_data=false)
deleteEntry(int $a_item_id)