ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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';
35{
38
39 protected $db = null;
40 protected $target_id = null;
41 protected $target_ref_id = null;
43
50 public function __construct($a_id = 0,$a_call_by_reference = true)
51 {
52 global $ilDB;
53
54 parent::__construct($a_id,$a_call_by_reference);
55 }
56
65 public static function _lookupTargetId($a_obj_id)
66 {
67 global $ilDB;
68
69 $query = "SELECT * FROM container_reference ".
70 "WHERE obj_id = ".$ilDB->quote($a_obj_id,'integer')." ";
71 $res = $ilDB->query($query);
72 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
73 {
74 return $row->target_obj_id;
75 }
76 return $a_obj_id;
77 }
78
85 public static function _lookupTargetRefId($a_obj_id)
86 {
87 global $ilDB;
88
89 $query = "SELECT ref_id FROM object_reference obr ".
90 "JOIN container_reference cr ON obr.obj_id = cr.target_obj_id ".
91 "WHERE cr.obj_id = ".$ilDB->quote($a_obj_id,'integer');
92 $res = $ilDB->query($query);
93 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
94 {
95 return $row->ref_id;
96 }
97 return false;
98 }
99
105 public static function _lookupTitle($a_obj_id)
106 {
107 global $ilDB;
108
109 $query = 'SELECT title,title_type FROM container_reference cr '.
110 'JOIN object_data od ON cr.obj_id = od.obj_id '.
111 'WHERE cr.obj_id = '.$ilDB->quote($a_obj_id,'integer');
112 $res = $ilDB->query($query);
113 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
114 {
116 {
117 return $row->title;
118 }
119 }
121 }
122
129 public static function _lookupTargetTitle($a_obj_id)
130 {
131 global $ilDB;
132
133 $query = "SELECT title FROM object_data od ".
134 "JOIN container_reference cr ON target_obj_id = od.obj_id ".
135 "WHERE cr.obj_id = ".$ilDB->quote($a_obj_id ,'integer');
136 $res = $ilDB->query($query);
137 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
138 {
139 return $row->title;
140 }
141 return '';
142 }
143
151 public static function _lookupSourceId($a_target_id)
152 {
153 global $ilDB;
154
155 $query = "SELECT * FROM container_reference ".
156 "WHERE target_obj_id = ".$ilDB->quote($a_target_id,'integer')." ";
157 $res = $ilDB->query($query);
158 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
159 {
160 return $row->obj_id;
161 }
162 return false;
163 }
164
173 public static function _lookupSourceIds($a_target_id)
174 {
175 global $ilDB;
176
177 $query = "SELECT * FROM container_reference ".
178 "WHERE target_obj_id = ".$ilDB->quote($a_target_id,'integer')." ";
179 $res = $ilDB->query($query);
180 $ret = array();
181 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
182 {
183 $ret[] = $row->obj_id;
184 }
185 return $ret;
186 }
187
194 public function getTargetId()
195 {
196 return $this->target_id;
197 }
198
199
207 public function setTargetId($a_target_id)
208 {
209 $this->target_id = $a_target_id;
210 }
211
219 public function setTargetRefId($a_id)
220 {
221 $this->target_ref_id = $a_id;
222 }
223
231 public function getTargetRefId()
232 {
234 }
235
240 public function getTitleType()
241 {
242 return $this->title_type;
243 }
244
249 public function setTitleType($type)
250 {
251 $this->title_type = $type;
252 }
253
260 public function read()
261 {
262 global $ilDB;
263
264 parent::read();
265
266 $query = "SELECT * FROM container_reference ".
267 "WHERE obj_id = ".$ilDB->quote($this->getId(),'integer')." ";
268 $res = $ilDB->query($query);
269
270 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
271 {
272 $this->setTargetId($row->target_obj_id);
273 $this->setTitleType($row->title_type);
274 }
275 $ref_ids = ilObject::_getAllReferences($this->getTargetId());
276 $this->setTargetRefId(current($ref_ids));
277
279 {
280 #$this->title = $this->lng->txt('reference_of').' '.ilObject::_lookupTitle($this->getTargetId());
281 $this->title = ilObject::_lookupTitle($this->getTargetId());
282 }
283 }
284
289 public function getPresentationTitle()
290 {
291 if($this->getTitleType() == self::TITLE_TYPE_CUSTOM)
292 {
293 return $this->getTitle();
294 }
295 else
296 {
297 return $this->lng->txt('reference_of').' '.$this->getTitle();
298 }
299 }
300
308 public function update()
309 {
310 global $ilDB;
311
312 parent::update();
313
314 $query = "DELETE FROM container_reference ".
315 "WHERE obj_id = ".$ilDB->quote($this->getId(),'integer')." ";
316 $ilDB->manipulate($query);
317
318 $query = "INSERT INTO container_reference (obj_id, target_obj_id, title_type) ".
319 "VALUES( ".
320 $ilDB->quote($this->getId(),'integer').", ".
321 $ilDB->quote($this->getTargetId(),'integer').", ".
322 $ilDB->quote($this->getTitleType(),'integer').' '.
323 ")";
324 $ilDB->manipulate($query);
325 }
326
334 public function delete()
335 {
336 global $ilDB;
337
338 if(!parent::delete())
339 {
340 return false;
341 }
342
343 $query = "DELETE FROM container_reference ".
344 "WHERE obj_id = ".$ilDB->quote($this->getId(),'integer')." ";
345 $ilDB->manipulate($query);
346
347 return true;
348 }
349
358 public function cloneObject($a_target_id,$a_copy_id = 0)
359 {
360 global $ilDB,$ilUser;
361
362 $new_obj = parent::cloneObject($a_target_id,$a_copy_id);
363
364 $query = "INSERT INTO container_reference (obj_id, target_obj_id, title_type) ".
365 "VALUES( ".
366 $ilDB->quote($new_obj->getId(),'integer').", ".
367 $ilDB->quote($this->getTargetId(),'integer').", ".
368 $ilDB->quote($this->getTitleType(),'integer').' '.
369 ")";
370 $ilDB->manipulate($query);
371 return $new_obj;
372 }
373
374}
375
376?>
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.
static _lookupSourceIds($a_target_id)
Get ids of all container references that target the object with the given id.
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