ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
5 
13 {
14 
20 
25  protected $entry_id;
26 
31  protected $type;
32 
37  protected $attributes;
38 
43  protected $file_type;
44 
45 
46  function __construct($file_type, $entry_id = null)
47  {
48  $this->file_type = $file_type;
49  if($entry_id)
50  {
51  $this->setEntryId($entry_id);
52  $this->doRead();
53  }
54  }
55 
56 
62  function doCreate()
63  {
64  global $ilDB;
65 
66  //auto-increment il_bibl_entry
67  $this->setEntryId($ilDB->nextID('il_bibl_entry'));
68 
69  //table il_bibl_entry
70  $ilDB->manipulate("INSERT INTO il_bibl_entry " . "(data_id, id, type) VALUES (" .
71  $ilDB->quote($this->getBibliographicObjId(), "integer") . "," . // data_id
72  $ilDB->quote($this->getEntryId(), "integer") . "," . // id
73  $ilDB->quote($this->getType(), "text") . // type
74  ")");
75  //table il_bibl_attribute
76  foreach($this->getAttributes() as $attribute)
77  {
78  //auto-increment il_bibl_attribute
79  $id = $ilDB->nextID('il_bibl_attribute');
80 
81  $ilDB->manipulate("INSERT INTO il_bibl_attribute " . "(entry_id, name, value, id) VALUES (" .
82  $ilDB->quote($this->getEntryId(), "integer") . "," . // entry_id
83  $ilDB->quote($attribute['name'], "text") . "," . // name
84  $ilDB->quote($attribute['value'], "text") . "," . // value
85  $ilDB->quote($id, "integer") . // id
86  ")");
87  }
88  }
89 
93  function doRead()
94  {
95  global $ilDB;
96 
97  //table il_bibl_entry
98  $set = $ilDB->query("SELECT * FROM il_bibl_entry " .
99  " WHERE id = ".$ilDB->quote($this->getEntryId(), "integer")
100  );
101  while ($rec = $ilDB->fetchAssoc($set))
102  {
103  $this->setType($rec['type']);
104  }
105 
106  $this->setAttributes($this->loadAttributes());
107 
108  $this->setOverwiew();
109  }
110 
114  function doUpdate()
115  {
116  global $ilDB;
117 
118  //table il_bibl_entry
119  $ilDB->manipulate($up = "UPDATE il_bibl_entry SET " . " type = " .
120  $ilDB->quote($this->getType(), "integer") . // type
121  " WHERE id = " . $ilDB->quote($this->getEntryId(), "integer"));
122 
123 
124  //table il_bibl_attribute
125  foreach($this->getAttributes() as $attribute)
126  {
127  $ilDB->manipulate($up = "UPDATE il_bibl_attribute SET " .
128  " name = " . $ilDB->quote($attribute['name'], "integer") . "," . // name
129  " value = " . $ilDB->quote($attribute['value'], "integer") . "," . // value
130  " WHERE id = " . $ilDB->quote($attribute['id'], "integer"));
131  }
132  }
133 
137  function doDelete()
138  {
139  global $ilDB;
140 
141  $this->emptyCache();
142  $this->deleteOptions();
143 
144  $ilDB->manipulate("DELETE FROM il_bibl_entry WHERE id = " . $ilDB->quote($this->getEntryId(), "integer"));
145  $ilDB->manipulate("DELETE FROM il_bibl_attribute WHERE entry_id = " . $ilDB->quote($this->getEntryId(), "integer"));
146  }
147 
152  protected function loadAttributes()
153  {
154  global $ilDB;
155 
156  $all_attributes = array();
157 
158  //table il_bibl_attribute
159  $set = $ilDB->query("SELECT * FROM il_bibl_attribute " .
160  " WHERE entry_id = ".$ilDB->quote($this->getEntryId(), "integer")
161  );
162  while ($rec = $ilDB->fetchAssoc($set))
163  {
164  $all_attributes[$rec['name']] = $rec['value'];
165  }
166 
167  if($this->file_type == "ris"){
168  //for RIS-Files also add the type;
169  $type = $this->getType();
170  }else{
171  $type = 'default';
172  }
173 
174  $parsed_attributes = array();
175  foreach($all_attributes as $key => $value){
176 
177  // surround links with <a href="">
178  // Allowed signs in URL: a-z A-Z 0-9 . ? & _ / - ~ ! ' * ( ) + , : ; @ = $ # [ ] %
179  $value = preg_replace('!(http)(s)?:\/\/[a-zA-Z0-9.?&_/\-~\!\'\*()+,:;@=$#\[\]%]+!', "<a href=\"\\0\" target=\"_blank\">\\0</a>",$value);
180 
181  $parsed_attributes[strtolower($this->file_type . '_' . $type . '_' . $key)] = $value;
182  }
183  return $parsed_attributes;
184  }
185 
186 
187  public function setAttributes($attributes)
188  {
189  $this->attributes = $attributes;
190  }
191 
192  public function getAttributes()
193  {
194  return $this->attributes;
195  }
196 
197 
198  public function setOverwiew()
199  {
200 
201  $attributes = $this->getAttributes();
202 
203  //Get the model which declares which attributes to show in the overview table and how to show them
204  //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>"
205  $overviewModels = ilObjBibliographic::__getAllOverviewModels();
206 
207  //get design for specific entry type or get filetypes default design if type is not specified
208  $entryType = $this->getType();
209 
210  //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, ...)
211  if(!$overviewModels[$this->file_type][$entryType]){
212  $entryType = 'default';
213  }
214 
215  $single_entry = $overviewModels[$this->file_type][$entryType];
216 
217  //split the model into single attributes (which begin and end with a bracket, eg [|bib_default_title|. ] )
218  //such values are saved in $placeholders[0] while the same values but whithout brackets are saved in $placeholders[1] (eg |bib_default_title|. )
219  preg_match_all('/\[(.*?)\]/', $single_entry, $placeholders);
220 
221 
222  foreach($placeholders[1] as $key => $placeholder){
223  //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.
224  $cuts = explode('|', $placeholder);
225 
226 
227  //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)
228  if(!$attributes[$cuts[1]]){
229  $attribute_elements = explode('_', $cuts[1]);
230  $attribute_elements[1] = strtolower($this->getType());
231  $cuts[1] = implode('_', $attribute_elements);
232  }
233 
234  if($attributes[$cuts[1]]){
235  //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
236  $single_entry = str_replace($placeholders[0][$key], $cuts[0] . $attributes[$cuts[1]] . $cuts[2], $single_entry);
237  // replace the <emph> tags with a span, in order to make text italic by css
238  do{
239  $first_sign_after_begin_emph_tag = strpos(strtolower($single_entry), '<emph>') + 6;
240  $last_sign_after_end_emph_tag = strpos(strtolower($single_entry), '</emph>');
241  $italic_text_length = $last_sign_after_end_emph_tag - $first_sign_after_begin_emph_tag;
242 
243  //would not be true if there is no <emph> tag left
244  if($last_sign_after_end_emph_tag){
245  $italic_text = substr($single_entry, $first_sign_after_begin_emph_tag, $italic_text_length);
246 
247  //parse
248  $it_tpl = new ilTemplate("tpl.bibliographic_italicizer.html", true, true, "Modules/Bibliographic");
249  $it_tpl->setCurrentBlock("italic_section");
250 
251  $it_tpl->setVariable('ITALIC_STRING', $italic_text);
252  $it_tpl->parseCurrentBlock();
253 
254  //replace the emph tags and the text between with the parsed text from il_tpl
255  $text_before_emph_tag = substr($single_entry, 0, $first_sign_after_begin_emph_tag - 6);
256  $text_after_emph_tag = substr($single_entry, $last_sign_after_end_emph_tag + 7);
257  $single_entry = $text_before_emph_tag . $it_tpl->get() . $text_after_emph_tag;
258  }
259  } while($last_sign_after_end_emph_tag);
260  }else{
261  //if the attribute for the attribute key does not exist, just remove this attribute-key from the overview text line of a single entry
262  $single_entry = str_replace($placeholders[0][$key], '', $single_entry);
263  }
264  }
265 
266  $this->Overwiew = $single_entry;
267  }
268 
272  public function getOverwiew()
273  {
274  return $this->Overwiew;
275  }
276 
277 
282  {
283  $this->bibliographic_obj_id = $bibliographic_obj_id;
284  }
285 
289  public function getBibliographicObjId()
290  {
292 
293  }
294 
298  public function setEntryId($entry_id)
299  {
300  $this->entry_id = $entry_id;
301  }
302 
306  public function getEntryId()
307  {
308  return $this->entry_id;
309  }
310 
314  public function setType($type)
315  {
316  $this->type = $type;
317  }
318 
322  public function getType()
323  {
324  return $this->type;
325  }
326 
332  static function __getAllEntries($object_id)
333  {
334  global $ilDB;
335 
336  $entries = array();
337 
338  $set = $ilDB->query("SELECT id FROM il_bibl_entry ".
339  " WHERE data_id = ".$ilDB->quote($object_id, "integer")
340  );
341 
342  while ($rec = $ilDB->fetchAssoc($set))
343  {
344  $entries[]['entry_id'] = $rec['id'];
345  }
346 
347  return $entries;
348 
349  }
350 
351 
352 }