ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
class.ilBibliographicEntry.php
Go to the documentation of this file.
1<?php
2
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 static $instances = array();
48
49
56 public static function getInstance($file_type, $entry_id = NULL) {
57 if (!$entry_id) {
58 return new self($file_type, $entry_id);
59 }
60
61 if (!isset(self::$instances[$entry_id])) {
62 self::$instances[$entry_id] = new self($file_type, $entry_id);
63 }
64
65 return self::$instances[$entry_id];
66 }
67
68
73 protected function __construct($file_type, $entry_id = NULL) {
74 $this->file_type = $file_type;
75 if ($entry_id) {
76 $this->setEntryId($entry_id);
77 $this->doRead();
78 }
79 }
80
81
87 function doCreate() {
88 global $ilDB;
89 //auto-increment il_bibl_entry
90 $this->setEntryId($ilDB->nextID('il_bibl_entry'));
91 //table il_bibl_entry
92 $ilDB->manipulate("INSERT INTO il_bibl_entry " . "(data_id, id, type) VALUES (" . $ilDB->quote($this->getBibliographicObjId(), "integer")
93 . "," . // data_id
94 $ilDB->quote($this->getEntryId(), "integer") . "," . // id
95 $ilDB->quote($this->getType(), "text") . // type
96 ")");
97 //table il_bibl_attribute
98 foreach ($this->getAttributes() as $attribute) {
99 //auto-increment il_bibl_attribute
100 $id = $ilDB->nextID('il_bibl_attribute');
101 $ilDB->manipulate("INSERT INTO il_bibl_attribute " . "(entry_id, name, value, id) VALUES (" . $ilDB->quote($this->getEntryId(), "integer")
102 . "," . // entry_id
103 $ilDB->quote($attribute['name'], "text") . "," . // name
104 $ilDB->quote($attribute['value'], "text") . "," . // value
105 $ilDB->quote($id, "integer") . // id
106 ")");
107 }
108 }
109
110
114 function doRead() {
115 global $ilDB;
116 //table il_bibl_entry
117 $set = $ilDB->query("SELECT * FROM il_bibl_entry " . " WHERE id = " . $ilDB->quote($this->getEntryId(), "integer"));
118 while ($rec = $ilDB->fetchAssoc($set)) {
119 $this->setType($rec['type']);
120 }
121 $this->setAttributes($this->loadAttributes());
122 $this->setOverwiew();
123 }
124
125
129 function doUpdate() {
130 global $ilDB;
131 //table il_bibl_entry
132 $ilDB->manipulate($up = "UPDATE il_bibl_entry SET " . " type = " . $ilDB->quote($this->getType(), "integer") . // type
133 " WHERE id = " . $ilDB->quote($this->getEntryId(), "integer"));
134 //table il_bibl_attribute
135 foreach ($this->getAttributes() as $attribute) {
136 $ilDB->manipulate($up = "UPDATE il_bibl_attribute SET " . " name = " . $ilDB->quote($attribute['name'], "integer") . "," . // name
137 " value = " . $ilDB->quote($attribute['value'], "integer") . "," . // value
138 " WHERE id = " . $ilDB->quote($attribute['id'], "integer"));
139 }
140 }
141
142
146 function doDelete() {
147 global $ilDB;
148 $this->emptyCache();
149 $this->deleteOptions();
150 $ilDB->manipulate("DELETE FROM il_bibl_entry WHERE id = " . $ilDB->quote($this->getEntryId(), "integer"));
151 $ilDB->manipulate("DELETE FROM il_bibl_attribute WHERE entry_id = " . $ilDB->quote($this->getEntryId(), "integer"));
152 }
153
154
160 protected function loadAttributes() {
161 global $ilDB;
162 $all_attributes = array();
163 //table il_bibl_attribute
164 $set = $ilDB->query("SELECT * FROM il_bibl_attribute " . " WHERE entry_id = " . $ilDB->quote($this->getEntryId(), "integer"));
165 while ($rec = $ilDB->fetchAssoc($set)) {
166 $all_attributes[$rec['name']] = $rec['value'];
167 }
168 if ($this->file_type == "ris") {
169 //for RIS-Files also add the type;
170 $type = $this->getType();
171 } else {
172 $type = 'default';
173 }
174 $parsed_attributes = array();
175 foreach ($all_attributes as $key => $value) {
176 // surround links with <a href="">
177 // Allowed signs in URL: a-z A-Z 0-9 . ? & _ / - ~ ! ' * ( ) + , : ; @ = $ # [ ] %
178 $value = preg_replace('!(http)(s)?:\/\/[a-zA-Z0-9.?&_/\-~\!\'\*()+,:;@=$#\[\]%]+!', "<a href=\"\\0\" target=\"_blank\">\\0</a>", $value);
179 $parsed_attributes[strtolower($this->file_type . '_' . $type . '_' . $key)] = $value;
180 }
181
182 return $parsed_attributes;
183 }
184
185
189 public function setAttributes($attributes) {
190 $this->attributes = $attributes;
191 }
192
193
197 public function getAttributes() {
198 return $this->attributes;
199 }
200
201
202 public function setOverwiew() {
203 $attributes = $this->getAttributes();
204 //Get the model which declares which attributes to show in the overview table and how to show them
205 //example for overviewModels: $overviewModels['bib']['default'] => "[<strong>|bib_default_author|</strong>: ][|bib_default_title|. ]<Emph>[|bib_default_publisher|][, |bib_default_year|][, |bib_default_address|].</Emph>"
207 //get design for specific entry type or get filetypes default design if type is not specified
208 $entryType = $this->getType();
209 //if there is no model for the specific entrytype (book, article, ....) the entry overview will be structured by the default entrytype from the given filetype (ris, bib, ...)
210 if (!$overviewModels[$this->file_type][$entryType]) {
211 $entryType = 'default';
212 }
213 $single_entry = $overviewModels[$this->file_type][$entryType];
214 //split the model into single attributes (which begin and end with a bracket, eg [|bib_default_title|. ] )
215 //such values are saved in $placeholders[0] while the same values but whithout brackets are saved in $placeholders[1] (eg |bib_default_title|. )
216 preg_match_all('/\[(.*?)\]/', $single_entry, $placeholders);
217 foreach ($placeholders[1] as $key => $placeholder) {
218 //cut a moedel attribute like |bib_default_title|. in three pieces while $cuts[1] is the attribute key for the actual value and $cuts[0] is what comes before respectively $cuts[2] is what comes after the value if it is not empty.
219 $cuts = explode('|', $placeholder);
220 //if attribute key does not exist, because it comes from the default entry (e.g. ris_default_u2), we replace 'default' with the entrys type (e.g. ris_book_u2)
221 if (!$attributes[$cuts[1]]) {
222 $attribute_elements = explode('_', $cuts[1]);
223 $attribute_elements[1] = strtolower($this->getType());
224 $cuts[1] = implode('_', $attribute_elements);
225 }
226 if ($attributes[$cuts[1]]) {
227 //if the attribute for the attribute key exists, replace one attribute in the overview text line of a single entry with its actual value and the text before and after the value given by the model
228 $single_entry = str_replace($placeholders[0][$key], $cuts[0] . $attributes[$cuts[1]] . $cuts[2], $single_entry);
229 // replace the <emph> tags with a span, in order to make text italic by css
230 do {
231 $first_sign_after_begin_emph_tag = strpos(strtolower($single_entry), '<emph>') + 6;
232 $last_sign_after_end_emph_tag = strpos(strtolower($single_entry), '</emph>');
233 $italic_text_length = $last_sign_after_end_emph_tag - $first_sign_after_begin_emph_tag;
234 //would not be true if there is no <emph> tag left
235 if ($last_sign_after_end_emph_tag) {
236 $italic_text = substr($single_entry, $first_sign_after_begin_emph_tag, $italic_text_length);
237 //parse
238 $it_tpl = new ilTemplate("tpl.bibliographic_italicizer.html", true, true, "Modules/Bibliographic");
239 $it_tpl->setCurrentBlock("italic_section");
240 $it_tpl->setVariable('ITALIC_STRING', $italic_text);
241 $it_tpl->parseCurrentBlock();
242 //replace the emph tags and the text between with the parsed text from il_tpl
243 $text_before_emph_tag = substr($single_entry, 0, $first_sign_after_begin_emph_tag - 6);
244 $text_after_emph_tag = substr($single_entry, $last_sign_after_end_emph_tag + 7);
245 $single_entry = $text_before_emph_tag . $it_tpl->get() . $text_after_emph_tag;
246 }
247 } while ($last_sign_after_end_emph_tag);
248 } else {
249 //if the attribute for the attribute key does not exist, just remove this attribute-key from the overview text line of a single entry
250 $single_entry = str_replace($placeholders[0][$key], '', $single_entry);
251 }
252 }
253 $this->Overwiew = $single_entry;
254 }
255
256
260 public function getOverwiew() {
261 return $this->Overwiew;
262 }
263
264
269 $this->bibliographic_obj_id = $bibliographic_obj_id;
270 }
271
272
276 public function getBibliographicObjId() {
278 }
279
280
284 public function setEntryId($entry_id) {
285 $this->entry_id = $entry_id;
286 }
287
288
292 public function getEntryId() {
293 return $this->entry_id;
294 }
295
296
300 public function setType($type) {
301 $this->type = $type;
302 }
303
304
308 public function getType() {
309 return $this->type;
310 }
311
312
320 static function getAllEntries($object_id) {
321 global $ilDB;
322 $entries = array();
323 $set = $ilDB->query("SELECT id FROM il_bibl_entry " . " WHERE data_id = " . $ilDB->quote($object_id, "integer"));
324 while ($rec = $ilDB->fetchAssoc($set)) {
325 $entries[]['entry_id'] = $rec['id'];
326 }
327
328 return $entries;
329 }
330}
Class ilObjBibliographic.
__construct($file_type, $entry_id=NULL)
static getAllEntries($object_id)
Read all entries from the database.
doDelete()
Delete data from db.
loadAttributes()
Reads all the entrys attributes from database.
setBibliographicObjId($bibliographic_obj_id)
doRead()
Read data from database tables il_bibl_entry and il_bibl_attribute.
static getInstance($file_type, $entry_id=NULL)
doUpdate()
Update database tables il_bibl_entry and il_bibl_attribute.
special template class to simplify handling of ITX/PEAR
global $ilDB