ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilObjCategory.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 require_once "./Services/Container/classes/class.ilContainer.php";
6 
7 
20 {
27  public function __construct($a_id = 0, $a_call_by_reference = true)
28  {
29  global $DIC;
30 
31  $this->db = $DIC->database();
32  $this->app_event_handler = $DIC["ilAppEventHandler"];
33  $this->log = $DIC["ilLog"];
34  $this->user = $DIC->user();
35  $this->type = "cat";
36  parent::__construct($a_id, $a_call_by_reference);
37  }
38 
45  public function delete()
46  {
47  $ilDB = $this->db;
48  $ilAppEventHandler = $this->app_event_handler;
49 
50  // always call parent delete function first!!
51  if (!parent::delete()) {
52  return false;
53  }
54 
55  // put here category specific stuff
56  include_once('./Services/User/classes/class.ilObjUserFolder.php');
58 
59  // taxonomies
60  include_once "Services/Taxonomy/classes/class.ilObjTaxonomy.php";
61  foreach (ilObjTaxonomy::getUsageOfObject($this->getId()) as $tax_id) {
62  if ($tax_id) {
63  $tax = new ilObjTaxonomy($tax_id);
64  $tax->delete();
65  }
66  }
67 
68  $ilAppEventHandler->raise(
69  'Modules/Category',
70  'delete',
71  array('object' => $this,
72  'obj_id' => $this->getId())
73  );
74 
75  return true;
76  }
77 
86  public function cloneObject($a_target_id, $a_copy_id = 0, $a_omit_tree = false)
87  {
88  $new_obj = parent::cloneObject($a_target_id, $a_copy_id, $a_omit_tree);
89 
90  return $new_obj;
91  }
92 
93  public function cloneDependencies($a_target_id, $a_copy_id)
94  {
95  parent::cloneDependencies($a_target_id, $a_copy_id);
96 
97 
98  // clone taxonomies
99 
100  include_once("./Services/Taxonomy/classes/class.ilObjTaxonomy.php");
101  $all_tax = ilObjTaxonomy::getUsageOfObject($this->getId());
102  if (sizeof($all_tax)) {
103  include_once("./Services/Taxonomy/classes/class.ilTaxNodeAssignment.php");
104 
105  $cwo = ilCopyWizardOptions::_getInstance($a_copy_id);
106  $mappings = $cwo->getMappings();
107 
108  foreach ($all_tax as $old_tax_id) {
109  if ($old_tax_id) {
110  // clone it
111  $old_tax = new ilObjTaxonomy($old_tax_id);
112  $new_tax = $old_tax->cloneObject(0, 0, true);
113  $tax_map = $old_tax->getNodeMapping();
114 
115  // assign new taxonomy to new category
116  ilObjTaxonomy::saveUsage($new_tax->getId(), ilObject::_lookupObjId($a_target_id));
117 
118  // clone assignments (for all sub-items)
119  foreach ($mappings as $old_ref_id => $new_ref_id) {
120  if ($old_ref_id != $new_ref_id) {
121  $old_obj_id = ilObject::_lookupObjId($old_ref_id);
122  $new_obj_id = ilObject::_lookupObjId($new_ref_id);
123  $obj_type = ilObject::_lookupType($old_obj_id);
124 
125  $tax_ass = new ilTaxNodeAssignment($obj_type, $old_obj_id, "obj", $old_tax_id);
126  $assignmts = $tax_ass->getAssignmentsOfItem($old_obj_id);
127  if (sizeof($assignmts)) {
128  $new_tax_ass = new ilTaxNodeAssignment($obj_type, $new_obj_id, "obj", $new_tax->getId());
129  foreach ($assignmts as $a) {
130  if ($tax_map[$a["node_id"]]) {
131  $new_tax_ass->addAssignment($tax_map[$a["node_id"]], $new_obj_id);
132  }
133  }
134  }
135  }
136  }
137  }
138  }
139  }
140  }
141 
146  public function addAdditionalSubItemInformation(&$a_item_data)
147  {
148  include_once './Services/Object/classes/class.ilObjectActivation.php';
150  }
151 } // END class.ilObjCategory
static _updateUserFolderAssignment($a_old_id, $a_new_id)
Update user folder assignment Typically called after deleting a category with local user accounts...
addAssignment($a_node_id, $a_item_id, $a_order_nr=0)
Add assignment.
Taxonomy node <-> item assignment.
static getUsageOfObject($a_obj_id, $a_include_titles=false)
Get usage of object.
global $DIC
Definition: saml.php:7
cloneObject($a_target_id, $a_copy_id=0, $a_omit_tree=false)
Clone course (no member data)
user()
Definition: user.php:4
static addAdditionalSubItemInformation(array &$a_item)
Parse item data for list entries.
static _getInstance($a_copy_id)
Get instance of copy wizard options.
addAdditionalSubItemInformation(&$a_item_data)
Add additional information to sub item, e.g.
getId()
get object id public
cloneDependencies($a_target_id, $a_copy_id)
static _lookupObjId($a_id)
Class ilContainer.
static _lookupType($a_id, $a_reference=false)
lookup object type
Class ilObjCategory.
__construct($a_id=0, $a_call_by_reference=true)
Constructor public.
static saveUsage($a_tax_id, $a_obj_id)
Save Usage.
global $ilDB
const USER_FOLDER_ID
Class ilObjUserFolder.