ILIAS  release_8 Revision v8.24
class.ilDclStandardField.php
Go to the documentation of this file.
1<?php
2
20{
22
23 public function __construct($a_id = 0)
24 {
26 global $DIC;
27 $this->main_tpl = $DIC->ui()->mainTemplate();
28 }
29
30 public function doRead(): void
31 {
32 global $DIC;
33 $ilLog = $DIC['ilLog'];
34 $message = "Standard fields cannot be read from DB";
35 $this->main_tpl->setOnScreenMessage('failure', $message);
36 $ilLog->write("[ilDclStandardField] " . $message);
37 }
38
39 public function doCreate(): void
40 {
41 global $DIC;
42 $ilLog = $DIC['ilLog'];
43 $message = "Standard fields cannot be written to DB";
44 $this->main_tpl->setOnScreenMessage('failure', $message);
45 $ilLog->write("[ilDclStandardField] " . $message);
46 }
47
48 public function doUpdate(): void
49 {
51 }
52
53 public function clone(ilDclStandardField $original_record): void
54 {
55 $this->setOrder($original_record->getOrder());
56 $this->setUnique($original_record->isUnique());
57 $this->setExportable($original_record->getExportable());
58
59 $this->doUpdate();
60 }
61
62 public function getLocked(): bool
63 {
64 return true;
65 }
66
67 public static function _getStandardFieldsAsArray(): array
68 {
69
70 //TODO: this isn't particularly pretty especially as $lng is used in the model. On the long run the standard fields should be refactored into "normal" fields.
71 global $DIC;
72 $lng = $DIC->language();
73 $stdfields = [
74 [
75 "id" => "id",
76 "title" => $lng->txt("dcl_id"),
77 "description" => $lng->txt("dcl_id_description"),
79 ],
80 [
81 "id" => "create_date",
82 "title" => $lng->txt("dcl_creation_date"),
83 "description" => $lng->txt("dcl_creation_date_description"),
85 ],
86 [
87 "id" => "last_update",
88 "title" => $lng->txt("dcl_last_update"),
89 "description" => $lng->txt("dcl_last_update_description"),
91 ],
92 [
93 "id" => "owner",
94 "title" => $lng->txt("dcl_owner"),
95 "description" => $lng->txt("dcl_owner_description"),
96 "datatype_id" => ilDclDatatype::INPUTFORMAT_TEXT
97 ],
98 [
99 "id" => "last_edit_by",
100 "title" => $lng->txt("dcl_last_edited_by"),
101 "description" => $lng->txt("dcl_last_edited_by_description"),
102 "datatype_id" => ilDclDatatype::INPUTFORMAT_TEXT
103 ],
104 [
105 'id' => 'comments',
106 'title' => $lng->txt('dcl_comments'),
107 'description' => $lng->txt('dcl_comments_desc'),
108 'datatype_id' => ilDclDatatype::INPUTFORMAT_TEXT
109 ],
110 ];
111
112 return $stdfields;
113 }
114
115 public static function _getStandardFields(int $table_id): array
116 {
117 $stdFields = array();
118 foreach (self::_getStandardFieldsAsArray() as $array) {
119 $array["table_id"] = $table_id;
120 $field = new ilDclStandardField();
121 $field->buildFromDBRecord($array);
122 $stdFields[] = $field;
123 }
124
125 return $stdFields;
126 }
127
132 public static function _getNonImportableStandardFieldTitles(): array
133 {
134 global $DIC;
135 $ilDB = $DIC['ilDB'];
136 $identifiers = '';
137 foreach (
138 array(
139 'dcl_id',
140 'dcl_creation_date',
141 'dcl_last_update',
142 'dcl_last_edited_by',
143 'dcl_comments',
144 ) as $id
145 ) {
146 $identifiers .= $ilDB->quote($id, 'text') . ',';
147 }
148 $identifiers = rtrim($identifiers, ',');
149 $sql = $ilDB->query(
150 'SELECT value FROM lng_data WHERE identifier IN (' . $identifiers
151 . ')'
152 );
153 $titles = array();
154 while ($rec = $ilDB->fetchAssoc($sql)) {
155 $titles[] = $rec['value'];
156 }
157
158 return $titles;
159 }
160
165 public static function _getImportableStandardFieldTitle(): array
166 {
167 global $DIC;
168 $ilDB = $DIC['ilDB'];
169 $identifiers = '';
170 foreach (array('dcl_owner') as $id) {
171 $identifiers .= $ilDB->quote($id, 'text') . ',';
172 }
173 $identifiers = rtrim($identifiers, ',');
174 $sql = $ilDB->query(
175 'SELECT value, identifier FROM lng_data WHERE identifier IN ('
176 . $identifiers . ')'
177 );
178 $titles = array();
179 while ($rec = $ilDB->fetchAssoc($sql)) {
180 $titles[$rec['identifier']][] = $rec['value'];
181 }
182
183 return $titles;
184 }
185
190 public static function _isStandardField($field_id): bool
191 {
192 $return = false;
193 foreach (self::_getStandardFieldsAsArray() as $field) {
194 if ($field["id"] == $field_id) {
195 $return = true;
196 }
197 }
198
199 return $return;
200 }
201
206 public static function _getDatatypeForId(string $id): ?string
207 {
208 $datatype = null;
209 foreach (self::_getStandardFieldsAsArray() as $fields_data) {
210 if ($id == $fields_data['id']) {
211 $datatype = $fields_data['datatype_id'];
212 break;
213 }
214 }
215
216 return $datatype;
217 }
218
219 public function isStandardField(): bool
220 {
221 return true;
222 }
223
224 public function isUnique(): bool
225 {
226 return false;
227 }
228
233 string $direction = "asc",
234 bool $sort_by_status = false
236 $sql_obj = new ilDclRecordQueryObject();
237
238 $join_str = "";
239 if ($this->getId() == 'owner' || $this->getId() == 'last_edit_by') {
240 $join_str = "LEFT JOIN usr_data AS sort_usr_data_{$this->getId()} ON (sort_usr_data_{$this->getId()}.usr_id = record.{$this->getId()})";
241 $select_str = " sort_usr_data_{$this->getId()}.login AS field_{$this->getId()},";
242 } else {
243 $select_str = " record.{$this->getId()} AS field_{$this->getId()},";
244 }
245
246 $sql_obj->setSelectStatement($select_str);
247 $sql_obj->setJoinStatement($join_str);
248
249 if ($this->getId() !== "comments") {
250 $sql_obj->setOrderStatement("field_{$this->getId()} " . $direction);
251 }
252
253 return $sql_obj;
254 }
255
260 $filter_value = "",
261 ?ilDclBaseFieldModel $sort_field = null
263 global $DIC;
264 $ilDB = $DIC['ilDB'];
265
266 $where_additions = "";
267 $join_str = "";
268 if ($this->getDatatypeId() == ilDclDatatype::INPUTFORMAT_TEXT) {
269 $join_str = "INNER JOIN usr_data AS filter_usr_data_{$this->getId()} ON (filter_usr_data_{$this->getId()}.usr_id = record.{$this->getId()} AND filter_usr_data_{$this->getId()}.login LIKE "
270 . $ilDB->quote("%$filter_value%", 'text') . ") ";
271 } else {
272 if ($this->getDatatypeId() == ilDclDatatype::INPUTFORMAT_NUMBER) {
273 $from = (isset($filter_value['from'])) ? $filter_value['from'] : null;
274 $to = (isset($filter_value['to'])) ? $filter_value['to'] : null;
275 if (is_numeric($from)) {
276 $where_additions .= " AND record.{$this->getId()} >= "
277 . $ilDB->quote($from, 'integer');
278 }
279 if (is_numeric($to)) {
280 $where_additions .= " AND record.{$this->getId()} <= "
281 . $ilDB->quote($to, 'integer');
282 }
283 } else {
284 if ($this->getDatatypeId() == ilDclDatatype::INPUTFORMAT_DATETIME) {
285 $date_from = (isset($filter_value['from'])
286 && is_object($filter_value['from'])) ? $filter_value['from'] : null;
287 $date_to = (isset($filter_value['to'])
288 && is_object($filter_value['to'])) ? $filter_value['to'] : null;
289
290 // db->quote(.. date) at some point invokes ilDate->_toString, which adds a <br /> to the string,
291 // that's why strip_tags is used
292 if ($date_from) {
293 $where_additions .= " AND (record.{$this->getId()} >= "
294 . strip_tags($ilDB->quote($date_from, 'date')) . ")";
295 }
296 if ($date_to) {
297 $where_additions .= " AND (record.{$this->getId()} <= "
298 . strip_tags($ilDB->quote($date_to, 'date')) . ")";
299 }
300 }
301 }
302 }
303
304 $sql_obj = new ilDclRecordQueryObject();
305 $sql_obj->setJoinStatement($join_str);
306 $sql_obj->setWhereStatement($where_additions);
307
308 return $sql_obj;
309 }
310
311 public function getSortField(): string
312 {
313 if ($this->getId() == 'comments') {
314 return 'n_comments';
315 } else {
316 return $this->getTitle();
317 }
318 }
319
320 public function hasNumericSorting(): bool
321 {
322 if ($this->getId() == 'comments') {
323 return true;
324 }
325
326 return parent::hasNumericSorting();
327 }
328
329 public function allowFilterInListView(): bool
330 {
331 //comments are filterable if they are enabled in the tables settings
332 return $this->id != 'comments'
333 || ilDclCache::getTableCache($this->getTableId())->getPublicCommentsEnabled();
334 }
335
336 public function fillHeaderExcel(ilExcel $worksheet, int &$row, int &$col): void
337 {
338 parent::fillHeaderExcel($worksheet, $row, $col);
339 if ($this->getId() == 'owner') {
340 global $DIC;
341 $lng = $DIC['lng'];
342 $worksheet->setCell($row, $col, $lng->txt("dcl_owner_name"));
343 $col++;
344 }
345 }
346
350 public function getValueFromExcel(ilExcel $excel, int $row, int $col)
351 {
352 $value = $excel->getCell($row, $col);
353 switch ($this->id) {
354 case 'owner':
355 return ilObjUser::_lookupId($value);
356 default:
357 return $value;
358 }
359 }
360
364 public function afterClone($records)
365 {
366 }
367}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
updateTableFieldSetting()
update exportable and fieldorder
static getTableCache(int $table_id=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setSelectStatement(string $selectStatement)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getRecordQuerySortObject(string $direction="asc", bool $sort_by_status=false)
Returns a query-object for building the record-loader-sql-query.
fillHeaderExcel(ilExcel $worksheet, int &$row, int &$col)
static _getStandardFields(int $table_id)
clone(ilDclStandardField $original_record)
getSortField()
Returns the sort-field id.
static _isStandardField($field_id)
getValueFromExcel(ilExcel $excel, int $row, int $col)
hasNumericSorting()
Set to true, when the sorting should be handled numerical.
static _getDatatypeForId(string $id)
gives you the datatype id of a specified standard field.
getRecordQueryFilterObject( $filter_value="", ?ilDclBaseFieldModel $sort_field=null)
Returns a query-object for building the record-loader-sql-query.
ilGlobalTemplateInterface $main_tpl
getCell(int $a_row, int $a_col)
Returns the value of a cell.
setCell(int $a_row, int $a_col, $a_value, ?string $a_datatype=null)
Set cell value.
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
static _lookupId($a_user_str)
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$lng
$message
Definition: xapiexit.php:32