ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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
24include_once 'Services/Object/classes/class.ilObject.php';
25
36{
39
40 protected $db = null;
41 protected $target_id = null;
42 protected $target_ref_id = null;
44
51 public function __construct($a_id = 0,$a_call_by_reference = true)
52 {
53 global $ilDB;
54
55 parent::__construct($a_id,$a_call_by_reference);
56 }
57
66 public static function _lookupTargetId($a_obj_id)
67 {
68 global $ilDB;
69
70 $query = "SELECT * FROM container_reference ".
71 "WHERE obj_id = ".$ilDB->quote($a_obj_id,'integer')." ";
72 $res = $ilDB->query($query);
73 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
74 {
75 return $row->target_obj_id;
76 }
77 return $a_obj_id;
78 }
79
86 public static function _lookupTargetRefId($a_obj_id)
87 {
88 global $ilDB;
89
90 $query = "SELECT ref_id FROM object_reference obr ".
91 "JOIN container_reference cr ON obr.obj_id = cr.target_obj_id ".
92 "WHERE cr.obj_id = ".$ilDB->quote($a_obj_id,'integer');
93 $res = $ilDB->query($query);
94 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
95 {
96 return $row->ref_id;
97 }
98 return false;
99 }
100
106 public static function _lookupTitle($a_obj_id)
107 {
108 global $ilDB;
109
110 $query = 'SELECT title,title_type FROM container_reference cr '.
111 'JOIN object_data od ON cr.obj_id = od.obj_id '.
112 'WHERE cr.obj_id = '.$ilDB->quote($a_obj_id,'integer');
113 $res = $ilDB->query($query);
114 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
115 {
117 {
118 return $row->title;
119 }
120 }
122 }
123
130 public static function _lookupTargetTitle($a_obj_id)
131 {
132 global $ilDB;
133
134 $query = "SELECT title FROM object_data od ".
135 "JOIN container_reference cr ON target_obj_id = od.obj_id ".
136 "WHERE cr.obj_id = ".$ilDB->quote($a_obj_id ,'integer');
137 $res = $ilDB->query($query);
138 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
139 {
140 return $row->title;
141 }
142 return '';
143 }
144
152 public static function _lookupSourceId($a_target_id)
153 {
154 global $ilDB;
155
156 $query = "SELECT * FROM container_reference ".
157 "WHERE target_obj_id = ".$ilDB->quote($a_target_id,'integer')." ";
158 $res = $ilDB->query($query);
159 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
160 {
161 return $row->obj_id;
162 }
163 return false;
164 }
165
172 public function getTargetId()
173 {
174 return $this->target_id;
175 }
176
177
185 public function setTargetId($a_target_id)
186 {
187 $this->target_id = $a_target_id;
188 }
189
197 public function setTargetRefId($a_id)
198 {
199 $this->target_ref_id = $a_id;
200 }
201
209 public function getTargetRefId()
210 {
212 }
213
218 public function getTitleType()
219 {
220 return $this->title_type;
221 }
222
227 public function setTitleType($type)
228 {
229 $this->title_type = $type;
230 }
231
238 public function read()
239 {
240 global $ilDB;
241
242 parent::read();
243
244 $query = "SELECT * FROM container_reference ".
245 "WHERE obj_id = ".$ilDB->quote($this->getId(),'integer')." ";
246 $res = $ilDB->query($query);
247
248 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
249 {
250 $this->setTargetId($row->target_obj_id);
251 $this->setTitleType($row->title_type);
252 }
253 $ref_ids = ilObject::_getAllReferences($this->getTargetId());
254 $this->setTargetRefId(current($ref_ids));
255
257 {
258 #$this->title = $this->lng->txt('reference_of').' '.ilObject::_lookupTitle($this->getTargetId());
259 $this->title = ilObject::_lookupTitle($this->getTargetId());
260 }
261 }
262
267 public function getPresentationTitle()
268 {
269 if($this->getTitleType() == self::TITLE_TYPE_CUSTOM)
270 {
271 return $this->getTitle();
272 }
273 else
274 {
275 return $this->lng->txt('reference_of').' '.$this->getTitle();
276 }
277 }
278
286 public function update()
287 {
288 global $ilDB;
289
290 parent::update();
291
292 $query = "DELETE FROM container_reference ".
293 "WHERE obj_id = ".$ilDB->quote($this->getId(),'integer')." ";
294 $ilDB->manipulate($query);
295
296 $query = "INSERT INTO container_reference (obj_id, target_obj_id, title_type) ".
297 "VALUES( ".
298 $ilDB->quote($this->getId(),'integer').", ".
299 $ilDB->quote($this->getTargetId(),'integer').", ".
300 $ilDB->quote($this->getTitleType(),'integer').' '.
301 ")";
302 $ilDB->manipulate($query);
303 }
304
312 public function delete()
313 {
314 global $ilDB;
315
316 if(!parent::delete())
317 {
318 return false;
319 }
320
321 $query = "DELETE FROM container_reference ".
322 "WHERE obj_id = ".$ilDB->quote($this->getId(),'integer')." ";
323 $ilDB->manipulate($query);
324
325 return true;
326 }
327
336 public function cloneObject($a_target_id,$a_copy_id = 0)
337 {
338 global $ilDB,$ilUser;
339
340 $new_obj = parent::cloneObject($a_target_id,$a_copy_id);
341
342 $query = "INSERT INTO container_reference (obj_id, target_obj_id, title_type) ".
343 "VALUES( ".
344 $ilDB->quote($new_obj->getId(),'integer').", ".
345 $ilDB->quote($this->getTargetId(),'integer').", ".
346 $ilDB->quote($this->getTitleType(),'integer').' '.
347 ")";
348 $ilDB->manipulate($query);
349 return $new_obj;
350 }
351
352}
353
354?>
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
static _lookupTargetId($a_obj_id)
lookup target id
static _lookupSourceId($a_target_id)
lookup source id
__construct($a_id=0, $a_call_by_reference=true)
Constructor.
setTitleType($type)
Set title type.
static _lookupTargetTitle($a_obj_id)
Lookup target title.
static _lookupTargetRefId($a_obj_id)
Lookup target ref_id.
setTargetId($a_target_id)
set target id
static _lookupTitle($a_obj_id)
Overwitten from base class.
cloneObject($a_target_id, $a_copy_id=0)
Clone course reference.
setTargetRefId($a_id)
set target ref_id
getPresentationTitle()
Get presentation title.
Class ilObject Basic functions for all objects.
static _lookupTitle($a_id)
lookup object title
static _getAllReferences($a_id)
get all reference ids of object
getId()
get object id @access public
getTitle()
get object title @access public
global $ilDB
global $ilUser
Definition: imgupload.php:15