ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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
5require_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 {
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 $query = "DELETE FROM object_translation WHERE obj_id = " . $ilDB->quote($this->getId(), 'integer');
60 $res = $ilDB->manipulate($query);
61
62 // taxonomies
63 include_once "Services/Taxonomy/classes/class.ilObjTaxonomy.php";
64 foreach (ilObjTaxonomy::getUsageOfObject($this->getId()) as $tax_id) {
65 if ($tax_id) {
66 $tax = new ilObjTaxonomy($tax_id);
67 $tax->delete();
68 }
69 }
70
71 $ilAppEventHandler->raise(
72 'Modules/Category',
73 'delete',
74 array('object' => $this,
75 'obj_id' => $this->getId())
76 );
77
78 return true;
79 }
80
87 public function getTranslations()
88 {
90
91 $q = "SELECT * FROM object_translation WHERE obj_id = " .
92 $ilDB->quote($this->getId(), 'integer') . " ORDER BY lang_default DESC";
93 $r = $ilDB->query($q);
94
95 $num = 0;
96
97 while ($row = $r->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
98 $data["Fobject"][$num]= array("title" => $row->title,
99 "desc" => $row->description,
100 "lang" => $row->lang_code
101 );
102 $num++;
103 }
104
105 // first entry is always the default language
106 $data["default_language"] = 0;
107
108 return $data ? $data : array();
109 }
110
111 // remove all Translations of current category
112 public function removeTranslations()
113 {
115
116 $query = "DELETE FROM object_translation WHERE obj_id= " .
117 $ilDB->quote($this->getId(), 'integer');
118 $res = $ilDB->manipulate($query);
119 }
120
121 // remove translations of current category
122 public function deleteTranslation($a_lang)
123 {
125
126 $query = "DELETE FROM object_translation WHERE obj_id= " .
127 $ilDB->quote($this->getId(), 'integer') . " AND lang_code = " .
128 $ilDB->quote($a_lang, 'text');
129 $res = $ilDB->manipulate($query);
130 }
131
132 // add a new translation to current category
133 public function addTranslation($a_title, $a_desc, $a_lang, $a_lang_default)
134 {
136
137 if (empty($a_title)) {
138 $a_title = "NO TITLE";
139 }
140
141 $query = "INSERT INTO object_translation " .
142 "(obj_id,title,description,lang_code,lang_default) " .
143 "VALUES " .
144 "(" . $ilDB->quote($this->getId(), 'integer') . "," .
145 $ilDB->quote($a_title, 'text') . "," . $ilDB->quote($a_desc, 'text') . "," .
146 $ilDB->quote($a_lang, 'text') . "," . $ilDB->quote($a_lang_default, 'integer') . ")";
147 $res = $ilDB->manipulate($query);
148
149 return true;
150 }
151
152 // update a translation to current category
153 public function updateTranslation($a_title, $a_desc, $a_lang, $a_lang_default)
154 {
157
158 if (empty($a_title)) {
159 $a_title = "NO TITLE";
160 }
161
162 $query = "UPDATE object_translation " .
163 "SET title = " . $ilDB->quote($a_title, 'text') . "," .
164 "description = " . $ilDB->quote($a_desc, 'text') . "," .
165 "lang_code = " . $ilDB->quote($a_lang, 'text') . "," .
166 "lang_default = " . $ilDB->quote($a_lang_default, 'integer') . " " .
167 "WHERE " .
168 " obj_id = " . $ilDB->quote($this->getId(), 'integer');
169 $res = $ilDB->manipulate($query);
170
171 return true;
172 }
173
182 public function cloneObject($a_target_id, $a_copy_id = 0, $a_omit_tree = false)
183 {
184 $new_obj = parent::cloneObject($a_target_id, $a_copy_id, $a_omit_tree);
185
186 include_once("./Services/Object/classes/class.ilObjectTranslation.php");
188 $ot->copy($new_obj->getId());
189
190 return $new_obj;
191 }
192
193 public function cloneDependencies($a_target_id, $a_copy_id)
194 {
195 parent::cloneDependencies($a_target_id, $a_copy_id);
196
197
198 // clone taxonomies
199
200 include_once("./Services/Taxonomy/classes/class.ilObjTaxonomy.php");
201 $all_tax = ilObjTaxonomy::getUsageOfObject($this->getId());
202 if (sizeof($all_tax)) {
203 include_once("./Services/Taxonomy/classes/class.ilTaxNodeAssignment.php");
204
205 $cwo = ilCopyWizardOptions::_getInstance($a_copy_id);
206 $mappings = $cwo->getMappings();
207
208 foreach ($all_tax as $old_tax_id) {
209 if ($old_tax_id) {
210 // clone it
211 $old_tax = new ilObjTaxonomy($old_tax_id);
212 $new_tax = $old_tax->cloneObject(0, 0, true);
213 $tax_map = $old_tax->getNodeMapping();
214
215 // assign new taxonomy to new category
216 ilObjTaxonomy::saveUsage($new_tax->getId(), ilObject::_lookupObjId($a_target_id));
217
218 // clone assignments (for all sub-items)
219 foreach ($mappings as $old_ref_id => $new_ref_id) {
220 if ($old_ref_id != $new_ref_id) {
221 $old_obj_id = ilObject::_lookupObjId($old_ref_id);
222 $new_obj_id = ilObject::_lookupObjId($new_ref_id);
223 $obj_type = ilObject::_lookupType($old_obj_id);
224
225 $tax_ass = new ilTaxNodeAssignment($obj_type, $old_obj_id, "obj", $old_tax_id);
226 $assignmts = $tax_ass->getAssignmentsOfItem($old_obj_id);
227 if (sizeof($assignmts)) {
228 $new_tax_ass = new ilTaxNodeAssignment($obj_type, $new_obj_id, "obj", $new_tax->getId());
229 foreach ($assignmts as $a) {
230 if ($tax_map[$a["node_id"]]) {
231 $new_tax_ass->addAssignment($tax_map[$a["node_id"]], $new_obj_id);
232 }
233 }
234 }
235 }
236 }
237 }
238 }
239 }
240 }
241
246 public function addAdditionalSubItemInformation(&$a_item_data)
247 {
248 include_once './Services/Object/classes/class.ilObjectActivation.php';
250 }
251} // END class.ilObjCategory
user()
Definition: user.php:4
An exception for terminatinating execution or to throw for unit testing.
const USER_FOLDER_ID
Class ilObjUserFolder.
Class ilContainer.
static _getInstance($a_copy_id)
Get instance of copy wizard options.
Class ilObjCategory.
getTranslations()
get all translations from this category
addTranslation($a_title, $a_desc, $a_lang, $a_lang_default)
cloneObject($a_target_id, $a_copy_id=0, $a_omit_tree=false)
Clone course (no member data)
cloneDependencies($a_target_id, $a_copy_id)
Clone object dependencies (container sorting)
__construct($a_id=0, $a_call_by_reference=true)
Constructor @access public.
addAdditionalSubItemInformation(&$a_item_data)
Add additional information to sub item, e.g.
updateTranslation($a_title, $a_desc, $a_lang, $a_lang_default)
static getUsageOfObject($a_obj_id, $a_include_titles=false)
Get usage of object.
static saveUsage($a_tax_id, $a_obj_id)
Save Usage.
static _updateUserFolderAssignment($a_old_id, $a_new_id)
Update user folder assignment Typically called after deleting a category with local user accounts.
static addAdditionalSubItemInformation(array &$a_item)
Parse item data for list entries.
static getInstance($a_obj_id)
Get instance.
static _lookupObjId($a_id)
getId()
get object id @access public
static _lookupType($a_id, $a_reference=false)
lookup object type
Taxonomy node <-> item assignment.
$r
Definition: example_031.php:79
$query
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
global $ilDB