ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilBiblEntryFactory.php
Go to the documentation of this file.
1 <?php
19 
26 {
39  protected $entry_id;
45  protected $type;
51  protected $attributes;
57  protected $file_type;
61  protected $field_factory;
65  protected $overview_factory;
66 
67 
75  {
76  $this->file_type = $file_type;
77  $this->field_factory = $field_factory;
78  $this->overview_factory = $overview_factory;
79  }
80 
81 
82 
87  {
88  $ilBiblEntry = ilBiblEntry::where(array('id' => $entry_id))->first();
90 
91  if ($this->file_type->getId() == ilBiblTypeFactoryInterface::DATA_TYPE_RIS) {
92  //for RIS-Files also add the type;
93  $type = $ilBiblEntry->getType();
94  } else {
95  $type = 'default';
96  }
97  $parsed_attributes = array();
98  foreach ($attributes as $attribute) {
99  $value = $this->secure($attribute->getValue());
100  // surround links with <a href="">
101  // Allowed signs in URL: a-z A-Z 0-9 . ? & _ / - ~ ! ' * ( ) + , : ; @ = $ # [ ] %
102  $value = preg_replace('!(http)(s)?:\/\/[a-zA-Z0-9.?&_/\-~\!\'\*()+,:;@=$#\[\]%]+!', "<a href=\"\\0\" target=\"_blank\">\\0</a>", $value);
103 
104 
105 
106  $attribute->setValue($value);
107  $parsed_attributes[strtolower($this->file_type->getStringRepresentation() . '_' . $type . '_' . $attribute->getName())] = $value;
108 
109  $this->field_factory->findOrCreateFieldOfAttribute($attribute);
110  }
111 
112  return $parsed_attributes;
113  }
114 
115 
119  public function findByIdAndTypeString($id, $type_string) : ilBiblEntryInterface
120  {
121  return ilBiblEntry::where(array('id' => $id))->first();
122  }
123 
124 
128  public function findOrCreateEntry($id, $bibliographic_obj_id, $entry_type)
129  {
130  $inst = $this->getARInstance($id);
131  if (!$inst) {
132  $inst = $this->createEntry($bibliographic_obj_id, $entry_type);
133  }
134  $inst->setDataId($bibliographic_obj_id);
135  $inst->setEntryType($entry_type);
136  $inst->update();
137 
138  return $inst;
139  }
140 
141 
145  public function createEntry($bibliographic_obj_id, $entry_type)
146  {
147  $inst = new ilBiblEntry();
148  $inst->setDataId($bibliographic_obj_id);
149  $inst->setEntryType($entry_type);
150  $inst->create();
151 
152  return $inst;
153  }
154 
155 
159  public function getEmptyInstance()
160  {
161  return new ilBiblEntry();
162  }
163 
164 
170  private function getARInstance($id)
171  {
172  return ilBiblEntry::where(["ïd" => $id])->first();
173  }
174 
175 
179  public function filterEntriesForTable($object_id, ilBiblTableQueryInfo $info = null)
180  {
181  $entries = $this->filterEntryIdsForTableAsArray($object_id, $info);
182  $entry_objects = [];
183  foreach ($entries as $entry_id => $entry) {
184  $entry_objects[$entry_id] = $this->findByIdAndTypeString($entry['type'], $entry['id']);
185  }
186 
187  return $entry_objects;
188  }
189 
190 
194  public function filterEntryIdsForTableAsArray($object_id, ilBiblTableQueryInfo $info = null)
195  {
196  global $DIC;
197 
198  $types = ["integer"];
199  $values = [$object_id];
200 
201  if ($info instanceof ilBiblTableQueryInfo) {
202  $filters = $info->getFilters();
203  if (!empty($filters)) {
204  $q = "SELECT (e.id), e.type FROM il_bibl_entry AS e WHERE data_id = %s";
205  foreach ($filters as $filter) {
206  $value = $filter->getFieldValue();
207  if (!$value) {
208  continue;
209  }
210  if ($filter->getOperator() === "IN" && is_array($filter->getFieldValue())) {
211  $types[] = "text";
212  $values[] = $filter->getFieldName();
213  $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") . ")";
214  } else {
215  $types[] = "text";
216  $values[] = $filter->getFieldName();
217  $types[] = "text";
218  $values[] = "{$value}";
219  $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 )";
220  }
221  }
222  } else {
223  $q = "SELECT DISTINCT (e.id), e.type FROM il_bibl_entry AS e
224  JOIN il_bibl_attribute AS a ON a.entry_id = e.id
225  WHERE data_id = %s";
226  }
227  }
228  $entries = array();
229  $set = $DIC->database()->queryF($q, $types, $values);
230 
231  $i = 0;
232  while ($rec = $DIC->database()->fetchAssoc($set)) {
233  $entries[$i]['entry_id'] = $rec['id'];
234  $entries[$i]['entry_type'] = $rec['type'];
235  $i++;
236  }
237 
238  return $entries;
239  }
240 
241 
242  public function deleteEntryById($id)
243  {
244  $entry = ilBiblEntry::where(array('id' => $id))->first();
245  if ($entry instanceof ilBiblEntry) {
246  $entry->delete();
247  }
248  }
249 
250 
251  public function getAllEntries($object_id)
252  {
253  return ilBiblEntry::where(array('data_id' => $object_id))->first();
254  }
255 
256 
257  public function getEntryById($id)
258  {
259  return ilBiblEntry::where(array('id' => $id))->first();
260  }
261 
262 
263  public function getAllAttributesByEntryId($id)
264  {
265  return ilBiblAttribute::where(array('entry_id' => $id))->get();
266  }
267 
268 
272  public function getFileType()
273  {
274  return $this->file_type;
275  }
276 
277 
281  public function setFileType($file_type)
282  {
283  $this->file_type = $file_type;
284  }
285 
286 
290  public function setAttributes($attributes)
291  {
292  $this->attributes = $attributes;
293  }
294 
295 
300  public function getAttributes()
301  {
302  return $this->attributes;
303  }
304 }
getAllEntries($object_id)
Read all entries from the database.
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.
Class ilBiblTableQueryInfo.
global $DIC
Definition: goto.php:24
Interface ilBiblFieldFactoryInterface.
Class ilBiblEntry.
Class ilBiblOverviewModelFactoryInterface.
findByIdAndTypeString($id, $type_string)
filterEntryIdsForTableAsArray($object_id, ilBiblTableQueryInfo $info=null)
getEntryById($id)
Get entry from the database.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface ilBiblEntryInterface.
$i
Definition: metadata.php:24