ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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  function __construct($a_id = 0,$a_call_by_reference = true)
28  {
29  $this->type = "cat";
30  parent::__construct($a_id,$a_call_by_reference);
31  }
32 
39  function delete()
40  {
41  global $ilDB,$ilAppEventHandler;
42 
43  // always call parent delete function first!!
44  if (!parent::delete())
45  {
46  return false;
47  }
48 
49  // put here category specific stuff
50  include_once('./Services/User/classes/class.ilObjUserFolder.php');
52 
53  $query = "DELETE FROM object_translation WHERE obj_id = ".$ilDB->quote($this->getId(),'integer');
54  $res = $ilDB->manipulate($query);
55 
56  // taxonomies
57  include_once "Services/Taxonomy/classes/class.ilObjTaxonomy.php";
58  foreach(ilObjTaxonomy::getUsageOfObject($this->getId()) as $tax_id)
59  {
60  if($tax_id)
61  {
62  $tax = new ilObjTaxonomy($tax_id);
63  $tax->delete();
64  }
65  }
66 
67  $ilAppEventHandler->raise('Modules/Category',
68  'delete',
69  array('object' => $this,
70  'obj_id' => $this->getId()));
71 
72  return true;
73  }
74 
81  function getTranslations()
82  {
83  global $ilDB;
84 
85  $q = "SELECT * FROM object_translation WHERE obj_id = ".
86  $ilDB->quote($this->getId(),'integer')." ORDER BY lang_default DESC";
87  $r = $this->ilias->db->query($q);
88 
89  $num = 0;
90 
91  while ($row = $r->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
92  {
93  $data["Fobject"][$num]= array("title" => $row->title,
94  "desc" => $row->description,
95  "lang" => $row->lang_code
96  );
97  $num++;
98  }
99 
100  // first entry is always the default language
101  $data["default_language"] = 0;
102 
103  return $data ? $data : array();
104  }
105 
106  // remove all Translations of current category
108  {
109  global $ilDB;
110 
111  $query = "DELETE FROM object_translation WHERE obj_id= ".
112  $ilDB->quote($this->getId(),'integer');
113  $res = $ilDB->manipulate($query);
114  }
115 
116  // remove translations of current category
117  function deleteTranslation($a_lang)
118  {
119  global $ilDB;
120 
121  $query = "DELETE FROM object_translation WHERE obj_id= ".
122  $ilDB->quote($this->getId(),'integer')." AND lang_code = ".
123  $ilDB->quote($a_lang, 'text');
124  $res = $ilDB->manipulate($query);
125  }
126 
127  // add a new translation to current category
128  function addTranslation($a_title,$a_desc,$a_lang,$a_lang_default)
129  {
130  global $ilDB;
131 
132  if (empty($a_title))
133  {
134  $a_title = "NO TITLE";
135  }
136 
137  $query = "INSERT INTO object_translation ".
138  "(obj_id,title,description,lang_code,lang_default) ".
139  "VALUES ".
140  "(".$ilDB->quote($this->getId(),'integer').",".
141  $ilDB->quote($a_title,'text').",".$ilDB->quote($a_desc,'text').",".
142  $ilDB->quote($a_lang,'text').",".$ilDB->quote($a_lang_default,'integer').")";
143  $res = $ilDB->manipulate($query);
144 
145  return true;
146  }
147 
148  // update a translation to current category
149  function updateTranslation($a_title,$a_desc,$a_lang,$a_lang_default)
150  {
151  global $ilDB, $ilLog;
152 
153  if (empty($a_title))
154  {
155  $a_title = "NO TITLE";
156  }
157 
158  $query = "UPDATE object_translation ".
159  "SET title = ". $ilDB->quote($a_title,'text').",".
160  "description = ".$ilDB->quote($a_desc,'text').",".
161  "lang_code = ".$ilDB->quote($a_lang,'text') . ",".
162  "lang_default = ".$ilDB->quote($a_lang_default,'integer')." ".
163  "WHERE ".
164  " obj_id = ".$ilDB->quote($this->getId(),'integer');
165  $res = $ilDB->manipulate($query);
166 
167  return true;
168  }
169 
178  public function cloneObject($a_target_id,$a_copy_id = 0, $a_omit_tree = false)
179  {
180  global $ilDB,$ilUser;
181 
182  $new_obj = parent::cloneObject($a_target_id,$a_copy_id,$a_omit_tree);
183 
184  /* done in class.ilContainer
185  include_once('./Services/Container/classes/class.ilContainerSortingSettings.php');
186  ilContainerSortingSettings::_cloneSettings($this->getId(),$new_obj->getId());
187  */
188 
189  include_once("./Services/Object/classes/class.ilObjectTranslation.php");
190  $ot = ilObjectTranslation::getInstance($this->getId());
191  $ot->copy($new_obj->getId());
192 
193  /*
194  $first = true;
195  $translations = $this->getTranslations();
196  if(is_array($translations['Fobject']))
197  {
198  foreach($translations['Fobject'] as $num => $translation)
199  {
200  $new_obj->addTranslation($translation['title'],$translation['desc'],$translation['lang'],$first);
201 
202  if($first)
203  {
204  $first = false;
205  }
206  }
207  }*/
208 
209  // clone icons
210  $new_obj->saveIcons($this->getBigIconPath(),
211  $this->getSmallIconPath(),
212  $this->getTinyIconPath());
213 
214  return $new_obj;
215  }
216 
217  public function cloneDependencies($a_target_id,$a_copy_id)
218  {
219  parent::cloneDependencies($a_target_id,$a_copy_id);
220 
221 
222  // clone taxonomies
223 
224  include_once("./Services/Taxonomy/classes/class.ilObjTaxonomy.php");
225  $all_tax = ilObjTaxonomy::getUsageOfObject($this->getId());
226  if(sizeof($all_tax))
227  {
228  include_once("./Services/Taxonomy/classes/class.ilTaxNodeAssignment.php");
229 
230  $cwo = ilCopyWizardOptions::_getInstance($a_copy_id);
231  $mappings = $cwo->getMappings();
232 
233  foreach($all_tax as $old_tax_id)
234  {
235  if($old_tax_id)
236  {
237  // clone it
238  $old_tax = new ilObjTaxonomy($old_tax_id);
239  $new_tax = $old_tax->cloneObject(0,0,true);
240  $tax_map = $old_tax->getNodeMapping();
241 
242  // assign new taxonomy to new category
243  ilObjTaxonomy::saveUsage($new_tax->getId(), ilObject::_lookupObjId($a_target_id));
244 
245  // clone assignments (for all sub-items)
246  foreach($mappings as $old_ref_id => $new_ref_id)
247  {
248  if($old_ref_id != $new_ref_id)
249  {
250  $old_obj_id = ilObject::_lookupObjId($old_ref_id);
251  $new_obj_id = ilObject::_lookupObjId($new_ref_id);
252  $obj_type = ilObject::_lookupType($old_obj_id);
253 
254  $tax_ass = new ilTaxNodeAssignment($obj_type, $old_obj_id, "obj", $old_tax_id);
255  $assignmts = $tax_ass->getAssignmentsOfItem($old_obj_id);
256  if(sizeof($assignmts))
257  {
258  $new_tax_ass = new ilTaxNodeAssignment($obj_type, $new_obj_id, "obj", $new_tax->getId());
259  foreach($assignmts as $a)
260  {
261  if($tax_map[$a["node_id"]])
262  {
263  $new_tax_ass->addAssignment($tax_map[$a["node_id"]], $new_obj_id);
264  }
265  }
266  }
267  }
268  }
269  }
270  }
271  }
272  }
273 
278  function addAdditionalSubItemInformation(&$a_item_data)
279  {
280  include_once './Services/Object/classes/class.ilObjectActivation.php';
282  }
283 
284 } // END class.ilObjCategory
285 ?>
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.
cloneObject($a_target_id, $a_copy_id=0, $a_omit_tree=false)
Clone course (no member data)
getBigIconPath()
Get path for big icon.
getTinyIconPath()
Get path for tiny icon.
getTranslations()
get all translations from this category
addTranslation($a_title, $a_desc, $a_lang, $a_lang_default)
static addAdditionalSubItemInformation(array &$a_item)
Parse item data for list entries.
$r
Definition: example_031.php:79
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)
$ilUser
Definition: imgupload.php:18
redirection script todo: (a better solution should control the processing via a xml file) ...
Class ilContainer.
Create styles array
The data for the language used.
static _lookupType($a_id, $a_reference=false)
lookup object type
Class ilObjCategory.
updateTranslation($a_title, $a_desc, $a_lang, $a_lang_default)
__construct($a_id=0, $a_call_by_reference=true)
Constructor public.
getSmallIconPath()
Get path for small icon.
static saveUsage($a_tax_id, $a_obj_id)
Save Usage.
static getInstance($a_obj_id)
Get instance.
global $ilDB
const USER_FOLDER_ID
Class ilObjUserFolder.