ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilBiblEntryFactory.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
10 {
11 
23  protected $entry_id;
29  protected $type;
35  protected $attributes;
41  protected $file_type;
45  protected $field_factory;
49  protected $overview_factory;
50 
51 
59  {
60  $this->file_type = $file_type;
61  $this->field_factory = $field_factory;
62  $this->overview_factory = $overview_factory;
63  }
64 
65 
70  {
71  $ilBiblEntry = ilBiblEntry::where(array( 'id' => $entry_id ))->first();
73 
74  if ($this->file_type->getId() == ilBiblTypeFactoryInterface::DATA_TYPE_RIS) {
75  //for RIS-Files also add the type;
76  $type = $ilBiblEntry->getType();
77  } else {
78  $type = 'default';
79  }
80  $parsed_attributes = array();
81  foreach ($attributes as $attribute) {
82  // surround links with <a href="">
83  // Allowed signs in URL: a-z A-Z 0-9 . ? & _ / - ~ ! ' * ( ) + , : ; @ = $ # [ ] %
84  $value = preg_replace('!(http)(s)?:\/\/[a-zA-Z0-9.?&_/\-~\!\'\*()+,:;@=$#\[\]%]+!', "<a href=\"\\0\" target=\"_blank\">\\0</a>", $attribute->getValue());
85  $attribute->setValue($value);
86  $parsed_attributes[strtolower($this->file_type->getStringRepresentation() . '_' . $type . '_' . $attribute->getName())] = $value;
87 
88  $this->field_factory->findOrCreateFieldOfAttribute($attribute);
89  }
90 
91  return $parsed_attributes;
92  }
93 
94 
98  public function findByIdAndTypeString($id, $type_string) : ilBiblEntryInterface
99  {
100  return ilBiblEntry::where(array( 'id' => $id))->first();
101  }
102 
103 
107  public function findOrCreateEntry($id, $bibliographic_obj_id, $entry_type)
108  {
109  $inst = $this->getARInstance($id);
110  if (!$inst) {
111  $inst = $this->createEntry($bibliographic_obj_id, $entry_type);
112  }
113  $inst->setDataId($bibliographic_obj_id);
114  $inst->setEntryType($entry_type);
115  $inst->update();
116 
117  return $inst;
118  }
119 
120 
124  public function createEntry($bibliographic_obj_id, $entry_type)
125  {
126  $inst = new ilBiblEntry();
127  $inst->setDataId($bibliographic_obj_id);
128  $inst->setEntryType($entry_type);
129  $inst->create();
130 
131  return $inst;
132  }
133 
134 
138  public function getEmptyInstance()
139  {
140  return new ilBiblEntry();
141  }
142 
143 
149  private function getARInstance($id)
150  {
151  return ilBiblEntry::where([ "ïd" => $id ])->first();
152  }
153 
154 
158  public function filterEntriesForTable($object_id, ilBiblTableQueryInfo $info = null)
159  {
160  $entries = $this->filterEntryIdsForTableAsArray($object_id, $info);
161  $entry_objects = [];
162  foreach ($entries as $entry_id => $entry) {
163  $entry_objects[$entry_id] = $this->findByIdAndTypeString($entry['type'], $entry['id']);
164  }
165 
166  return $entry_objects;
167  }
168 
169 
173  public function filterEntryIdsForTableAsArray($object_id, ilBiblTableQueryInfo $info = null)
174  {
175  global $DIC;
176 
177  $types = [ "integer" ];
178  $values = [ $object_id ];
179 
180  if ($info instanceof ilBiblTableQueryInfo) {
181  $filters = $info->getFilters();
182  if (!empty($filters)) {
183  $q = "SELECT (e.id), e.type FROM il_bibl_entry AS e WHERE data_id = %s";
184  foreach ($filters as $filter) {
185  $value = $filter->getFieldValue();
186  if (!$value) {
187  continue;
188  }
189  if ($filter->getOperator() === "IN" && is_array($filter->getFieldValue())) {
190  $types[] = "text";
191  $values[] = $filter->getFieldName();
192  $q .= " AND e.id IN (SELECT a.entry_id FROM il_bibl_attribute AS a WHERE a.name = %s AND " . $DIC->database()->in("a.value", $value, false, "text") . ")";
193  } else {
194  $types[] = "text";
195  $values[] = $filter->getFieldName();
196  $types[] = "text";
197  $values[] = "{$value}";
198  $q .= " AND e.id IN (SELECT a.entry_id FROM il_bibl_attribute AS a WHERE a.name = %s AND a.value {$filter->getOperator()} %s )";
199  }
200  }
201  } else {
202  $q = "SELECT DISTINCT (e.id), e.type FROM il_bibl_entry AS e
203  JOIN il_bibl_attribute AS a ON a.entry_id = e.id
204  WHERE data_id = %s";
205  }
206  }
207  $entries = array();
208  $set = $DIC->database()->queryF($q, $types, $values);
209 
210  $i = 0;
211  while ($rec = $DIC->database()->fetchAssoc($set)) {
212  $entries[$i]['entry_id'] = $rec['id'];
213  $entries[$i]['entry_type'] = $rec['type'];
214  $i++;
215  }
216 
217  return $entries;
218  }
219 
220 
221  public function deleteEntryById($id)
222  {
223  $entry = ilBiblEntry::where(array('id' => $id))->first();
224  if ($entry instanceof ilBiblEntry) {
225  $entry->delete();
226  }
227  }
228 
229 
230  public function getAllEntries($object_id)
231  {
232  return ilBiblEntry::where(array( 'data_id' => $object_id ))->first();
233  }
234 
235 
236  public function getEntryById($id)
237  {
238  return ilBiblEntry::where(array( 'id' => $id ))->first();
239  }
240 
241 
243  {
244  return ilBiblAttribute::where(array( 'entry_id' => $id ))->get();
245  }
246 
250  public function getFileType()
251  {
252  return $this->file_type;
253  }
254 
255 
259  public function setFileType($file_type)
260  {
261  $this->file_type = $file_type;
262  }
263 
264 
268  public function setAttributes($attributes)
269  {
270  $this->attributes = $attributes;
271  }
272 
273 
278  public function getAttributes()
279  {
280  return $this->attributes;
281  }
282 }
getAllEntries($object_id)
Read all entries from the database.
global $DIC
Definition: saml.php:7
if(!array_key_exists('StateId', $_REQUEST)) $id
findOrCreateEntry($id, $bibliographic_obj_id, $entry_type)
static where($where, $operator=null)
filterEntriesForTable($object_id, ilBiblTableQueryInfo $info=null)
Interface ilBiblEntryFactoryInterface.
Interface ilBiblTypeInterface.
createEntry($bibliographic_obj_id, $entry_type)
__construct(ilBiblFieldFactoryInterface $field_factory, \ilBiblTypeInterface $file_type, ilBiblOverviewModelFactoryInterface $overview_factory)
ilBiblEntryFactory constructor.
Class ilBiblEntryFactory.
$values
Class ilBiblTableQueryInfo.
Interface ilBiblFieldFactoryInterface.
Class ilBiblEntry.
Class ilBiblOverviewModelFactoryInterface.
findByIdAndTypeString($id, $type_string)
filterEntryIdsForTableAsArray($object_id, ilBiblTableQueryInfo $info=null)
$i
Definition: disco.tpl.php:19
getEntryById($id)
Get entry from the database.
$info
Definition: index.php:5
Interface ilBiblEntryInterface.