ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilBibliographicEntry.php
Go to the documentation of this file.
1 <?php
2 require_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 
77  protected function __construct($file_type, $entry_id = NULL) {
78  $this->file_type = $file_type;
79  if ($entry_id) {
80  $this->setEntryId($entry_id);
81  $this->doRead();
82  }
83  }
84 
85 
86  public function doCreate() {
87  global $ilDB;
88  //auto-increment il_bibl_entry
89  $this->setEntryId($ilDB->nextID('il_bibl_entry'));
90  //table il_bibl_entry
91  $ilDB->manipulate("INSERT INTO il_bibl_entry " . "(data_id, id, type) VALUES (" . $ilDB->quote($this->getBibliographicObjId(), "integer")
92  . "," . // data_id
93  $ilDB->quote($this->getEntryId(), "integer") . "," . // id
94  $ilDB->quote($this->getType(), "text") . // type
95  ")");
96  //table il_bibl_attribute
97  foreach ($this->getAttributes() as $attribute) {
98  //auto-increment il_bibl_attribute
99  $id = $ilDB->nextID('il_bibl_attribute');
100  $ilDB->manipulate("INSERT INTO il_bibl_attribute " . "(entry_id, name, value, id) VALUES (" . $ilDB->quote($this->getEntryId(), "integer")
101  . "," . // entry_id
102  $ilDB->quote($attribute['name'], "text") . "," . // name
103  $ilDB->quote($attribute['value'], "text") . "," . // value
104  $ilDB->quote($id, "integer") . // id
105  ")");
106  }
107  }
108 
109 
110  public function doRead() {
111  global $ilDB;
112  //table il_bibl_entry
113  $set = $ilDB->query("SELECT * FROM il_bibl_entry " . " WHERE id = " . $ilDB->quote($this->getEntryId(), "integer"));
114  while ($rec = $ilDB->fetchAssoc($set)) {
115  $this->setType($rec['type']);
116  }
117  $this->setAttributes($this->loadAttributes());
118  $this->initOverviewHTML();
119  }
120 
121 
122  public function doUpdate() {
123  global $ilDB;
124  //table il_bibl_entry
125  $ilDB->manipulate($up = "UPDATE il_bibl_entry SET " . " type = " . $ilDB->quote($this->getType(), "integer") . // type
126  " WHERE id = " . $ilDB->quote($this->getEntryId(), "integer"));
127  //table il_bibl_attribute
128  foreach ($this->getAttributes() as $attribute) {
129  $ilDB->manipulate($up = "UPDATE il_bibl_attribute SET " . " name = " . $ilDB->quote($attribute['name'], "integer") . "," . // name
130  " value = " . $ilDB->quote($attribute['value'], "integer") . "," . // value
131  " WHERE id = " . $ilDB->quote($attribute['id'], "integer"));
132  }
133  }
134 
135 
136  public function doDelete() {
137  global $ilDB;
138  $this->emptyCache();
139  $this->deleteOptions();
140  $ilDB->manipulate("DELETE FROM il_bibl_entry WHERE id = " . $ilDB->quote($this->getEntryId(), "integer"));
141  $ilDB->manipulate("DELETE FROM il_bibl_attribute WHERE entry_id = " . $ilDB->quote($this->getEntryId(), "integer"));
142  }
143 
144 
150  protected function loadAttributes() {
151  global $ilDB;
152  $all_attributes = array();
153  //table il_bibl_attribute
154  $set = $ilDB->query("SELECT * FROM il_bibl_attribute " . " WHERE entry_id = " . $ilDB->quote($this->getEntryId(), "integer"));
155  while ($rec = $ilDB->fetchAssoc($set)) {
156  $all_attributes[$rec['name']] = $rec['value'];
157  }
158  if ($this->file_type == "ris") {
159  //for RIS-Files also add the type;
160  $type = $this->getType();
161  } else {
162  $type = 'default';
163  }
164  $parsed_attributes = array();
165  foreach ($all_attributes as $key => $value) {
166  // surround links with <a href="">
167  // Allowed signs in URL: a-z A-Z 0-9 . ? & _ / - ~ ! ' * ( ) + , : ; @ = $ # [ ] %
168  $value = preg_replace('!(http)(s)?:\/\/[a-zA-Z0-9.?&_/\-~\!\'\*()+,:;@=$#\[\]%]+!', "<a href=\"\\0\" target=\"_blank\" rel=\"noopener\">\\0</a>", $value);
169  $parsed_attributes[strtolower($this->file_type . '_' . $type . '_' . $key)] = $value;
170  }
171 
172  return $parsed_attributes;
173  }
174 
175 
179  public function setAttributes($attributes) {
180  $this->attributes = $attributes;
181  }
182 
183 
187  public function getAttributes() {
188  return $this->attributes;
189  }
190 
191 
192  public function initOverviewHTML() {
193  $ilBiblOverviewGUI = new ilBiblOverviewGUI($this);
194  $this->setOverview($ilBiblOverviewGUI->getHtml());
195  }
196 
197 
201  public function getOverview() {
202  return $this->overview;
203  }
204 
205 
209  public function setOverview($overview) {
210  $this->overview = $overview;
211  }
212 
213 
218  $this->bibliographic_obj_id = $bibliographic_obj_id;
219  }
220 
221 
225  public function getBibliographicObjId() {
227  }
228 
229 
233  public function setEntryId($entry_id) {
234  $this->entry_id = $entry_id;
235  }
236 
237 
241  public function getEntryId() {
242  return $this->entry_id;
243  }
244 
245 
249  public function setType($type) {
250  $this->type = $type;
251  }
252 
253 
257  public function getType() {
258  return $this->type;
259  }
260 
261 
265  public function getFileType() {
266  return $this->file_type;
267  }
268 
269 
273  public function setFileType($file_type) {
274  $this->file_type = $file_type;
275  }
276 
277 
285  static function getAllEntries($object_id) {
286  global $ilDB;
287  $entries = array();
288  $set = $ilDB->query("SELECT id FROM il_bibl_entry " . " WHERE data_id = " . $ilDB->quote($object_id, "integer"));
289  while ($rec = $ilDB->fetchAssoc($set)) {
290  $entries[]['entry_id'] = $rec['id'];
291  }
292 
293  return $entries;
294  }
295 }
__construct($file_type, $entry_id=NULL)
static getInstance($file_type, $entry_id=NULL)
static getAllEntries($object_id)
Read all entries from the database.
loadAttributes()
Reads all the entrys attributes from database.
Class ilBiblOverviewGUI.
global $ilDB
Class ilBibliographicEntry.
setBibliographicObjId($bibliographic_obj_id)