ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 ilObjCategory($a_id = 0,$a_call_by_reference = true)
28  {
29  $this->type = "cat";
30  $this->ilContainer($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  $ilAppEventHandler->raise('Modules/Category',
57  'delete',
58  array('object' => $this,
59  'obj_id' => $this->getId()));
60 
61  return true;
62  }
63 
70  function getTranslations()
71  {
72  global $ilDB;
73 
74  $q = "SELECT * FROM object_translation WHERE obj_id = ".
75  $ilDB->quote($this->getId(),'integer')." ORDER BY lang_default DESC";
76  $r = $this->ilias->db->query($q);
77 
78  $num = 0;
79 
80  while ($row = $r->fetchRow(DB_FETCHMODE_OBJECT))
81  {
82  $data["Fobject"][$num]= array("title" => $row->title,
83  "desc" => $row->description,
84  "lang" => $row->lang_code
85  );
86  $num++;
87  }
88 
89  // first entry is always the default language
90  $data["default_language"] = 0;
91 
92  return $data ? $data : array();
93  }
94 
95  // remove all Translations of current category
96  function removeTranslations()
97  {
98  global $ilDB;
99 
100  $query = "DELETE FROM object_translation WHERE obj_id= ".
101  $ilDB->quote($this->getId(),'integer');
102  $res = $ilDB->manipulate($query);
103  }
104 
105  // remove translations of current category
106  function deleteTranslation($a_lang)
107  {
108  global $ilDB;
109 
110  $query = "DELETE FROM object_translation WHERE obj_id= ".
111  $ilDB->quote($this->getId(),'integer')." AND lang_code = ".
112  $ilDB->quote($a_lang, 'text');
113  $res = $ilDB->manipulate($query);
114  }
115 
116  // add a new translation to current category
117  function addTranslation($a_title,$a_desc,$a_lang,$a_lang_default)
118  {
119  global $ilDB;
120 
121  if (empty($a_title))
122  {
123  $a_title = "NO TITLE";
124  }
125 
126  $query = "INSERT INTO object_translation ".
127  "(obj_id,title,description,lang_code,lang_default) ".
128  "VALUES ".
129  "(".$ilDB->quote($this->getId(),'integer').",".
130  $ilDB->quote($a_title,'text').",".$ilDB->quote($a_desc,'text').",".
131  $ilDB->quote($a_lang,'text').",".$ilDB->quote($a_lang_default,'integer').")";
132  $res = $ilDB->manipulate($query);
133 
134  return true;
135  }
136 
137  // update a translation to current category
138  function updateTranslation($a_title,$a_desc,$a_lang,$a_lang_default)
139  {
140  global $ilDB, $ilLog;
141 
142  if (empty($a_title))
143  {
144  $a_title = "NO TITLE";
145  }
146 
147  $query = "UPDATE object_translation ".
148  "SET title = ". $ilDB->quote($a_title,'text').",".
149  "description = ".$ilDB->quote($a_desc,'text').",".
150  "lang_code = ".$ilDB->quote($a_lang,'text') . ",".
151  "lang_default = ".$ilDB->quote($a_lang_default,'integer')." ".
152  "WHERE ".
153  " obj_id = ".$ilDB->quote($this->getId(),'integer');
154  $res = $ilDB->manipulate($query);
155 
156  return true;
157  }
158 
167  public function cloneObject($a_target_id,$a_copy_id = 0)
168  {
169  global $ilDB,$ilUser;
170 
171  $new_obj = parent::cloneObject($a_target_id,$a_copy_id);
172 
173  /* done in class.ilContainer
174  include_once('./Services/Container/classes/class.ilContainerSortingSettings.php');
175  ilContainerSortingSettings::_cloneSettings($this->getId(),$new_obj->getId());
176  */
177  $first = true;
178  $translations = $this->getTranslations();
179  if(is_array($translations['Fobject']))
180  {
181  foreach($translations['Fobject'] as $num => $translation)
182  {
183  $new_obj->addTranslation($translation['title'],$translation['desc'],$translation['lang'],$first);
184 
185  if($first)
186  {
187  $first = false;
188  }
189  }
190  }
191 
192  // clone icons
193  $new_obj->saveIcons($this->getBigIconPath(),
194  $this->getSmallIconPath(),
195  $this->getTinyIconPath());
196 
197 
198  return $new_obj;
199  }
200 
205  function addAdditionalSubItemInformation(&$a_item_data)
206  {
207  include_once './Services/Object/classes/class.ilObjectActivation.php';
209  }
210 
211 } // END class.ilObjCategory
212 ?>