ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjCategory.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 
25 require_once "./Services/Container/classes/class.ilContainer.php";
26 
27 
40 {
47  function ilObjCategory($a_id = 0,$a_call_by_reference = true)
48  {
49  global $ilBench;
50 
51  $ilBench->start("Core", "ilObjCategory_Constructor");
52 
53  $this->type = "cat";
54  $this->ilContainer($a_id,$a_call_by_reference);
55 
56  $ilBench->stop("Core", "ilObjCategory_Constructor");
57  }
58 
59 
66  function delete()
67  {
68  global $ilDB,$ilAppEventHandler;
69 
70  // always call parent delete function first!!
71  if (!parent::delete())
72  {
73  return false;
74  }
75 
76  // put here category specific stuff
77  include_once('./Services/User/classes/class.ilObjUserFolder.php');
79 
80  $query = "DELETE FROM object_translation WHERE obj_id = ".$ilDB->quote($this->getId(),'integer');
81  $res = $ilDB->manipulate($query);
82 
83  $ilAppEventHandler->raise('Modules/Category',
84  'delete',
85  array('object' => $this,
86  'obj_id' => $this->getId()));
87 
88  return true;
89  }
90 
97  function getTranslations()
98  {
99  global $ilDB;
100 
101  $q = "SELECT * FROM object_translation WHERE obj_id = ".
102  $ilDB->quote($this->getId(),'integer')." ORDER BY lang_default DESC";
103  $r = $this->ilias->db->query($q);
104 
105  $num = 0;
106 
107  while ($row = $r->fetchRow(DB_FETCHMODE_OBJECT))
108  {
109  $data["Fobject"][$num]= array("title" => $row->title,
110  "desc" => $row->description,
111  "lang" => $row->lang_code
112  );
113  $num++;
114  }
115 
116  // first entry is always the default language
117  $data["default_language"] = 0;
118 
119  return $data ? $data : array();
120  }
121 
122  // remove all Translations of current category
124  {
125  global $ilDB;
126 
127  $query = "DELETE FROM object_translation WHERE obj_id= ".
128  $ilDB->quote($this->getId(),'integer');
129  $res = $ilDB->manipulate($query);
130  }
131 
132  // add a new translation to current category
133  function addTranslation($a_title,$a_desc,$a_lang,$a_lang_default)
134  {
135  global $ilDB;
136 
137  if (empty($a_title))
138  {
139  $a_title = "NO TITLE";
140  }
141 
142  $query = "INSERT INTO object_translation ".
143  "(obj_id,title,description,lang_code,lang_default) ".
144  "VALUES ".
145  "(".$ilDB->quote($this->getId(),'integer').",".
146  $ilDB->quote($a_title,'text').",".$ilDB->quote($a_desc,'text').",".
147  $ilDB->quote($a_lang,'text').",".$ilDB->quote($a_lang_default,'integer').")";
148  $res = $ilDB->manipulate($query);
149 
150  return true;
151  }
152 
153  // update a translation to current category
154  function updateTranslation($a_title,$a_desc,$a_lang,$a_lang_default)
155  {
156  global $ilDB, $ilLog;
157 
158  if (empty($a_title))
159  {
160  $a_title = "NO TITLE";
161  }
162 
163  $query = "UPDATE object_translation ".
164  "SET title = ". $ilDB->quote($a_title,'text').",".
165  "description = ".$ilDB->quote($a_desc,'text').",".
166  "lang_code = ".$ilDB->quote($a_lang,'text') . ",".
167  "lang_default = ".$ilDB->quote($a_lang_default,'integer')." ".
168  "WHERE ".
169  " obj_id = ".$ilDB->quote($this->getId(),'integer');
170  $res = $ilDB->manipulate($query);
171 
172  return true;
173  }
174 
183  public function cloneObject($a_target_id,$a_copy_id = 0)
184  {
185  global $ilDB,$ilUser;
186 
187  $new_obj = parent::cloneObject($a_target_id,$a_copy_id);
188 
189  /* done in class.ilContainer
190  include_once('./Services/Container/classes/class.ilContainerSortingSettings.php');
191  ilContainerSortingSettings::_cloneSettings($this->getId(),$new_obj->getId());
192  */
193  $first = true;
194  $translations = $this->getTranslations();
195  if(is_array($translations['Fobject']))
196  {
197  foreach($translations['Fobject'] as $num => $translation)
198  {
199  $new_obj->addTranslation($translation['title'],$translation['desc'],$translation['lang'],$first);
200 
201  if($first)
202  {
203  $first = false;
204  }
205  }
206  }
207 
208  // clone icons
209  $new_obj->saveIcons($this->getBigIconPath(),
210  $this->getSmallIconPath(),
211  $this->getTinyIconPath());
212 
213 
214  return $new_obj;
215  }
216 } // END class.ilObjCategory
217 ?>