19 declare(strict_types=0);
37 $this->tree = $DIC->repositoryTree();
38 $this->objDefinition = $DIC[
'objDefinition'];
45 bool $a_full_data =
false 49 $cache_idx = $a_ref_id .
"__" . $a_full_data;
50 if (!isset(self::$possible_items[$cache_idx])) {
51 $all_possible = array();
53 if (!$this->tree->isDeleted($a_ref_id)) {
55 $data = $this->tree->getRbacSubtreeInfo($a_ref_id);
57 $node = $this->tree->getNodeData($a_ref_id);
58 $data = $this->tree->getSubTree($node);
60 foreach (
$data as $node) {
62 $item_ref_id = (
int) $node[
'child'];
64 $item_ref_id = (
int) $node[
'ref_id'];
74 switch ($node[
'type']) {
95 $all_possible[] = $item_ref_id;
97 $all_possible[$item_ref_id] = array(
98 'ref_id' => (
int) $item_ref_id,
99 'obj_id' => (
int) $node[
'obj_id'],
100 'title' => (
string) $node[
'title'],
101 'description' => (
string) $node[
'description'],
102 'type' => (
string) $node[
'type']
108 case $this->objDefinition->isPluginTypeName(
111 $only_active =
false;
120 $all_possible[] = $item_ref_id;
122 $all_possible[$item_ref_id] = array(
123 'ref_id' => (
int) $item_ref_id,
124 'obj_id' => (
int) $node[
'obj_id'],
125 'title' => (
string) $node[
'title'],
126 'description' => (
string) $node[
'description'],
127 'type' => (
string) $node[
'type']
136 self::$possible_items[$cache_idx] = $all_possible;
139 return self::$possible_items[$cache_idx];
146 if ($a_item_type ==
'tst') {
150 if ($olp->isAnonymized()) {
159 parent::cloneCollection($a_target_id, $a_copy_id);
162 $mappings = $cwo->getMappings();
165 $target_collection =
new static($target_obj_id,
$this->mode);
169 ) as $grouping_id => $group) {
170 $target_item_ids = array();
171 foreach ($group[
"items"] as $item) {
172 if (!isset($mappings[$item]) or !$mappings[$item]) {
176 $target_item_ids[] = $mappings[$item];
180 if ($grouping_id &&
sizeof($target_item_ids) > 1) {
182 $num_obligatory = min(
183 sizeof($target_item_ids),
184 $group[
"num_obligatory"]
187 $target_collection->createNewGrouping(
193 foreach ($target_item_ids as $item_id) {
200 protected function read(
int $a_obj_id): void
208 $res = $this->db->query(
209 "SELECT utc.item_id, obd.type" .
210 " FROM ut_lp_collections utc" .
211 " JOIN object_reference obr ON item_id = ref_id" .
212 " JOIN object_data obd ON obr.obj_id = obd.obj_id" .
213 " WHERE utc.obj_id = " . $this->db->quote($a_obj_id,
"integer") .
214 " AND active = " . $this->db->quote(1,
"integer") .
218 if (in_array($row->item_id, $possible) &&
236 $query =
"INSERT INTO ut_lp_collections" .
237 " (obj_id, lpmode, item_id, grouping_id, num_obligatory, active)" .
238 " VALUES (" . $this->db->quote($this->obj_id,
"integer") .
239 ", " . $this->db->quote($this->mode,
"integer") .
240 ", " . $this->db->quote($a_item_id,
"integer") .
241 ", " . $this->db->quote(0,
"integer") .
242 ", " . $this->db->quote(0,
"integer") .
243 ", " . $this->db->quote(1,
"integer") .
245 $this->db->manipulate($query);
246 $this->items[] = $a_item_id;
253 $query =
"DELETE FROM ut_lp_collections " .
254 " WHERE obj_id = " . $this->db->quote($this->obj_id,
"integer") .
255 " AND item_id = " . $this->db->quote($a_item_id,
"integer") .
256 " AND grouping_id = " . $this->db->quote(0,
"integer");
257 $this->db->manipulate($query);
265 $ilDB = $DIC[
'ilDB'];
266 $query =
"SELECT item_id FROM ut_lp_collections" .
267 " WHERE obj_id = " .
$ilDB->quote($a_obj_id,
"integer") .
268 " AND grouping_id > " .
$ilDB->quote(0,
"integer");
270 return $res->numRows() ? true :
false;
275 $grouped_item_ids = [];
277 $query =
"SELECT item_id FROM ut_lp_collections" .
281 $res = $this->db->query($query);
282 while ($row =
$res->fetchObject()) {
283 $grouped_item_ids[] = $row->item_id;
286 return array_diff($a_item_ids, $grouped_item_ids);
293 $query =
"SELECT grouping_id FROM ut_lp_collections" .
297 $res = $this->db->query($query);
298 while ($row =
$res->fetchObject()) {
299 $grouping_ids[] = $row->grouping_id;
302 return $grouping_ids;
307 parent::deactivateEntries($a_item_ids);
311 $query =
"UPDATE ut_lp_collections" .
312 " SET active = " . $this->db->quote(0,
"integer") .
313 " WHERE " . $this->db->in(
319 " AND obj_id = " . $this->db->quote($this->obj_id,
"integer");
320 $this->db->manipulate($query);
328 parent::activateEntries($non_grouped_ids);
332 $query =
"UPDATE ut_lp_collections" .
333 " SET active = " . $this->db->quote(1,
"integer") .
334 " WHERE " . $this->db->in(
340 " AND obj_id = " . $this->db->quote($this->obj_id,
"integer");
341 $this->db->manipulate($query);
347 int $a_num_obligatory = 1
351 $all_item_ids = array();
353 $query =
"SELECT item_id FROM ut_lp_collections" .
354 " WHERE obj_id = " . $this->db->quote($this->obj_id,
"integer") .
355 " AND " . $this->db->in(
361 $res = $this->db->query($query);
363 $all_item_ids[] = $row->item_id;
366 $all_item_ids = array_unique(array_merge($all_item_ids, $a_item_ids));
371 $query =
"SELECT MAX(grouping_id) grp FROM ut_lp_collections" .
372 " WHERE obj_id = " . $this->db->quote($this->obj_id,
"integer") .
374 $res = $this->db->query($query);
379 $query =
"UPDATE ut_lp_collections SET" .
380 " grouping_id = " . $this->db->quote($grp_id,
"integer") .
381 ", num_obligatory = " . $this->db->quote(
385 ", active = " . $this->db->quote(1,
"integer") .
386 " WHERE obj_id = " . $this->db->quote($this->obj_id,
"integer") .
387 " AND " . $this->db->in(
"item_id", $all_item_ids,
false,
"integer");
388 $this->db->manipulate($query);
395 $query =
"UPDATE ut_lp_collections" .
396 " SET grouping_id = " . $this->db->quote(0,
"integer") .
397 ", num_obligatory = " . $this->db->quote(0,
"integer") .
398 " WHERE obj_id = " . $this->db->quote($this->obj_id,
"integer") .
399 " AND " . $this->db->in(
405 $this->db->manipulate($query);
410 foreach ($a_obl as $grouping_id => $num) {
411 $query =
"SELECT count(obj_id) num FROM ut_lp_collections" .
412 " WHERE obj_id = " . $this->db->quote(
416 " AND grouping_id = " . $this->db->quote(
421 $res = $this->db->query($query);
423 if ($num <= 0 || $num >= $row->num) {
428 foreach ($a_obl as $grouping_id => $num) {
429 $query =
"UPDATE ut_lp_collections" .
430 " SET num_obligatory = " . $this->db->quote($num,
"integer") .
431 " WHERE obj_id = " . $this->db->quote(
435 " AND grouping_id = " . $this->db->quote(
439 $this->db->manipulate($query);
449 foreach (
$items as $item_id => $item) {
450 if (in_array($item_id, $done)) {
457 $table_item[
'grouped'] = array();
459 if (count((array) ($grouped_items[
'items'] ?? [])) > 1) {
460 foreach ($grouped_items[
'items'] as $grouped_item_id) {
461 if ($grouped_item_id == $item_id ||
462 !is_array(
$items[$grouped_item_id] ??
false)) {
470 $table_item[
'num_obligatory'] = $grouped_items[
'num_obligatory'];
471 $table_item[
'grouping_id'] = $grouped_items[
'grouping_id'];
473 $done[] = $grouped_item_id;
476 $data[] = $table_item;
483 $table_item = $a_item;
484 $table_item[
'id'] = $a_id;
488 $table_item[
'mode_id'] = $olp->getCurrentMode();
489 $table_item[
'mode'] = $olp->getModeText($table_item[
'mode_id']);
490 $table_item[
'anonymized'] = $olp->isAnonymized();
498 $query =
"SELECT grouping_id FROM ut_lp_collections" .
499 " WHERE obj_id = " . $this->db->quote($this->obj_id,
"integer") .
500 " AND item_id = " . $this->db->quote($item_id,
"integer");
501 $res = $this->db->query($query);
504 $grouping_id = (
int) $row->grouping_id;
506 if ($grouping_id > 0) {
507 $query =
"SELECT item_id, num_obligatory FROM ut_lp_collections" .
508 " WHERE obj_id = " . $this->db->quote(
512 " AND grouping_id = " . $this->db->quote(
516 $res = $this->db->query($query);
519 $items[
'num_obligatory'] = (
int) $row->num_obligatory;
520 $items[
'grouping_id'] = (
int) $grouping_id;
529 $query =
" SELECT * FROM ut_lp_collections" .
530 " WHERE obj_id = " . $this->db->quote($this->obj_id,
"integer") .
531 " AND active = " . $this->db->quote(1,
"integer");
532 $res = $this->db->query($query);
536 if (in_array($row->item_id,
$items)) {
537 $grouped[$row->grouping_id][
'items'][] = (
int) $row->item_id;
538 $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.
__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)
__construct(Container $dic, ilPlugin $plugin)
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)