ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilDclTextFieldModel.php
Go to the documentation of this file.
1<?php
2
10{
11
15 public function getRecordQueryFilterObject($filter_value = "", ilDclBaseFieldModel $sort_field = null)
16 {
17 global $DIC;
18 $ilDB = $DIC['ilDB'];
19
20 $join_str
21 = "INNER JOIN il_dcl_record_field AS filter_record_field_{$this->getId()} ON (filter_record_field_{$this->getId()}.record_id = record.id AND filter_record_field_{$this->getId()}.field_id = "
22 . $ilDB->quote($this->getId(), 'integer') . ") ";
23 $join_str .= "INNER JOIN il_dcl_stloc{$this->getStorageLocation()}_value AS filter_stloc_{$this->getId()} ON (filter_stloc_{$this->getId()}.record_field_id = filter_record_field_{$this->getId()}.id AND filter_stloc_{$this->getId()}.value LIKE "
24 . $ilDB->quote("%$filter_value%", 'text') . ") ";
25
26 $sql_obj = new ilDclRecordQueryObject();
27 $sql_obj->setJoinStatement($join_str);
28
29 return $sql_obj;
30 }
31
32
36 public function getRecordQuerySortObject($direction = "asc", $sort_by_status = false)
37 {
38 // use custom record sorting for url-fields
40 return new ilDclTextRecordQueryObject();
41 } else {
42 return parent::getRecordQuerySortObject($direction, $sort_by_status);
43 }
44 }
45
46
51 public function checkValidityFromForm(ilPropertyFormGUI &$form, $record_id = null)
52 {
53 $has_url_property = $this->getProperty(ilDclBaseFieldModel::PROP_URL);
54 if ($has_url_property) {
55 $values = array(
56 'link' => $form->getInput("field_" . $this->getId()),
57 'title' => $form->getInput("field_" . $this->getId() . "_title"),
58 );
59 $this->checkValidityOfURLField($values, $record_id);
60 } else {
61 parent::checkValidityFromForm($form, $record_id);
62 }
63 }
64
65
69 public function checkValidity($value, $record_id = null)
70 {
71 $has_url_property = $this->getProperty(ilDclBaseFieldModel::PROP_URL);
72 if ($has_url_property) {
73 return $this->checkValidityOfURLField($value, $record_id);
74 }
75
76 //Don't check empty values
77 if ($value == null) {
78 return true;
79 }
80
81 $this->checkRegexAndLength($value);
82
83 if ($this->isUnique()) {
84 $table = ilDclCache::getTableCache($this->getTableId());
85 foreach ($table->getRecords() as $record) {
86 //for text it has to be case insensitive.
87 $record_value = $record->getRecordFieldValue($this->getId());
88
89 if (strtolower($this->normalizeValue($record_value)) == strtolower($this->normalizeValue(nl2br($value)))
90 && ($record->getId() != $record_id
91 || $record_id == 0)
92 ) {
94 }
95 }
96 }
97 }
98
99
107 protected function checkValidityOfURLField($value, $record_id)
108 {
109 // TODO: value should always be an array with url fields, can we remove the check & json_decode?
110 if (!is_array($value)) {
111 $value = array('link' => $value, 'title' => '');
112 }
113
114 //Don't check empty values
115 if (!$value['link']) {
116 return true;
117 }
118
119 $this->checkRegexAndLength($value['link']);
120
121 //check url/email
122 $link = (substr($value['link'], 0, 3) === 'www') ? 'http://' . $value['link'] : $value['link'];
123 if (!filter_var($link, FILTER_VALIDATE_URL) && !filter_var($link, FILTER_VALIDATE_EMAIL) && $link != '') {
125 }
126
127 if ($this->isUnique()) {
128 $table = ilDclCache::getTableCache($this->getTableId());
129 foreach ($table->getRecords() as $record) {
130 $record_value = $record->getRecordFieldValue($this->getId());
131
132 if ($record_value == $value
133 && ($record->getId() != $record_id
134 || $record_id == 0)
135 ) {
137 }
138 }
139 }
140 }
141
142
147 {
148 global $DIC;
149 $lng = $DIC['lng'];
150
151 $return = true;
152 // Additional check for text fields: The length property should be max 200 if the textarea option is not set
153 if ((int) $form->getInput('prop_' . ilDclBaseFieldModel::PROP_LENGTH) > 200 && !$form->getInput('prop_' . ilDclBaseFieldModel::PROP_TEXTAREA)) {
154 $inputObj = $form->getItemByPostVar('prop_' . ilDclBaseFieldModel::PROP_LENGTH);
155 $inputObj->setAlert($lng->txt("form_msg_value_too_high"));
156 $return = false;
157 }
158
159 return $return;
160 }
161
162
166 public function getValidFieldProperties()
167 {
168 return array(
174 );
175 }
176
177
183 protected function checkRegexAndLength($value)
184 {
186 if (substr($regex, 0, 1) != "/") {
187 $regex = "/" . $regex;
188 }
189 if (substr($regex, -1) != "/") {
190 $regex .= "/";
191 }
192
193 if ($this->getProperty(ilDclBaseFieldModel::PROP_LENGTH) < $this->strlen($value, 'UTF-8')
194 && is_numeric($this->getProperty(ilDclBaseFieldModel::PROP_LENGTH))
195 ) {
197 }
198
199 if ($this->getProperty(ilDclBaseFieldModel::PROP_REGEX) != null) {
200 try {
201 $preg_match = preg_match($regex, $value);
202 } catch (ErrorException $e) {
204 }
205
206 if ($preg_match == false) {
208 }
209 }
210 }
211
212
219 public function strlen($value, $encoding = 'UTF-8')
220 {
221 switch (true) {
222 case function_exists('mb_strlen'):
223 return mb_strlen($value, $encoding);
224 case function_exists('iconv_strlen'):
225 return iconv_strlen($value, $encoding);
226 default:
227 return strlen($value);
228 }
229 }
230
231
232 public function fillHeaderExcel(ilExcel $worksheet, &$row, &$col)
233 {
234 parent::fillHeaderExcel($worksheet, $row, $col);
236 $worksheet->setCell($row, $col, $this->getTitle() . '_title');
237 $col++;
238 }
239 }
240
241
246 public function checkTitlesForImport(array &$titles, array &$import_fields)
247 {
248 foreach ($titles as $k => $title) {
249 if (!ilStr::isUtf8($title)) {
250 $title = utf8_encode($title);
251 }
252 if ($title == $this->getTitle()) {
253 $import_fields[$k] = $this;
254 if ($this->hasProperty(ilDclBaseFieldModel::PROP_URL) && $titles[$k + 1] == $this->getTitle() . '_title') {
255 unset($titles[$k + 1]);
256 }
257 }
258 }
259 }
260}
An exception for terminatinating execution or to throw for unit testing.
Class ilDclBaseFieldModel.
hasProperty($key)
Checks if a certain property for a field is set.
getProperty($key)
Returns a certain property of a field.
const PROP_LENGTH
General properties.
static getTableCache($table_id=0)
Class ilDclBaseFieldModel.
Class ilDclRecordQueryObject.
Class ilDclTextFieldModel.
checkTitlesForImport(array &$titles, array &$import_fields)
checkValidityFromForm(ilPropertyFormGUI &$form, $record_id=null)
checkValidity($value, $record_id=null)
Check if input is valid.bool
checkValidityOfURLField($value, $record_id)
strlen($value, $encoding='UTF-8')
fillHeaderExcel(ilExcel $worksheet, &$row, &$col)
getRecordQueryFilterObject($filter_value="", ilDclBaseFieldModel $sort_field=null)
Returns a query-object for building the record-loader-sql-query.null|ilDclRecordQueryObject
checkFieldCreationInput(ilPropertyFormGUI $form)
@inheritDoc
getRecordQuerySortObject($direction="asc", $sort_by_status=false)
Returns a query-object for building the record-loader-sql-query.null|ilDclRecordQueryObject
Class ilDclTextRecordQueryObject.
setCell($a_row, $a_col, $a_value, $a_datatype=null)
Set cell value.
This class represents a property form user interface.
getInput($a_post_var, $ensureValidation=true)
Returns the value of a HTTP-POST variable, identified by the passed id.
getItemByPostVar($a_post_var)
Get Item by POST variable.
static isUtf8($a_str)
Check whether string is utf-8.
$lng
global $ilDB
$DIC
Definition: xapitoken.php:46