ILIAS  Release_4_1_x_branch Revision 61804
 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  protected $db = null;
36  protected $target_id = null;
37  protected $target_ref_id = null;
38 
45  public function __construct($a_id = 0,$a_call_by_reference = true)
46  {
47  global $ilDB;
48 
49  parent::__construct($a_id,$a_call_by_reference);
50  }
51 
60  public static function _lookupTargetId($a_obj_id)
61  {
62  global $ilDB;
63 
64  $query = "SELECT * FROM container_reference ".
65  "WHERE obj_id = ".$ilDB->quote($a_obj_id,'integer')." ";
66  $res = $ilDB->query($query);
67  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
68  {
69  return $row->target_obj_id;
70  }
71  return $a_obj_id;
72  }
73 
80  public static function _lookupTargetRefId($a_obj_id)
81  {
82  global $ilDB;
83 
84  $query = "SELECT ref_id FROM object_reference obr ".
85  "JOIN container_reference cr ON obr.obj_id = cr.target_obj_id ".
86  "WHERE cr.obj_id = ".$ilDB->quote($a_obj_id,'integer');
87  $res = $ilDB->query($query);
88  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
89  {
90  return $row->ref_id;
91  }
92  return false;
93  }
94 
100  public static function _lookupTitle($a_obj_id)
101  {
103  }
104 
111  public static function _lookupTargetTitle($a_obj_id)
112  {
113  global $ilDB;
114 
115  $query = "SELECT title FROM object_data od ".
116  "JOIN container_reference cr ON target_obj_id = od.obj_id ".
117  "WHERE cr.obj_id = ".$ilDB->quote($a_obj_id ,'integer');
118  $res = $ilDB->query($query);
119  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
120  {
121  return $row->title;
122  }
123  return '';
124  }
125 
133  public static function _lookupSourceId($a_target_id)
134  {
135  global $ilDB;
136 
137  $query = "SELECT * FROM container_reference ".
138  "WHERE target_obj_id = ".$ilDB->quote($a_target_id,'integer')." ";
139  $res = $ilDB->query($query);
140  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
141  {
142  return $row->obj_id;
143  }
144  return false;
145  }
146 
153  public function getTargetId()
154  {
155  return $this->target_id;
156  }
157 
158 
166  public function setTargetId($a_target_id)
167  {
168  $this->target_id = $a_target_id;
169  }
170 
178  public function setTargetRefId($a_id)
179  {
180  $this->target_ref_id = $a_id;
181  }
182 
190  public function getTargetRefId()
191  {
192  return $this->target_ref_id;
193  }
194 
201  public function read()
202  {
203  global $ilDB;
204 
205  parent::read();
206 
207  $query = "SELECT * FROM container_reference ".
208  "WHERE obj_id = ".$ilDB->quote($this->getId(),'integer')." ";
209  $res = $ilDB->query($query);
210  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
211  {
212  $this->setTargetId($row->target_obj_id);
213  }
214  $ref_ids = ilObject::_getAllReferences($this->getTargetId());
215  $this->setTargetRefId(current($ref_ids));
216 
217  $this->title = $this->lng->txt('reference_of').' '.ilObject::_lookupTitle($this->getTargetId());
218 
219  }
220 
228  public function update()
229  {
230  global $ilDB;
231 
232  parent::update();
233 
234  $query = "DELETE FROM container_reference ".
235  "WHERE obj_id = ".$ilDB->quote($this->getId(),'integer')." ";
236  $ilDB->manipulate($query);
237 
238  $query = "INSERT INTO container_reference (obj_id, target_obj_id) ".
239  "VALUES( ".
240  $ilDB->quote($this->getId(),'integer').", ".
241  $ilDB->quote($this->getTargetId(),'integer')." ".
242  ")";
243  $ilDB->manipulate($query);
244  }
245 
253  public function delete()
254  {
255  global $ilDB;
256 
257  if(!parent::delete())
258  {
259  return false;
260  }
261 
262  $query = "DELETE FROM container_reference ".
263  "WHERE obj_id = ".$ilDB->quote($this->getId(),'integer')." ";
264  $ilDB->manipulate($query);
265 
266  return true;
267  }
268 
277  public function cloneObject($a_target_id,$a_copy_id = 0)
278  {
279  global $ilDB,$ilUser;
280 
281  $new_obj = parent::cloneObject($a_target_id,$a_copy_id);
282 
283  $query = "INSERT INTO container_reference (obj_id, target_obj_id) ".
284  "VALUES( ".
285  $ilDB->quote($new_obj->getId(),'integer').", ".
286  $ilDB->quote($this->getTargetId(),'integer')." ".
287  ")";
288  $ilDB->manipulate($query);
289  return $new_obj;
290  }
291 
292 }
293 
294 ?>