ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
24 include_once './Services/Object/classes/class.ilObject.php';
35 {
39  protected $user;
40 
41  const TITLE_TYPE_REUSE = 1;
42  const TITLE_TYPE_CUSTOM = 2;
43 
44  protected $db = null;
45  protected $target_id = null;
46  protected $target_ref_id = null;
47  protected $title_type = self::TITLE_TYPE_REUSE;
48 
55  public function __construct($a_id = 0, $a_call_by_reference = true)
56  {
57  global $DIC;
58 
59  $this->db = $DIC->database();
60  $this->user = $DIC->user();
61  $ilDB = $DIC->database();
62 
63  parent::__construct($a_id, $a_call_by_reference);
64  }
65 
74  public static function _lookupTargetId($a_obj_id)
75  {
76  global $DIC;
77 
78  $ilDB = $DIC->database();
79 
80  $query = "SELECT * FROM container_reference " .
81  "WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " ";
82  $res = $ilDB->query($query);
83  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
84  return $row->target_obj_id;
85  }
86  return $a_obj_id;
87  }
88 
95  public static function _lookupTargetRefId($a_obj_id)
96  {
97  global $DIC;
98 
99  $ilDB = $DIC->database();
100 
101  $query = "SELECT ref_id FROM object_reference obr " .
102  "JOIN container_reference cr ON obr.obj_id = cr.target_obj_id " .
103  "WHERE cr.obj_id = " . $ilDB->quote($a_obj_id, 'integer');
104  $res = $ilDB->query($query);
105  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
106  return $row->ref_id;
107  }
108  return false;
109  }
110 
116  public static function _lookupTitle($a_obj_id)
117  {
118  global $DIC;
119 
120  $ilDB = $DIC->database();
121 
122  $query = 'SELECT title,title_type FROM container_reference cr ' .
123  'JOIN object_data od ON cr.obj_id = od.obj_id ' .
124  'WHERE cr.obj_id = ' . $ilDB->quote($a_obj_id, 'integer');
125  $res = $ilDB->query($query);
126  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
127  if ($row->title_type == ilContainerReference::TITLE_TYPE_CUSTOM) {
128  return $row->title;
129  }
130  }
132  }
133 
140  public static function _lookupTargetTitle($a_obj_id)
141  {
142  global $DIC;
143 
144  $ilDB = $DIC->database();
145 
146  $query = "SELECT title FROM object_data od " .
147  "JOIN container_reference cr ON target_obj_id = od.obj_id " .
148  "WHERE cr.obj_id = " . $ilDB->quote($a_obj_id, 'integer');
149  $res = $ilDB->query($query);
150  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
151  return $row->title;
152  }
153  return '';
154  }
155 
163  public static function _lookupSourceId($a_target_id)
164  {
165  global $DIC;
166 
167  $ilDB = $DIC->database();
168 
169  $query = "SELECT * FROM container_reference " .
170  "WHERE target_obj_id = " . $ilDB->quote($a_target_id, 'integer') . " ";
171  $res = $ilDB->query($query);
172  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
173  return $row->obj_id;
174  }
175  return false;
176  }
177 
186  public static function _lookupSourceIds($a_target_id)
187  {
188  global $DIC;
189 
190  $ilDB = $DIC->database();
191 
192  $query = "SELECT * FROM container_reference " .
193  "WHERE target_obj_id = " . $ilDB->quote($a_target_id, 'integer') . " ";
194  $res = $ilDB->query($query);
195  $ret = array();
196  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
197  $ret[] = $row->obj_id;
198  }
199  return $ret;
200  }
201 
208  public function getTargetId()
209  {
210  return $this->target_id;
211  }
212 
213 
221  public function setTargetId($a_target_id)
222  {
223  $this->target_id = $a_target_id;
224  }
225 
233  public function setTargetRefId($a_id)
234  {
235  $this->target_ref_id = $a_id;
236  }
237 
245  public function getTargetRefId()
246  {
247  return $this->target_ref_id;
248  }
249 
254  public function getTitleType()
255  {
256  return $this->title_type;
257  }
258 
263  public function setTitleType($type)
264  {
265  $this->title_type = $type;
266  }
267 
274  public function read()
275  {
276  $ilDB = $this->db;
277 
278  parent::read();
279 
280  $query = "SELECT * FROM container_reference " .
281  "WHERE obj_id = " . $ilDB->quote($this->getId(), 'integer') . " ";
282  $res = $ilDB->query($query);
283 
284  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
285  $this->setTargetId($row->target_obj_id);
286  $this->setTitleType($row->title_type);
287  }
288  $ref_ids = ilObject::_getAllReferences($this->getTargetId());
289  $this->setTargetRefId(current($ref_ids));
290 
292  #$this->title = $this->lng->txt('reference_of').' '.ilObject::_lookupTitle($this->getTargetId());
293  $this->title = ilObject::_lookupTitle($this->getTargetId());
294  }
295  }
296 
301  public function getPresentationTitle()
302  {
303  if ($this->getTitleType() == self::TITLE_TYPE_CUSTOM) {
304  return $this->getTitle();
305  } else {
306  return $this->lng->txt('reference_of') . ' ' . $this->getTitle();
307  }
308  }
309 
317  public function update()
318  {
319  $ilDB = $this->db;
320 
321  parent::update();
322 
323  $query = "DELETE FROM container_reference " .
324  "WHERE obj_id = " . $ilDB->quote($this->getId(), 'integer') . " ";
325  $ilDB->manipulate($query);
326 
327  $query = "INSERT INTO container_reference (obj_id, target_obj_id, title_type) " .
328  "VALUES( " .
329  $ilDB->quote($this->getId(), 'integer') . ", " .
330  $ilDB->quote($this->getTargetId(), 'integer') . ", " .
331  $ilDB->quote($this->getTitleType(), 'integer') . ' ' .
332  ")";
333  $ilDB->manipulate($query);
334  }
335 
343  public function delete()
344  {
345  $ilDB = $this->db;
346 
347  if (!parent::delete()) {
348  return false;
349  }
350 
351  $query = "DELETE FROM container_reference " .
352  "WHERE obj_id = " . $ilDB->quote($this->getId(), 'integer') . " ";
353  $ilDB->manipulate($query);
354 
355  return true;
356  }
357 
366  public function cloneObject($a_target_id, $a_copy_id = 0, $a_omit_tree = false)
367  {
368  $ilDB = $this->db;
370 
371  $new_obj = parent::cloneObject($a_target_id, $a_copy_id, $a_omit_tree);
372 
373  $query = "INSERT INTO container_reference (obj_id, target_obj_id, title_type) " .
374  "VALUES( " .
375  $ilDB->quote($new_obj->getId(), 'integer') . ", " .
376  $ilDB->quote($this->getTargetId(), 'integer') . ", " .
377  $ilDB->quote($this->getTitleType(), 'integer') . ' ' .
378  ")";
379  $ilDB->manipulate($query);
380  return $new_obj;
381  }
382 }
global $DIC
Definition: saml.php:7
getPresentationTitle()
Get presentation title.
static _lookupTitle($a_id)
lookup object title
user()
Definition: user.php:4
static _getAllReferences($a_id)
get all reference ids of object
setTitleType($type)
Set title type.
foreach($_POST as $key=> $value) $res
static _lookupTitle($a_obj_id)
Overwitten from base class.
getId()
get object id public
getTargetRefId()
get Target ref_id
cloneObject($a_target_id, $a_copy_id=0, $a_omit_tree=false)
Clone course reference.
getTitle()
get object title public
static _lookupTargetTitle($a_obj_id)
Lookup target title.
$ilUser
Definition: imgupload.php:18
$query
$row
update($pash, $contents, Config $config)
setTargetRefId($a_id)
set target ref_id
setTargetId($a_target_id)
set target id
global $ilDB
$ret
Definition: parser.php:6
static _lookupSourceId($a_target_id)
lookup source id
static _lookupTargetRefId($a_obj_id)
Lookup target ref_id.
static _lookupSourceIds($a_target_id)
Get ids of all container references that target the object with the given id.
static _lookupTargetId($a_obj_id)
lookup target id
__construct($a_id=0, $a_call_by_reference=true)
Constructor.