ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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
4include_once './Modules/DataCollection/classes/Fields/Base/class.ilDclBaseFieldModel.php';
5include_once './Modules/DataCollection/classes/Fields/Base/class.ilDclDatatype.php';
6
19{
20 /*
21 * doRead
22 */
23 public function doRead()
24 {
25 global $DIC;
26 $ilLog = $DIC['ilLog'];
27 $message = "Standard fields cannot be read from DB";
28 ilUtil::sendFailure($message);
29 $ilLog->write("[ilDclStandardField] ".$message);
30 }
31
32 /*
33 * doCreate
34 */
35 public function doCreate()
36 {
37 global $DIC;
38 $ilLog = $DIC['ilLog'];
39 $message = "Standard fields cannot be written to DB";
40 ilUtil::sendFailure($message);
41 $ilLog->write("[ilDclStandardField] ".$message);
42 }
43
44 /*
45 * doUpdate
46 */
47 public function doUpdate()
48 {
50 }
51
52
56 public function cloneStructure($original_record) {
57 $this->setLocked($original_record->getLocked());
58 $this->setOrder($original_record->getOrder());
59 $this->setRequired($original_record->getRequired());
60 $this->setUnique($original_record->isUnique());
61 $this->setExportable($original_record->getExportable());
62
63 $this->doUpdate();
64 }
65
66 /*
67 * getLocked
68 */
69 public function getLocked()
70 {
71 return true;
72 }
73
74 /*
75 * _getStandardFieldsAsArray
76 */
77 static function _getStandardFieldsAsArray()
78 {
79
80 //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.
81 global $DIC;
82 $lng = $DIC['lng'];
83 $stdfields = array(
84 array("id"=>"id", "title" => $lng->txt("dcl_id"), "description" => $lng->txt("dcl_id_description"), "datatype_id" => ilDclDatatype::INPUTFORMAT_NUMBER, "required" => true),
85 array("id"=>"create_date", "title" => $lng->txt("dcl_creation_date"), "description" => $lng->txt("dcl_creation_date_description"), "datatype_id" => ilDclDatatype::INPUTFORMAT_DATETIME, "required" => true),
86 array("id"=>"last_update", "title" => $lng->txt("dcl_last_update"), "description" => $lng->txt("dcl_last_update_description"), "datatype_id" => ilDclDatatype::INPUTFORMAT_DATETIME, "required" => true),
87 array("id"=>"owner", "title" => $lng->txt("dcl_owner"), "description" => $lng->txt("dcl_owner_description"), "datatype_id" => ilDclDatatype::INPUTFORMAT_TEXT, "required" => true),
88 array("id"=>"last_edit_by", "title" => $lng->txt("dcl_last_edited_by"), "description" => $lng->txt("dcl_last_edited_by_description"), "datatype_id" => ilDclDatatype::INPUTFORMAT_TEXT, "required" => true),
89 array('id' => 'comments', 'title' => $lng->txt('dcl_comments'), 'description' => $lng->txt('dcl_comments_desc'), 'datatype_id' => ilDclDatatype::INPUTFORMAT_NONE, 'required' => false),
90 );
91 return $stdfields;
92 }
93
94 /*
95 * _getStandardFields
96 */
98 {
99 $stdFields = array();
100 foreach(self::_getStandardFieldsAsArray() as $array)
101 {
102 $array["table_id"] = $table_id;
103 //$array["datatype_id"] = self::_getDatatypeForId($array["id"]);
104 $field = new ilDclStandardField();
105 $field->buildFromDBRecord($array);
106 $stdFields[] = $field;
107 }
108 return $stdFields;
109 }
110
114 static function _getAllStandardFieldTitles() {
115 global $ilDB;
116 $identifiers = '';
117 foreach (array('dcl_id', 'dcl_creation_date', 'dcl_last_update', 'dcl_owner', 'dcl_last_edited_by', 'dcl_comments') as $id) {
118 $identifiers .= $ilDB->quote($id, 'text') . ',';
119 }
120 $identifiers = rtrim($identifiers, ',');
121 $sql = $ilDB->query('SELECT value FROM lng_data WHERE identifier IN (' . $identifiers . ')');
122 $titles = array();
123 while ($rec = $ilDB->fetchAssoc($sql)) {
124 $titles[] = $rec['value'];
125 }
126 return $titles;
127 }
128
129
130 /*
131 * _isStandardField
132 */
133 static function _isStandardField($field_id)
134 {
135 $return = false;
136 foreach(self::_getStandardFieldsAsArray() as $field)
137 {
138 if($field["id"] == $field_id)
139 {
140 $return = true;
141 }
142 }
143
144 return $return;
145 }
146
151 public static function _getDatatypeForId($id)
152 {
153 $datatype = null;
154 foreach (self::_getStandardFieldsAsArray() as $fields_data) {
155 if ($id == $fields_data['id']) {
156 $datatype = $fields_data['datatype_id'];
157 break;
158 }
159 }
160 return $datatype;
161 }
162
163 /*
164 * isStandardField
165 */
166 public function isStandardField()
167 {
168 return true;
169 }
170
171 /*
172 * isUnique
173 */
174 public function isUnique()
175 {
176 return false;
177 }
178
179
188 public function getRecordQuerySortObject($direction = "asc", $sort_by_status = false){
189 $sql_obj = new ilDclRecordQueryObject();
190
191 $join_str = "";
192 if ($this->getId() == 'owner' || $this->getId() == 'last_edit_by') {
193 $join_str = "LEFT JOIN usr_data AS sort_usr_data_{$this->getId()} ON (sort_usr_data_{$this->getId()}.usr_id = record.{$this->getId()})";
194 $select_str = " sort_usr_data_{$this->getId()}.login AS field_{$this->getId()},";
195 } else {
196 $select_str = " record.{$this->getId()} AS field_{$this->getId()},";
197 }
198
199 $sql_obj->setSelectStatement($select_str);
200 $sql_obj->setJoinStatement($join_str);
201
202 if($this->getId() !== "comments") {
203 $sql_obj->setOrderStatement("field_{$this->getId()} ".$direction);
204 }
205
206 return $sql_obj;
207 }
208
209
218 public function getRecordQueryFilterObject($filter_value = "", ilDclBaseFieldModel $sort_field = NULL) {
219 global $DIC;
220 $ilDB = $DIC['ilDB'];
221
222 $where_additions = "";
223 $join_str = "";
225 $join_str =
226 "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 "
227 . $ilDB->quote("%$filter_value%", 'text') . ") ";
228
229 } else if($this->getDatatypeId() == ilDclDatatype::INPUTFORMAT_NUMBER) {
230 $from = (isset($filter_value['from'])) ? $filter_value['from'] : NULL;
231 $to = (isset($filter_value['to'])) ? $filter_value['to'] : NULL;
232 if (is_numeric($from)) {
233 $where_additions .= " AND record.{$this->getId()} >= " . $ilDB->quote($from, 'integer');
234 }
235 if (is_numeric($to)) {
236 $where_additions .= " AND record.{$this->getId()} <= " . $ilDB->quote($to, 'integer');
237 }
238
239 } else if ($this->getDatatypeId() == ilDclDatatype::INPUTFORMAT_DATETIME) {
240 $date_from = (isset($filter_value['from']) && is_object($filter_value['from'])) ? $filter_value['from'] : NULL;
241 $date_to = (isset($filter_value['to']) && is_object($filter_value['to'])) ? $filter_value['to'] : NULL;
242
243 // db->quote(.. date) at some point invokes ilDate->_toString, which adds a <br /> to the string,
244 // that's why strip_tags is used
245 if ($date_from) {
246 $where_additions .= " AND (record.{$this->getId()} >= " . strip_tags($ilDB->quote($date_from, 'date')) . ")";
247 }
248 if ($date_to) {
249 $where_additions .= " AND (record.{$this->getId()} <= " . strip_tags($ilDB->quote($date_to, 'date')) . ")";
250 }
251
252 }
253
254 $sql_obj = new ilDclRecordQueryObject();
255 $sql_obj->setJoinStatement($join_str);
256 $sql_obj->setWhereStatement($where_additions);
257 return $sql_obj;
258 }
259
260
261 public function getSortField() {
262 if($this->getId() == 'comments') {
263 return 'n_comments';
264 }
265 }
266
267
268 public function hasNumericSorting() {
269 if($this->getId() == 'comments') {
270 return true;
271 }
272
273 return parent::hasNumericSorting();
274 }
275
279 public function allowFilterInListView() {
280 //comments are filterable if they are enabled in the tables settings
281 return $this->id != 'comments' || ilDclCache::getTableCache($this->getTableId())->getPublicCommentsEnabled();
282 }
283
284
288 public function afterClone($records) {
289 return; //0020762; afterClone of 'comments' leads to an error since comments has no datatype
290 }
291}
292
293?>
An exception for terminatinating execution or to throw for unit testing.
Class ilDclBaseFieldModel.
updateTableFieldSetting()
update exportable and fieldorder
setRequired($a_required)
Set Required.
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.
getRecordQueryFilterObject($filter_value="", ilDclBaseFieldModel $sort_field=NULL)
Returns a query-object for building the record-loader-sql-query.
doCreate()
Create new field.
getSortField()
Returns the sort-field id.
static _isStandardField($field_id)
cloneStructure($original_record)
hasNumericSorting()
Set to true, when the sorting should be handled numerical.
static _getStandardFields($table_id)
static _getDatatypeForId($id)
gives you the datatype id of a specified standard field.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
global $lng
Definition: privfeed.php:17
$records
Definition: simple_test.php:22
global $ilDB
global $DIC