ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilObjCategory.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
27{
28 protected ilLogger $cat_log;
29
30 public function __construct(int $a_id = 0, bool $a_call_by_reference = true)
31 {
32 global $DIC;
33
34 $this->db = $DIC->database();
35 $this->app_event_handler = $DIC["ilAppEventHandler"];
36 $this->log = $DIC["ilLog"];
37 $this->cat_log = ilLoggerFactory::getLogger("cat");
38 $this->user = $DIC->user();
39 $this->type = "cat";
40 parent::__construct($a_id, $a_call_by_reference);
41 }
42
43 public function delete(): bool
44 {
46 $ilAppEventHandler = $this->app_event_handler;
47
48 // always call parent delete function first!!
49 if (!parent::delete()) {
50 return false;
51 }
52
53 // put here category specific stuff
55
56 // taxonomies
57 foreach (ilObjTaxonomy::getUsageOfObject($this->getId()) as $tax_id) {
58 if ($tax_id) {
59 $tax = new ilObjTaxonomy($tax_id);
60 $tax->delete();
61 }
62 }
63
64 $ilAppEventHandler->raise(
65 'components/ILIAS/Category',
66 'delete',
67 [
68 'object' => $this,
69 'obj_id' => $this->getId()
70 ]
71 );
72
73 return true;
74 }
75
76 public function cloneObject(int $target_id, int $copy_id = 0, bool $omit_tree = false): ?ilObject
77 {
78 $new_obj = parent::cloneObject($target_id, $copy_id, $omit_tree);
79
80 return $new_obj;
81 }
82
83 public function cloneDependencies(int $target_id, int $copy_id): bool
84 {
85 parent::cloneDependencies($target_id, $copy_id);
86
87
88 // clone taxonomies
89
90 $all_tax = ilObjTaxonomy::getUsageOfObject($this->getId());
91 if (count($all_tax)) {
92 $cwo = ilCopyWizardOptions::_getInstance($copy_id);
93 $mappings = $cwo->getMappings();
94
95 foreach ($all_tax as $old_tax_id) {
96 if ($old_tax_id) {
97 // clone it
98 $old_tax = new ilObjTaxonomy($old_tax_id);
99 $new_tax = $old_tax->cloneObject(0, 0, true);
100 $tax_map = $old_tax->getNodeMapping();
101
102 // assign new taxonomy to new category
103 ilObjTaxonomy::saveUsage($new_tax->getId(), ilObject::_lookupObjId($target_id));
104
105 // clone assignments (for all sub-items)
106 foreach ($mappings as $old_ref_id => $new_ref_id) {
107 if (!is_numeric($old_ref_id)) { // e.g. 967_adv_rec
108 continue;
109 }
110 if ($old_ref_id != $new_ref_id) {
111 $old_obj_id = ilObject::_lookupObjId((int) $old_ref_id);
112 $new_obj_id = ilObject::_lookupObjId((int) $new_ref_id);
113 $obj_type = ilObject::_lookupType((int) $old_obj_id);
114
115 $this->cat_log->debug("Clone tax assignmets for old ref ID $old_ref_id of type $obj_type (old tax ID is $old_tax_id).");
116
117 $tax_ass = new ilTaxNodeAssignment($obj_type, $old_obj_id, "obj", $old_tax_id);
118 $assignmts = $tax_ass->getAssignmentsOfItem($old_obj_id);
119 if (count($assignmts)) {
120 $new_tax_ass = new ilTaxNodeAssignment($obj_type, $new_obj_id, "obj", $new_tax->getId());
121 foreach ($assignmts as $a) {
122 if ($tax_map[$a["node_id"]]) {
123 $new_tax_ass->addAssignment($tax_map[$a["node_id"]], $new_obj_id);
124 }
125 }
126 }
127 }
128 }
129 }
130 }
131 }
132 return true;
133 }
134
135 public function addAdditionalSubItemInformation(array &$object): void
136 {
138 }
139}
Class ilContainer.
static _getInstance(int $a_copy_id)
static getLogger(string $a_component_id)
Get component logger.
Component logger with individual log levels by component id.
Class ilObjCategory.
addAdditionalSubItemInformation(array &$object)
Add additional information to sub item, e.g.
cloneObject(int $target_id, int $copy_id=0, bool $omit_tree=false)
cloneDependencies(int $target_id, int $copy_id)
Clone object dependencies (container sorting)
__construct(int $a_id=0, bool $a_call_by_reference=true)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getUsageOfObject(int $a_obj_id, bool $a_include_titles=false)
static saveUsage(int $a_tax_id, int $a_obj_id)
static _updateUserFolderAssignment(int $a_old_id, int $a_new_id)
Update user folder assignment Typically called after deleting a category with local user accounts.
static addAdditionalSubItemInformation(array &$item)
Parse item data for list entries.
Class ilObject Basic functions for all objects.
static _lookupType(int $id, bool $reference=false)
ilAppEventHandler $app_event_handler
static _lookupObjId(int $ref_id)
ilDBInterface $db
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const USER_FOLDER_ID
Definition: constants.php:33
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
global $DIC
Definition: shib_login.php:26