ILIAS  Release_3_10_x_branch Revision 61812
 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)." ";
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);
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 
101  public static function _lookupTargetTitle($a_obj_id)
102  {
103  global $ilDB;
104 
105  $query = "SELECT title FROM object_data od ".
106  "JOIN container_reference cr ON target_obj_id = od.obj_id ".
107  "WHERE cr.obj_id = ".$ilDB->quote($a_obj_id);
108  $res = $ilDB->query($query);
109  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
110  {
111  return $row->title;
112  }
113  return '';
114  }
115 
123  public static function _lookupSourceId($a_target_id)
124  {
125  global $ilDB;
126 
127  $query = "SELECT * FROM container_reference ".
128  "WHERE target_obj_id = ".$ilDB->quote($a_target_id)." ";
129  $res = $ilDB->query($query);
130  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
131  {
132  return $row->obj_id;
133  }
134  return false;
135  }
136 
143  public function getTargetId()
144  {
145  return $this->target_id;
146  }
147 
148 
156  public function setTargetId($a_target_id)
157  {
158  $this->target_id = $a_target_id;
159  }
160 
168  public function setTargetRefId($a_id)
169  {
170  $this->target_ref_id = $a_id;
171  }
172 
180  public function getTargetRefId()
181  {
182  return $this->target_ref_id;
183  }
184 
191  public function read()
192  {
193  global $ilDB;
194 
195  parent::read();
196 
197  $query = "SELECT * FROM container_reference ".
198  "WHERE obj_id = ".$ilDB->quote($this->getId())." ";
199  $res = $ilDB->query($query);
200  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
201  {
202  $this->setTargetId($row->target_obj_id);
203  }
204  $ref_ids = ilObject::_getAllReferences($this->getTargetId());
205  $this->setTargetRefId(current($ref_ids));
206 
207  $this->title = $this->lng->txt('reference_of').' '.ilObject::_lookupTitle($this->getTargetId());
208 
209  }
210 
218  public function update()
219  {
220  global $ilDB;
221 
222  parent::update();
223 
224  $query = "DELETE FROM container_reference ".
225  "WHERE obj_id = ".$ilDB->quote($this->getId())." ";
226  $ilDB->query($query);
227 
228  $query = "INSERT INTO container_reference ".
229  "SET obj_id = ".$ilDB->quote($this->getId()).", ".
230  "target_obj_id = ".$ilDB->quote($this->getTargetId())." ";
231  $ilDB->query($query);
232  }
233 
241  public function delete()
242  {
243  global $ilDB;
244 
245  if(!parent::delete())
246  {
247  return false;
248  }
249 
250  $query = "DELETE FROM container_reference ".
251  "WHERE obj_id = ".$ilDB->quote($this->getId())." ";
252  $ilDB->query($query);
253 
254  return true;
255  }
256 
265  public function cloneObject($a_target_id,$a_copy_id = 0)
266  {
267  global $ilDB,$ilUser;
268 
269  $new_obj = parent::cloneObject($a_target_id,$a_copy_id);
270 
271  $query = "INSERT INTO container_reference ".
272  "SET obj_id = ".$ilDB->quote($new_obj->getId()).", ".
273  "target_obj_id = ".$ilDB->quote($this->getTargetId())." ";
274  $ilDB->query($query);
275  }
276 
277 }
278 
279 ?>