ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilBiblEntryFactory.php
Go to the documentation of this file.
1<?php
2
24{
25 use ilBibliographicSecureString;
26
27 protected int $bibliographic_obj_id;
28 protected int $entry_id;
29 protected string $type;
30 protected array $attributes;
31 protected ilDBInterface $db;
32
33
37 public function __construct(protected \ilBiblFieldFactoryInterface $field_factory, protected \ilBiblTypeInterface $file_type, protected \ilBiblOverviewModelFactoryInterface $overview_factory)
38 {
39 global $DIC;
40 $this->db = $DIC->database();
41 }
42
46 public function loadParsedAttributesByEntryId(int $entry_id): array
47 {
48 $ilBiblEntry = ilBiblEntry::where(['id' => $entry_id])->first();
49 $attributes = $this->getAllAttributesByEntryId($entry_id);
50
51 $type = $this->file_type->getId() == ilBiblTypeFactoryInterface::DATA_TYPE_RIS ? $ilBiblEntry->getType() : 'default';
52 $parsed_attributes = [];
53 foreach ($attributes as $attribute) {
54 $value = $this->secure($attribute->getValue());
55 // surround links with <a href="">
56 // Allowed signs in URL: a-z A-Z 0-9 . ? & _ / - ~ ! ' * ( ) + , : ; @ = $ # [ ] %
57 $value = preg_replace('!(http)(s)?:\/\/[a-zA-Z0-9.?&_/\-~\!\'\*()+,:;@=$#\[\]%]+!', "<a href=\"\\0\" target=\"_blank\">\\0</a>", $value);
58
59
60
61 $attribute->setValue($value);
62 $parsed_attributes[strtolower($this->file_type->getStringRepresentation() . '_' . $type . '_' . $attribute->getName())] = $value;
63
64 $this->field_factory->findOrCreateFieldOfAttribute($attribute);
65 }
66
67 return $parsed_attributes;
68 }
69
73 public function findByIdAndTypeString(int $id, string $type_string): ilBiblEntryInterface
74 {
76 return ilBiblEntry::where(['id' => $id])->first();
77 }
78
82 public function findOrCreateEntry(int $id, int $bibliographic_obj_id, string $entry_type): \ilBiblEntryInterface
83 {
84 $inst = $this->getARInstance($id);
85 if ($inst === null) {
86 $inst = $this->createEntry($bibliographic_obj_id, $entry_type);
87 }
88 $inst->setDataId($bibliographic_obj_id);
89 $inst->setEntryType($entry_type);
90 $inst->update();
91
92 return $inst;
93 }
94
98 public function createEntry(int $bibliographic_obj_id, string $entry_type): \ilBiblEntryInterface
99 {
100 $inst = new ilBiblEntry();
101 $inst->setDataId($bibliographic_obj_id);
102 $inst->setEntryType($entry_type);
103 $inst->create();
104
105 return $inst;
106 }
107
108 public function getEmptyInstance(): \ilBiblEntry
109 {
110 return new ilBiblEntry();
111 }
112
113 private function getARInstance(int $id): ?\ilBiblEntry
114 {
116 return ilBiblEntry::where(["ïd" => $id])->first();
117 }
118
122 public function filterEntriesForTable(int $object_id, ?ilBiblTableQueryInfo $info = null): array
123 {
124 $entries = $this->filterEntryIdsForTableAsArray($object_id, $info);
125 $entry_objects = [];
126 foreach ($entries as $entry_id => $entry) {
127 $entry_objects[$entry_id] = $this->findByIdAndTypeString($entry['type'], $entry['id']);
128 }
129
130 return $entry_objects;
131 }
132
136 public function filterEntryIdsForTableAsArray(int $object_id, ?ilBiblTableQueryInfo $info = null): array
137 {
138 $types = ["integer"];
139 $values = [$object_id];
140
141 $filters = $info->getFilters();
142 if (!empty($filters)) {
143 $q = "SELECT (e.id), e.type FROM il_bibl_entry AS e WHERE data_id = %s";
144 foreach ($filters as $filter) {
145 $value = $filter->getFieldValue();
146 if (!$value) {
147 continue;
148 }
149 if ($filter->getOperator() === "IN" && is_array($filter->getFieldValue())) {
150 $types[] = "text";
151 $values[] = $filter->getFieldName();
152 $q .= " AND e.id IN (SELECT a.entry_id FROM il_bibl_attribute AS a WHERE a.name = %s AND " . $this->db->in("a.value", $value, false, "text") . ")";
153 } else {
154 $types[] = "text";
155 $values[] = $filter->getFieldName();
156 $types[] = "text";
157 $values[] = "{$value}";
158 $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 )";
159 }
160 }
161 } else {
162 $q = "SELECT DISTINCT (e.id), e.type FROM il_bibl_entry AS e
163 JOIN il_bibl_attribute AS a ON a.entry_id = e.id
164 WHERE data_id = %s";
165 }
166 $entries = [];
167 $set = $this->db->queryF($q, $types, $values);
168
169 $i = 0;
170 while ($rec = $this->db->fetchAssoc($set)) {
171 $entries[$i]['entry_id'] = $rec['id'];
172 $entries[$i]['entry_type'] = $rec['type'];
173 $i++;
174 }
175
176 return $entries;
177 }
178
179 public function deleteEntryById(int $id): void
180 {
181 $entry = ilBiblEntry::where(['id' => $id])->first();
182 if ($entry instanceof ilBiblEntry) {
183 $entry->delete();
184 }
185 }
186
187 public function deleteEntriesById(int $object_id): void
188 {
189 $this->db->manipulateF("DELETE FROM il_bibl_entry WHERE data_id = %s", ['integer'], [$object_id]);
190 }
191
195 public function getAllAttributesByEntryId(int $id): array
196 {
197 return ilBiblAttribute::where(['entry_id' => $id])->get();
198 }
199
201 {
202 return $this->file_type;
203 }
204
205 public function setFileType(string $file_type): void
206 {
207 $this->file_type = $file_type;
208 }
209
213 public function setAttributes(array $attributes): void
214 {
215 $this->attributes = $attributes;
216 }
217
222 public function getAttributes(): array
223 {
224 return $this->attributes;
225 }
226}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
static where($where, $operator=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
createEntry(int $bibliographic_obj_id, string $entry_type)
@inheritDoc
filterEntryIdsForTableAsArray(int $object_id, ?ilBiblTableQueryInfo $info=null)
@inheritDoc
filterEntriesForTable(int $object_id, ?ilBiblTableQueryInfo $info=null)
setAttributes(array $attributes)
findOrCreateEntry(int $id, int $bibliographic_obj_id, string $entry_type)
@inheritDoc
loadParsedAttributesByEntryId(int $entry_id)
@inheritDoc
findByIdAndTypeString(int $id, string $type_string)
@inheritDoc
setFileType(string $file_type)
__construct(protected \ilBiblFieldFactoryInterface $field_factory, protected \ilBiblTypeInterface $file_type, protected \ilBiblOverviewModelFactoryInterface $overview_factory)
ilBiblEntryFactory constructor.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$info
Definition: entry_point.php:21
Interface ilBiblEntryFactoryInterface.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface ilDBInterface.
global $DIC
Definition: shib_login.php:26
$q
Definition: shib_logout.php:23