ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilDclStandardField.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
16{
17 public function doRead()
18 {
19 global $DIC;
20 $ilLog = $DIC['ilLog'];
21 $message = "Standard fields cannot be read from DB";
23 $ilLog->write("[ilDclStandardField] " . $message);
24 }
25
26
27 public function doCreate()
28 {
29 global $DIC;
30 $ilLog = $DIC['ilLog'];
31 $message = "Standard fields cannot be written to DB";
33 $ilLog->write("[ilDclStandardField] " . $message);
34 }
35
36
37 public function doUpdate()
38 {
40 }
41
42
46 public function cloneStructure($original_record)
47 {
48 $this->setOrder($original_record->getOrder());
49 $this->setUnique($original_record->isUnique());
50 $this->setExportable($original_record->getExportable());
51
52 $this->doUpdate();
53 }
54
55
59 public function getLocked()
60 {
61 return true;
62 }
63
64
68 public static function _getStandardFieldsAsArray()
69 {
70
71 //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.
72 global $DIC;
73 $lng = $DIC['lng'];
74 $stdfields = array(
75 array(
76 "id" => "id",
77 "title" => $lng->txt("dcl_id"),
78 "description" => $lng->txt("dcl_id_description"),
80 ),
81 array(
82 "id" => "create_date",
83 "title" => $lng->txt("dcl_creation_date"),
84 "description" => $lng->txt("dcl_creation_date_description"),
86 ),
87 array(
88 "id" => "last_update",
89 "title" => $lng->txt("dcl_last_update"),
90 "description" => $lng->txt("dcl_last_update_description"),
92 ),
93 array(
94 "id" => "owner",
95 "title" => $lng->txt("dcl_owner"),
96 "description" => $lng->txt("dcl_owner_description"),
97 "datatype_id" => ilDclDatatype::INPUTFORMAT_TEXT
98 ),
99 array(
100 "id" => "last_edit_by",
101 "title" => $lng->txt("dcl_last_edited_by"),
102 "description" => $lng->txt("dcl_last_edited_by_description"),
103 "datatype_id" => ilDclDatatype::INPUTFORMAT_TEXT
104 ),
105 array(
106 'id' => 'comments',
107 'title' => $lng->txt('dcl_comments'),
108 'description' => $lng->txt('dcl_comments_desc'),
109 'datatype_id' => ilDclDatatype::INPUTFORMAT_NONE
110 ),
111 );
112
113 return $stdfields;
114 }
115
116
122 public static function _getStandardFields($table_id)
123 {
124 $stdFields = array();
125 foreach (self::_getStandardFieldsAsArray() as $array) {
126 $array["table_id"] = $table_id;
127 //$array["datatype_id"] = self::_getDatatypeForId($array["id"]);
128 $field = new ilDclStandardField();
129 $field->buildFromDBRecord($array);
130 $stdFields[] = $field;
131 }
132
133 return $stdFields;
134 }
135
136
142 {
143 global $DIC;
144 $ilDB = $DIC['ilDB'];
145 $identifiers = '';
146 foreach (
147 array(
148 'dcl_id',
149 'dcl_creation_date',
150 'dcl_last_update',
151 'dcl_last_edited_by',
152 'dcl_comments',
153 ) as $id
154 ) {
155 $identifiers .= $ilDB->quote($id, 'text') . ',';
156 }
157 $identifiers = rtrim($identifiers, ',');
158 $sql = $ilDB->query(
159 'SELECT value FROM lng_data WHERE identifier IN (' . $identifiers
160 . ')'
161 );
162 $titles = array();
163 while ($rec = $ilDB->fetchAssoc($sql)) {
164 $titles[] = $rec['value'];
165 }
166
167 return $titles;
168 }
169
170
175 public static function _getImportableStandardFieldTitle()
176 {
177 global $DIC;
178 $ilDB = $DIC['ilDB'];
179 $identifiers = '';
180 foreach (array('dcl_owner') as $id) {
181 $identifiers .= $ilDB->quote($id, 'text') . ',';
182 }
183 $identifiers = rtrim($identifiers, ',');
184 $sql = $ilDB->query(
185 'SELECT value, identifier FROM lng_data WHERE identifier IN ('
186 . $identifiers . ')'
187 );
188 $titles = array();
189 while ($rec = $ilDB->fetchAssoc($sql)) {
190 $titles[$rec['identifier']][] = $rec['value'];
191 }
192
193 return $titles;
194 }
195
196
202 public static function _isStandardField($field_id)
203 {
204 $return = false;
205 foreach (self::_getStandardFieldsAsArray() as $field) {
206 if ($field["id"] == $field_id) {
207 $return = true;
208 }
209 }
210
211 return $return;
212 }
213
214
222 public static function _getDatatypeForId($id)
223 {
224 $datatype = null;
225 foreach (self::_getStandardFieldsAsArray() as $fields_data) {
226 if ($id == $fields_data['id']) {
227 $datatype = $fields_data['datatype_id'];
228 break;
229 }
230 }
231
232 return $datatype;
233 }
234
235
239 public function isStandardField()
240 {
241 return true;
242 }
243
244
248 public function isUnique()
249 {
250 return false;
251 }
252
253
262 public function getRecordQuerySortObject($direction = "asc", $sort_by_status = false)
263 {
264 $sql_obj = new ilDclRecordQueryObject();
265
266 $join_str = "";
267 if ($this->getId() == 'owner' || $this->getId() == 'last_edit_by') {
268 $join_str = "LEFT JOIN usr_data AS sort_usr_data_{$this->getId()} ON (sort_usr_data_{$this->getId()}.usr_id = record.{$this->getId()})";
269 $select_str = " sort_usr_data_{$this->getId()}.login AS field_{$this->getId()},";
270 } else {
271 $select_str = " record.{$this->getId()} AS field_{$this->getId()},";
272 }
273
274 $sql_obj->setSelectStatement($select_str);
275 $sql_obj->setJoinStatement($join_str);
276
277 if ($this->getId() !== "comments") {
278 $sql_obj->setOrderStatement("field_{$this->getId()} " . $direction);
279 }
280
281 return $sql_obj;
282 }
283
284
293 public function getRecordQueryFilterObject($filter_value = "", ilDclBaseFieldModel $sort_field = null)
294 {
295 global $DIC;
296 $ilDB = $DIC['ilDB'];
297
298 $where_additions = "";
299 $join_str = "";
301 $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 "
302 . $ilDB->quote("%$filter_value%", 'text') . ") ";
303 } else {
305 $from = (isset($filter_value['from'])) ? $filter_value['from'] : null;
306 $to = (isset($filter_value['to'])) ? $filter_value['to'] : null;
307 if (is_numeric($from)) {
308 $where_additions .= " AND record.{$this->getId()} >= "
309 . $ilDB->quote($from, 'integer');
310 }
311 if (is_numeric($to)) {
312 $where_additions .= " AND record.{$this->getId()} <= "
313 . $ilDB->quote($to, 'integer');
314 }
315 } else {
317 $date_from = (isset($filter_value['from'])
318 && is_object($filter_value['from'])) ? $filter_value['from'] : null;
319 $date_to = (isset($filter_value['to'])
320 && is_object($filter_value['to'])) ? $filter_value['to'] : null;
321
322 // db->quote(.. date) at some point invokes ilDate->_toString, which adds a <br /> to the string,
323 // that's why strip_tags is used
324 if ($date_from) {
325 $where_additions .= " AND (record.{$this->getId()} >= "
326 . strip_tags($ilDB->quote($date_from, 'date')) . ")";
327 }
328 if ($date_to) {
329 $where_additions .= " AND (record.{$this->getId()} <= "
330 . strip_tags($ilDB->quote($date_to, 'date')) . ")";
331 }
332 }
333 }
334 }
335
336 $sql_obj = new ilDclRecordQueryObject();
337 $sql_obj->setJoinStatement($join_str);
338 $sql_obj->setWhereStatement($where_additions);
339
340 return $sql_obj;
341 }
342
343
347 public function getSortField()
348 {
349 if ($this->getId() == 'comments') {
350 return 'n_comments';
351 } else {
352 return $this->getTitle();
353 }
354 }
355
356
360 public function hasNumericSorting()
361 {
362 if ($this->getId() == 'comments') {
363 return true;
364 }
365
366 return parent::hasNumericSorting();
367 }
368
369
373 public function allowFilterInListView()
374 {
375 //comments are filterable if they are enabled in the tables settings
376 return $this->id != 'comments'
377 || ilDclCache::getTableCache($this->getTableId())->getPublicCommentsEnabled();
378 }
379
380
386 public function fillHeaderExcel(ilExcel $worksheet, &$row, &$col)
387 {
388 parent::fillHeaderExcel($worksheet, $row, $col);
389 if ($this->getId() == 'owner') {
390 global $DIC;
391 $lng = $DIC['lng'];
392 $worksheet->setCell($row, $col, $lng->txt("dcl_owner_name"));
393 $col++;
394 }
395 }
396
397
405 public function getValueFromExcel($excel, $row, $col)
406 {
407 $value = $excel->getCell($row, $col);
408 switch ($this->id) {
409 case 'owner':
410 return ilObjUser::_lookupId($value);
411 default:
412 return $value;
413 }
414 }
415
416
420 public function afterClone($records)
421 {
422 }
423}
An exception for terminatinating execution or to throw for unit testing.
Class ilDclBaseFieldModel.
updateTableFieldSetting()
update exportable and fieldorder
static getTableCache($table_id=0)
Class ilDclRecordQueryObject.
Class ilDclBaseFieldModel.
getRecordQuerySortObject($direction="asc", $sort_by_status=false)
Returns a query-object for building the record-loader-sql-query.
fillHeaderExcel(ilExcel $worksheet, &$row, &$col)
doCreate()
Create new field.
getValueFromExcel($excel, $row, $col)
static _isStandardField($field_id)
cloneStructure($original_record)
getRecordQueryFilterObject($filter_value="", ilDclBaseFieldModel $sort_field=null)
Returns a query-object for building the record-loader-sql-query.
static _getStandardFields($table_id)
static _getDatatypeForId($id)
gives you the datatype id of a specified standard field.
setCell($a_row, $a_col, $a_value, $a_datatype=null)
Set cell value.
static _lookupId($a_user_str)
Lookup id by login.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
global $DIC
Definition: goto.php:24
$lng
global $ilDB
$message
Definition: xapiexit.php:14