ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilContainerReference.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 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 
34 {
35  const TITLE_TYPE_REUSE = 1;
36  const TITLE_TYPE_CUSTOM = 2;
37 
38  protected $db = null;
39  protected $target_id = null;
40  protected $target_ref_id = null;
42 
49  public function __construct($a_id = 0,$a_call_by_reference = true)
50  {
51  global $ilDB;
52 
53  parent::__construct($a_id,$a_call_by_reference);
54  }
55 
64  public static function _lookupTargetId($a_obj_id)
65  {
66  global $ilDB;
67 
68  $query = "SELECT * FROM container_reference ".
69  "WHERE obj_id = ".$ilDB->quote($a_obj_id,'integer')." ";
70  $res = $ilDB->query($query);
71  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
72  {
73  return $row->target_obj_id;
74  }
75  return $a_obj_id;
76  }
77 
84  public static function _lookupTargetRefId($a_obj_id)
85  {
86  global $ilDB;
87 
88  $query = "SELECT ref_id FROM object_reference obr ".
89  "JOIN container_reference cr ON obr.obj_id = cr.target_obj_id ".
90  "WHERE cr.obj_id = ".$ilDB->quote($a_obj_id,'integer');
91  $res = $ilDB->query($query);
92  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
93  {
94  return $row->ref_id;
95  }
96  return false;
97  }
98 
104  public static function _lookupTitle($a_obj_id)
105  {
106  global $ilDB;
107 
108  $query = 'SELECT title,title_type FROM container_reference cr '.
109  'JOIN object_data od ON cr.obj_id = od.obj_id '.
110  'WHERE cr.obj_id = '.$ilDB->quote($a_obj_id,'integer');
111  $res = $ilDB->query($query);
112  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
113  {
115  {
116  return $row->title;
117  }
118  }
120  }
121 
128  public static function _lookupTargetTitle($a_obj_id)
129  {
130  global $ilDB;
131 
132  $query = "SELECT title FROM object_data od ".
133  "JOIN container_reference cr ON target_obj_id = od.obj_id ".
134  "WHERE cr.obj_id = ".$ilDB->quote($a_obj_id ,'integer');
135  $res = $ilDB->query($query);
136  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
137  {
138  return $row->title;
139  }
140  return '';
141  }
142 
150  public static function _lookupSourceId($a_target_id)
151  {
152  global $ilDB;
153 
154  $query = "SELECT * FROM container_reference ".
155  "WHERE target_obj_id = ".$ilDB->quote($a_target_id,'integer')." ";
156  $res = $ilDB->query($query);
157  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
158  {
159  return $row->obj_id;
160  }
161  return false;
162  }
163 
170  public function getTargetId()
171  {
172  return $this->target_id;
173  }
174 
175 
183  public function setTargetId($a_target_id)
184  {
185  $this->target_id = $a_target_id;
186  }
187 
195  public function setTargetRefId($a_id)
196  {
197  $this->target_ref_id = $a_id;
198  }
199 
207  public function getTargetRefId()
208  {
209  return $this->target_ref_id;
210  }
211 
216  public function getTitleType()
217  {
218  return $this->title_type;
219  }
220 
225  public function setTitleType($type)
226  {
227  $this->title_type = $type;
228  }
229 
236  public function read()
237  {
238  global $ilDB;
239 
240  parent::read();
241 
242  $query = "SELECT * FROM container_reference ".
243  "WHERE obj_id = ".$ilDB->quote($this->getId(),'integer')." ";
244  $res = $ilDB->query($query);
245 
246  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
247  {
248  $this->setTargetId($row->target_obj_id);
249  $this->setTitleType($row->title_type);
250  }
251  $ref_ids = ilObject::_getAllReferences($this->getTargetId());
252  $this->setTargetRefId(current($ref_ids));
253 
255  {
256  #$this->title = $this->lng->txt('reference_of').' '.ilObject::_lookupTitle($this->getTargetId());
257  $this->title = ilObject::_lookupTitle($this->getTargetId());
258  }
259  }
260 
265  public function getPresentationTitle()
266  {
267  if($this->getTitleType() == self::TITLE_TYPE_CUSTOM)
268  {
269  return $this->getTitle();
270  }
271  else
272  {
273  return $this->lng->txt('reference_of').' '.$this->getTitle();
274  }
275  }
276 
284  public function update()
285  {
286  global $ilDB;
287 
288  parent::update();
289 
290  $query = "DELETE FROM container_reference ".
291  "WHERE obj_id = ".$ilDB->quote($this->getId(),'integer')." ";
292  $ilDB->manipulate($query);
293 
294  $query = "INSERT INTO container_reference (obj_id, target_obj_id, title_type) ".
295  "VALUES( ".
296  $ilDB->quote($this->getId(),'integer').", ".
297  $ilDB->quote($this->getTargetId(),'integer').", ".
298  $ilDB->quote($this->getTitleType(),'integer').' '.
299  ")";
300  $ilDB->manipulate($query);
301  }
302 
310  public function delete()
311  {
312  global $ilDB;
313 
314  if(!parent::delete())
315  {
316  return false;
317  }
318 
319  $query = "DELETE FROM container_reference ".
320  "WHERE obj_id = ".$ilDB->quote($this->getId(),'integer')." ";
321  $ilDB->manipulate($query);
322 
323  return true;
324  }
325 
334  public function cloneObject($a_target_id,$a_copy_id = 0)
335  {
336  global $ilDB,$ilUser;
337 
338  $new_obj = parent::cloneObject($a_target_id,$a_copy_id);
339 
340  $query = "INSERT INTO container_reference (obj_id, target_obj_id, title_type) ".
341  "VALUES( ".
342  $ilDB->quote($new_obj->getId(),'integer').", ".
343  $ilDB->quote($this->getTargetId(),'integer').", ".
344  $ilDB->quote($this->getTitleType(),'integer').' '.
345  ")";
346  $ilDB->manipulate($query);
347  return $new_obj;
348  }
349 
350 }
351 
352 ?>