ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilBibliographicEntry.php
Go to the documentation of this file.
1<?php
2require_once('./Modules/Bibliographic/classes/class.ilBiblOverviewGUI.php');
3/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
4
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 if (!$entry_id) {
62 return new self($file_type, $entry_id);
63 }
64
65 if (!isset(self::$instances[$entry_id])) {
66 self::$instances[$entry_id] = new self($file_type, $entry_id);
67 }
68
69 return self::$instances[$entry_id];
70 }
71
72
79 public static function exists($entry_id, $obj_id) {
80 $q = "SELECT * FROM il_bibl_entry WHERE id = %s AND data_id = %s";
81 global $DIC;
82 $ilDB = $DIC['ilDB'];
86 $r = $ilDB->queryF($q, array('integer', 'integer'), array($entry_id, $obj_id));
87
88 return ($r->numRows() > 0);
89 }
90
91
96 protected function __construct($file_type, $entry_id = null) {
97 $this->file_type = $file_type;
98 if ($entry_id) {
99 $this->setEntryId($entry_id);
100 $this->doRead();
101 }
102 }
103
104
105 public function doCreate() {
106 global $DIC;
107 $ilDB = $DIC['ilDB'];
108 //auto-increment il_bibl_entry
109 $this->setEntryId($ilDB->nextID('il_bibl_entry'));
110 //table il_bibl_entry
111 $ilDB->manipulate("INSERT INTO il_bibl_entry " . "(data_id, id, type) VALUES (" . $ilDB->quote($this->getBibliographicObjId(), "integer")
112 . "," . // data_id
113 $ilDB->quote($this->getEntryId(), "integer") . "," . // id
114 $ilDB->quote($this->getType(), "text") . // type
115 ")");
116 //table il_bibl_attribute
117 foreach ($this->getAttributes() as $attribute) {
118 //auto-increment il_bibl_attribute
119 $id = $ilDB->nextID('il_bibl_attribute');
120 $ilDB->manipulate("INSERT INTO il_bibl_attribute " . "(entry_id, name, value, id) VALUES (" . $ilDB->quote($this->getEntryId(), "integer")
121 . "," . // entry_id
122 $ilDB->quote($attribute['name'], "text") . "," . // name
123 $ilDB->quote($attribute['value'], "text") . "," . // value
124 $ilDB->quote($id, "integer") . // id
125 ")");
126 }
127 }
128
129
130 public function doRead() {
131 global $DIC;
132 $ilDB = $DIC['ilDB'];
133 //table il_bibl_entry
134 $set = $ilDB->query("SELECT * FROM il_bibl_entry " . " WHERE id = " . $ilDB->quote($this->getEntryId(), "integer"));
135 while ($rec = $ilDB->fetchAssoc($set)) {
136 $this->setType($rec['type']);
137 }
138 $this->setAttributes($this->loadAttributes());
139 $this->initOverviewHTML();
140 }
141
142
143 public function doUpdate() {
144 global $DIC;
145 $ilDB = $DIC['ilDB'];
146 //table il_bibl_entry
147 $ilDB->manipulate($up = "UPDATE il_bibl_entry SET " . " type = " . $ilDB->quote($this->getType(), "integer") . // type
148 " WHERE id = " . $ilDB->quote($this->getEntryId(), "integer"));
149 //table il_bibl_attribute
150 foreach ($this->getAttributes() as $attribute) {
151 $ilDB->manipulate($up = "UPDATE il_bibl_attribute SET " . " name = " . $ilDB->quote($attribute['name'], "integer") . "," . // name
152 " value = " . $ilDB->quote($attribute['value'], "integer") . "," . // value
153 " WHERE id = " . $ilDB->quote($attribute['id'], "integer"));
154 }
155 }
156
157
158 public function doDelete() {
159 global $DIC;
160 $ilDB = $DIC['ilDB'];
161 $this->emptyCache();
162 $this->deleteOptions();
163 $ilDB->manipulate("DELETE FROM il_bibl_entry WHERE id = " . $ilDB->quote($this->getEntryId(), "integer"));
164 $ilDB->manipulate("DELETE FROM il_bibl_attribute WHERE entry_id = " . $ilDB->quote($this->getEntryId(), "integer"));
165 }
166
167
173 protected function loadAttributes() {
174 global $DIC;
175 $ilDB = $DIC['ilDB'];
176 $all_attributes = array();
177 //table il_bibl_attribute
178 $set = $ilDB->query("SELECT * FROM il_bibl_attribute " . " WHERE entry_id = " . $ilDB->quote($this->getEntryId(), "integer"));
179 while ($rec = $ilDB->fetchAssoc($set)) {
180 $all_attributes[$rec['name']] = $rec['value'];
181 }
182 if ($this->file_type == "ris") {
183 //for RIS-Files also add the type;
184 $type = $this->getType();
185 } else {
186 $type = 'default';
187 }
188 $parsed_attributes = array();
189 foreach ($all_attributes as $key => $value) {
190 // surround links with <a href="">
191 // Allowed signs in URL: a-z A-Z 0-9 . ? & _ / - ~ ! ' * ( ) + , : ; @ = $ # [ ] %
192 $value = preg_replace('!(http)(s)?:\/\/[a-zA-Z0-9.?&_/\-~\!\'\*()+,:;@=$#\[\]%]+!', "<a href=\"\\0\" target=\"_blank\" rel=\"noopener\">\\0</a>", $value);
193 $parsed_attributes[strtolower($this->file_type . '_' . $type . '_' . $key)] = $value;
194 }
195
196 return $parsed_attributes;
197 }
198
199
203 public function setAttributes($attributes) {
204 $this->attributes = $attributes;
205 }
206
207
211 public function getAttributes() {
212 return $this->attributes;
213 }
214
215
216 public function initOverviewHTML() {
217 $ilBiblOverviewGUI = new ilBiblOverviewGUI($this);
218 $this->setOverview($ilBiblOverviewGUI->getHtml());
219 }
220
221
225 public function getOverview() {
226 return $this->overview;
227 }
228
229
233 public function setOverview($overview) {
234 $this->overview = $overview;
235 }
236
237
242 $this->bibliographic_obj_id = $bibliographic_obj_id;
243 }
244
245
249 public function getBibliographicObjId() {
251 }
252
253
257 public function setEntryId($entry_id) {
258 $this->entry_id = $entry_id;
259 }
260
261
265 public function getEntryId() {
266 return $this->entry_id;
267 }
268
269
273 public function setType($type) {
274 $this->type = $type;
275 }
276
277
281 public function getType() {
282 return $this->type;
283 }
284
285
289 public function getFileType() {
290 return $this->file_type;
291 }
292
293
297 public function setFileType($file_type) {
298 $this->file_type = $file_type;
299 }
300
301
309 static function getAllEntries($object_id) {
310 global $DIC;
311 $ilDB = $DIC['ilDB'];
312 $entries = array();
313 $set = $ilDB->query("SELECT id FROM il_bibl_entry " . " WHERE data_id = " . $ilDB->quote($object_id, "integer"));
314 while ($rec = $ilDB->fetchAssoc($set)) {
315 $entries[]['entry_id'] = $rec['id'];
316 }
317
318 return $entries;
319 }
320}
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)
$r
Definition: example_031.php:79
global $ilDB
global $DIC