ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilBibliographicEntry.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
12{
13
25 protected $entry_id;
31 protected $type;
37 protected $attributes;
43 protected $file_type;
47 protected $overview = '';
51 protected static $instances = array();
52
53
60 public static function getInstance($file_type, $entry_id = null)
61 {
62 if (!$entry_id) {
63 return new self($file_type, $entry_id);
64 }
65
66 if (!isset(self::$instances[$entry_id])) {
67 self::$instances[$entry_id] = new self($file_type, $entry_id);
68 }
69
70 return self::$instances[$entry_id];
71 }
72
73
80 public static function exists($entry_id, $obj_id)
81 {
82 $q = "SELECT * FROM il_bibl_entry WHERE id = %s AND data_id = %s";
83 global $DIC;
84 $ilDB = $DIC['ilDB'];
88 $r = $ilDB->queryF($q, array('integer', 'integer'), array($entry_id, $obj_id));
89
90 return ($r->numRows() > 0);
91 }
92
93
98 protected function __construct($file_type, $entry_id = null)
99 {
100 $this->file_type = $file_type;
101 if ($entry_id) {
102 $this->setEntryId($entry_id);
103 $this->doRead();
104 }
105 }
106
107
108 public function doCreate()
109 {
110 global $DIC;
111 $ilDB = $DIC['ilDB'];
112 //auto-increment il_bibl_entry
113 $this->setEntryId($ilDB->nextID('il_bibl_entry'));
114 //table il_bibl_entry
115 $ilDB->manipulate("INSERT INTO il_bibl_entry " . "(data_id, id, type) VALUES ("
116 . $ilDB->quote($this->getBibliographicObjId(), "integer") . ","
117 . // data_id
118 $ilDB->quote($this->getEntryId(), "integer") . "," . // id
119 $ilDB->quote($this->getType(), "text") . // type
120 ")");
121 //table il_bibl_attribute
122 foreach ($this->getAttributes() as $attribute) {
123 //auto-increment il_bibl_attribute
124 $id = $ilDB->nextID('il_bibl_attribute');
125 $ilDB->manipulate("INSERT INTO il_bibl_attribute "
126 . "(entry_id, name, value, id) VALUES ("
127 . $ilDB->quote($this->getEntryId(), "integer") . "," . // entry_id
128 $ilDB->quote($attribute['name'], "text") . "," . // name
129 $ilDB->quote($attribute['value'], "text") . "," . // value
130 $ilDB->quote($id, "integer") . // id
131 ")");
132 }
133 }
134
135
136 public function doRead()
137 {
138 global $DIC;
139 $ilDB = $DIC['ilDB'];
140 //table il_bibl_entry
141 $set = $ilDB->query("SELECT * FROM il_bibl_entry " . " WHERE id = "
142 . $ilDB->quote($this->getEntryId(), "integer"));
143 while ($rec = $ilDB->fetchAssoc($set)) {
144 $this->setType($rec['type']);
145 }
146 $this->setAttributes($this->loadAttributes());
147 $this->initOverviewHTML();
148 }
149
150
151 public function doUpdate()
152 {
153 global $DIC;
154 $ilDB = $DIC['ilDB'];
155 //table il_bibl_entry
156 $ilDB->manipulate($up = "UPDATE il_bibl_entry SET " . " type = "
157 . $ilDB->quote($this->getType(), "integer") . // type
158 " WHERE id = " . $ilDB->quote($this->getEntryId(), "integer"));
159 //table il_bibl_attribute
160 foreach ($this->getAttributes() as $attribute) {
161 $ilDB->manipulate($up = "UPDATE il_bibl_attribute SET " . " name = "
162 . $ilDB->quote($attribute['name'], "integer") . "," . // name
163 " value = " . $ilDB->quote($attribute['value'], "integer") . ","
164 . // value
165 " WHERE id = " . $ilDB->quote($attribute['id'], "integer"));
166 }
167 }
168
169
170 public function doDelete()
171 {
172 global $DIC;
173 $ilDB = $DIC['ilDB'];
174 $this->emptyCache();
175 $this->deleteOptions();
176 $ilDB->manipulate("DELETE FROM il_bibl_entry WHERE id = "
177 . $ilDB->quote($this->getEntryId(), "integer"));
178 $ilDB->manipulate("DELETE FROM il_bibl_attribute WHERE entry_id = "
179 . $ilDB->quote($this->getEntryId(), "integer"));
180 }
181
182
188 protected function loadAttributes()
189 {
190 global $DIC;
191 $ilDB = $DIC['ilDB'];
192 $all_attributes = array();
193 //table il_bibl_attribute
194 $set = $ilDB->query("SELECT * FROM il_bibl_attribute " . " WHERE entry_id = "
195 . $ilDB->quote($this->getEntryId(), "integer"));
196 while ($rec = $ilDB->fetchAssoc($set)) {
197 $all_attributes[$rec['name']] = $rec['value'];
198 }
199 if ($this->file_type == "ris") {
200 //for RIS-Files also add the type;
201 $type = $this->getType();
202 } else {
203 $type = 'default';
204 }
205 $parsed_attributes = array();
206 foreach ($all_attributes as $key => $value) {
207 // surround links with <a href="">
208 // Allowed signs in URL: a-z A-Z 0-9 . ? & _ / - ~ ! ' * ( ) + , : ; @ = $ # [ ] %
209 $value = preg_replace('!(http)(s)?:\/\/[a-zA-Z0-9.?&_/\-~\!\'\*()+,:;@=$#\[\]%]+!', "<a href=\"\\0\" target=\"_blank\" rel=\"noopener\">\\0</a>", $value);
210 $parsed_attributes[strtolower($this->file_type . '_' . $type . '_' . $key)] = $value;
211 }
212
213 return $parsed_attributes;
214 }
215
216
220 public function setAttributes($attributes)
221 {
222 $this->attributes = $attributes;
223 }
224
225
229 public function getAttributes()
230 {
231 return $this->attributes;
232 }
233
234
235 public function initOverviewHTML()
236 {
237 $ilBiblOverviewGUI = new ilBiblOverviewGUI($this);
238 $this->setOverview($ilBiblOverviewGUI->getHtml());
239 }
240
241
245 public function getOverview()
246 {
247 return $this->overview;
248 }
249
250
254 public function setOverview($overview)
255 {
256 $this->overview = $overview;
257 }
258
259
264 {
265 $this->bibliographic_obj_id = $bibliographic_obj_id;
266 }
267
268
272 public function getBibliographicObjId()
273 {
275 }
276
277
281 public function setEntryId($entry_id)
282 {
283 $this->entry_id = $entry_id;
284 }
285
286
290 public function getEntryId()
291 {
292 return $this->entry_id;
293 }
294
295
299 public function setType($type)
300 {
301 $this->type = $type;
302 }
303
304
308 public function getType()
309 {
310 return $this->type;
311 }
312
313
317 public function getFileType()
318 {
319 return $this->file_type;
320 }
321
322
326 public function setFileType($file_type)
327 {
328 $this->file_type = $file_type;
329 }
330
331
339 public static function getAllEntries($object_id)
340 {
341 global $DIC;
342 $ilDB = $DIC['ilDB'];
343 $entries = array();
344 $set = $ilDB->query("SELECT id FROM il_bibl_entry " . " WHERE data_id = "
345 . $ilDB->quote($object_id, "integer"));
346 while ($rec = $ilDB->fetchAssoc($set)) {
347 $entries[]['entry_id'] = $rec['id'];
348 }
349
350 return $entries;
351 }
352}
An exception for terminatinating execution or to throw for unit testing.
Class ilBiblOverviewGUI.
Class ilBibliographicEntry.
static getAllEntries($object_id)
Read all entries from the database.
__construct($file_type, $entry_id=null)
loadAttributes()
Reads all the entrys attributes from database.
setBibliographicObjId($bibliographic_obj_id)
static getInstance($file_type, $entry_id=null)
$key
Definition: croninfo.php:18
$r
Definition: example_031.php:79
if(!array_key_exists('StateId', $_REQUEST)) $id
global $DIC
Definition: saml.php:7
global $ilDB