ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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  {
39  $this->updateTableFieldSetting();
40  }
41 
42 
46  public function cloneStructure($original_record)
47  {
48  $this->setLocked($original_record->getLocked());
49  $this->setOrder($original_record->getOrder());
50  $this->setRequired($original_record->getRequired());
51  $this->setUnique($original_record->isUnique());
52  $this->setExportable($original_record->getExportable());
53 
54  $this->doUpdate();
55  }
56 
57 
61  public function getLocked()
62  {
63  return true;
64  }
65 
66 
70  public static function _getStandardFieldsAsArray()
71  {
72 
73  //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.
74  global $DIC;
75  $lng = $DIC['lng'];
76  $stdfields = array(
77  array(
78  "id" => "id",
79  "title" => $lng->txt("dcl_id"),
80  "description" => $lng->txt("dcl_id_description"),
81  "datatype_id" => ilDclDatatype::INPUTFORMAT_NUMBER,
82  "required" => true,
83  ),
84  array(
85  "id" => "create_date",
86  "title" => $lng->txt("dcl_creation_date"),
87  "description" => $lng->txt("dcl_creation_date_description"),
88  "datatype_id" => ilDclDatatype::INPUTFORMAT_DATETIME,
89  "required" => true,
90  ),
91  array(
92  "id" => "last_update",
93  "title" => $lng->txt("dcl_last_update"),
94  "description" => $lng->txt("dcl_last_update_description"),
95  "datatype_id" => ilDclDatatype::INPUTFORMAT_DATETIME,
96  "required" => true,
97  ),
98  array(
99  "id" => "owner",
100  "title" => $lng->txt("dcl_owner"),
101  "description" => $lng->txt("dcl_owner_description"),
102  "datatype_id" => ilDclDatatype::INPUTFORMAT_TEXT,
103  "required" => true,
104  ),
105  array(
106  "id" => "last_edit_by",
107  "title" => $lng->txt("dcl_last_edited_by"),
108  "description" => $lng->txt("dcl_last_edited_by_description"),
109  "datatype_id" => ilDclDatatype::INPUTFORMAT_TEXT,
110  "required" => true,
111  ),
112  array(
113  'id' => 'comments',
114  'title' => $lng->txt('dcl_comments'),
115  'description' => $lng->txt('dcl_comments_desc'),
116  'datatype_id' => ilDclDatatype::INPUTFORMAT_NONE,
117  'required' => false,
118  ),
119  );
120 
121  return $stdfields;
122  }
123 
124 
130  public static function _getStandardFields($table_id)
131  {
132  $stdFields = array();
133  foreach (self::_getStandardFieldsAsArray() as $array) {
134  $array["table_id"] = $table_id;
135  //$array["datatype_id"] = self::_getDatatypeForId($array["id"]);
136  $field = new ilDclStandardField();
137  $field->buildFromDBRecord($array);
138  $stdFields[] = $field;
139  }
140 
141  return $stdFields;
142  }
143 
144 
149  public static function _getNonImportableStandardFieldTitles()
150  {
151  global $DIC;
152  $ilDB = $DIC['ilDB'];
153  $identifiers = '';
154  foreach (array(
155  'dcl_id',
156  'dcl_creation_date',
157  'dcl_last_update',
158  'dcl_last_edited_by',
159  'dcl_comments',
160  ) as $id) {
161  $identifiers .= $ilDB->quote($id, 'text') . ',';
162  }
163  $identifiers = rtrim($identifiers, ',');
164  $sql = $ilDB->query('SELECT value FROM lng_data WHERE identifier IN (' . $identifiers
165  . ')');
166  $titles = array();
167  while ($rec = $ilDB->fetchAssoc($sql)) {
168  $titles[] = $rec['value'];
169  }
170 
171  return $titles;
172  }
173 
174 
179  public static function _getImportableStandardFieldTitle()
180  {
181  global $DIC;
182  $ilDB = $DIC['ilDB'];
183  $identifiers = '';
184  foreach (array( 'dcl_owner' ) as $id) {
185  $identifiers .= $ilDB->quote($id, 'text') . ',';
186  }
187  $identifiers = rtrim($identifiers, ',');
188  $sql = $ilDB->query('SELECT value, identifier FROM lng_data WHERE identifier IN ('
189  . $identifiers . ')');
190  $titles = array();
191  while ($rec = $ilDB->fetchAssoc($sql)) {
192  $titles[$rec['identifier']][] = $rec['value'];
193  }
194 
195  return $titles;
196  }
197 
198 
204  public static function _isStandardField($field_id)
205  {
206  $return = false;
207  foreach (self::_getStandardFieldsAsArray() as $field) {
208  if ($field["id"] == $field_id) {
209  $return = true;
210  }
211  }
212 
213  return $return;
214  }
215 
216 
224  public static function _getDatatypeForId($id)
225  {
226  $datatype = null;
227  foreach (self::_getStandardFieldsAsArray() as $fields_data) {
228  if ($id == $fields_data['id']) {
229  $datatype = $fields_data['datatype_id'];
230  break;
231  }
232  }
233 
234  return $datatype;
235  }
236 
237 
241  public function isStandardField()
242  {
243  return true;
244  }
245 
246 
250  public function isUnique()
251  {
252  return false;
253  }
254 
255 
264  public function getRecordQuerySortObject($direction = "asc", $sort_by_status = false)
265  {
266  $sql_obj = new ilDclRecordQueryObject();
267 
268  $join_str = "";
269  if ($this->getId() == 'owner' || $this->getId() == 'last_edit_by') {
270  $join_str = "LEFT JOIN usr_data AS sort_usr_data_{$this->getId()} ON (sort_usr_data_{$this->getId()}.usr_id = record.{$this->getId()})";
271  $select_str = " sort_usr_data_{$this->getId()}.login AS field_{$this->getId()},";
272  } else {
273  $select_str = " record.{$this->getId()} AS field_{$this->getId()},";
274  }
275 
276  $sql_obj->setSelectStatement($select_str);
277  $sql_obj->setJoinStatement($join_str);
278 
279  if ($this->getId() !== "comments") {
280  $sql_obj->setOrderStatement("field_{$this->getId()} " . $direction);
281  }
282 
283  return $sql_obj;
284  }
285 
286 
295  public function getRecordQueryFilterObject($filter_value = "", ilDclBaseFieldModel $sort_field = null)
296  {
297  global $DIC;
298  $ilDB = $DIC['ilDB'];
299 
300  $where_additions = "";
301  $join_str = "";
303  $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 "
304  . $ilDB->quote("%$filter_value%", 'text') . ") ";
305  } else {
307  $from = (isset($filter_value['from'])) ? $filter_value['from'] : null;
308  $to = (isset($filter_value['to'])) ? $filter_value['to'] : null;
309  if (is_numeric($from)) {
310  $where_additions .= " AND record.{$this->getId()} >= "
311  . $ilDB->quote($from, 'integer');
312  }
313  if (is_numeric($to)) {
314  $where_additions .= " AND record.{$this->getId()} <= "
315  . $ilDB->quote($to, 'integer');
316  }
317  } else {
319  $date_from = (isset($filter_value['from'])
320  && is_object($filter_value['from'])) ? $filter_value['from'] : null;
321  $date_to = (isset($filter_value['to'])
322  && is_object($filter_value['to'])) ? $filter_value['to'] : null;
323 
324  // db->quote(.. date) at some point invokes ilDate->_toString, which adds a <br /> to the string,
325  // that's why strip_tags is used
326  if ($date_from) {
327  $where_additions .= " AND (record.{$this->getId()} >= "
328  . strip_tags($ilDB->quote($date_from, 'date')) . ")";
329  }
330  if ($date_to) {
331  $where_additions .= " AND (record.{$this->getId()} <= "
332  . strip_tags($ilDB->quote($date_to, 'date')) . ")";
333  }
334  }
335  }
336  }
337 
338  $sql_obj = new ilDclRecordQueryObject();
339  $sql_obj->setJoinStatement($join_str);
340  $sql_obj->setWhereStatement($where_additions);
341 
342  return $sql_obj;
343  }
344 
345 
349  public function getSortField()
350  {
351  if ($this->getId() == 'comments') {
352  return 'n_comments';
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 }
getRecordQuerySortObject($direction="asc", $sort_by_status=false)
Returns a query-object for building the record-loader-sql-query.
Class ilDclBaseFieldModel.
$worksheet
getRecordQueryFilterObject($filter_value="", ilDclBaseFieldModel $sort_field=null)
Returns a query-object for building the record-loader-sql-query.
Class ilDclRecordQueryObject.
global $DIC
Definition: saml.php:7
static _lookupId($a_user_str)
Lookup id by login.
cloneStructure($original_record)
$from
$records
Definition: simple_test.php:22
static getTableCache($table_id=0)
static _getDatatypeForId($id)
gives you the datatype id of a specified standard field.
static _getStandardFields($table_id)
catch(Exception $e) $message
setRequired($a_required)
Set Required.
setCell($a_row, $a_col, $a_value, $a_datatype=null)
Set cell value.
Class ilDclBaseFieldModel.
fillHeaderExcel(ilExcel $worksheet, &$row, &$col)
static _isStandardField($field_id)
Create styles array
The data for the language used.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
updateTableFieldSetting()
update exportable and fieldorder
global $lng
Definition: privfeed.php:17
global $ilDB
getValueFromExcel($excel, $row, $col)
getDatatypeId()
Get datatype_id.