ILIAS  release_8 Revision v8.24
class.ilDclTextFieldModel.php
Go to the documentation of this file.
1<?php
2
20{
25 $filter_value = "",
26 ?ilDclBaseFieldModel $sort_field = null
28 $join_str
29 = "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 = "
30 . $this->db->quote($this->getId(), 'integer') . ") ";
31 $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 "
32 . $this->db->quote("%$filter_value%", 'text') . ") ";
33
34 $sql_obj = new ilDclRecordQueryObject();
35 $sql_obj->setJoinStatement($join_str);
36
37 return $sql_obj;
38 }
39
40 public function getRecordQuerySortObject(
41 string $direction = "asc",
42 bool $sort_by_status = false
44 // use custom record sorting for url-fields
45 if ($this->hasProperty(ilDclBaseFieldModel::PROP_URL)) {
46 return new ilDclTextRecordQueryObject();
47 } else {
48 return parent::getRecordQuerySortObject($direction, $sort_by_status);
49 }
50 }
51
52 public function checkValidityFromForm(ilPropertyFormGUI &$form, ?int $record_id = null): void
53 {
54 $has_url_property = $this->getProperty(ilDclBaseFieldModel::PROP_URL);
55 if ($has_url_property) {
56 $values = [
57 'link' => $form->getInput("field_" . $this->getId()),
58 'title' => $form->getInput("field_" . $this->getId() . "_title"),
59 ];
60 $this->checkValidityOfURLField($values, $record_id);
61 } else {
62 parent::checkValidityFromForm($form, $record_id);
63 }
64 }
65
70 public function checkValidity($value, ?int $record_id = null): bool
71 {
72 $has_url_property = $this->getProperty(ilDclBaseFieldModel::PROP_URL);
73 if ($has_url_property) {
74 return $this->checkValidityOfURLField($value, $record_id);
75 }
76
77 // Don't check empty values
78 if ($value === null) {
79 return true;
80 }
81
82 $this->checkRegexAndLength($value);
83
84 if ($this->isUnique()) {
85 $table = ilDclCache::getTableCache($this->getTableId());
86 foreach ($table->getRecords() as $record) {
87 //for text it has to be case insensitive.
88 $record_value = $record->getRecordFieldValue($this->getId());
89
90 if (strtolower($this->normalizeValue($record_value)) == strtolower($this->normalizeValue($value))
91 && ($record->getId() != $record_id
92 || $record_id == 0)
93 ) {
95 }
96 }
97 }
98
99 return false;
100 }
101
108 protected function checkValidityOfURLField($value, ?int $record_id): bool
109 {
110 // TODO: value should always be an array with url fields, can we remove the check & json_decode?
111 if (!is_array($value)) {
112 $value = ['link' => $value, 'title' => ''];
113 }
114
115 //Don't check empty values
116 if (!$value['link']) {
117 return true;
118 }
119
120 $this->checkRegexAndLength($value['link']);
121
122 //check url/email
123 $link = (substr($value['link'], 0, 3) === 'www') ? 'https://' . $value['link'] : $value['link'];
124 if (!filter_var($link, FILTER_VALIDATE_URL) && !filter_var($link, FILTER_VALIDATE_EMAIL) && $link != '') {
126 }
127
128 if ($this->isUnique()) {
129 $table = ilDclCache::getTableCache($this->getTableId());
130 foreach ($table->getRecords() as $record) {
131 $record_value = $record->getRecordFieldValue($this->getId());
132
133 if ($record_value == $value
134 && ($record->getId() != $record_id
135 || !$record_id)
136 ) {
138 }
139 }
140 }
141
142 return true;
143 }
144
145 public function checkFieldCreationInput(ilPropertyFormGUI $form): bool
146 {
147 $return = true;
148 // Additional check for text fields: The length property should be max 200 if the textarea option is not set
149 if ((int) $form->getInput('prop_' . ilDclBaseFieldModel::PROP_LENGTH) > 200 && !$form->getInput('prop_' . ilDclBaseFieldModel::PROP_TEXTAREA)) {
150 $inputObj = $form->getItemByPostVar('prop_' . ilDclBaseFieldModel::PROP_LENGTH);
151 $inputObj->setAlert($this->lng->txt("form_msg_value_too_high"));
152 $return = false;
153 }
154
155 return $return;
156 }
157
161 public function getValidFieldProperties(): array
162 {
163 return [
169 ];
170 }
171
172 protected function checkRegexAndLength(string $value): void
173 {
174 $regex = $this->getProperty(ilDclBaseFieldModel::PROP_REGEX);
175 if (substr($regex, 0, 1) != "/") {
176 $regex = "/" . $regex;
177 }
178 if (substr($regex, -1) != "/") {
179 $regex .= "/";
180 }
181
182 if ($this->getProperty(ilDclBaseFieldModel::PROP_LENGTH) < $this->strlen($value)
183 && is_numeric($this->getProperty(ilDclBaseFieldModel::PROP_LENGTH))
184 ) {
186 }
187
188 if ($this->getProperty(ilDclBaseFieldModel::PROP_REGEX) != null) {
189 try {
190 $preg_match = preg_match($regex, $value);
191 } catch (ErrorException $e) {
193 }
194
195 if ($preg_match == false) {
197 }
198 }
199 }
200
201 public function strlen(string $value, string $encoding = 'UTF-8'): int
202 {
203 switch (true) {
204 case function_exists('mb_strlen'):
205 return mb_strlen($value, $encoding);
206 case function_exists('iconv_strlen'):
207 return iconv_strlen($value, $encoding);
208 default:
209 return strlen($value);
210 }
211 }
212
213 public function fillHeaderExcel(ilExcel $worksheet, int &$row, int &$col): void
214 {
215 parent::fillHeaderExcel($worksheet, $row, $col);
216 if ($this->getProperty(ilDclBaseFieldModel::PROP_URL)) {
217 $worksheet->setCell($row, $col, $this->getTitle() . '_title');
218 $col++;
219 }
220 }
221
222 public function checkTitlesForImport(array &$titles, array &$import_fields): void
223 {
224 foreach ($titles as $k => $title) {
225 if (!ilStr::isUtf8($title)) {
226 $title = utf8_encode($title);
227 }
228 if ($title == $this->getTitle()) {
229 $import_fields[$k] = $this;
230 if ($this->hasProperty(ilDclBaseFieldModel::PROP_URL) && $titles[$k + 1] == $this->getTitle() . '_title') {
231 unset($titles[$k + 1]);
232 }
233 }
234 }
235 }
236}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const PROP_LENGTH
General properties.
static getTableCache(int $table_id=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
checkTitlesForImport(array &$titles, array &$import_fields)
checkValidityFromForm(ilPropertyFormGUI &$form, ?int $record_id=null)
checkValidityOfURLField($value, ?int $record_id)
checkValidity($value, ?int $record_id=null)
fillHeaderExcel(ilExcel $worksheet, int &$row, int &$col)
strlen(string $value, string $encoding='UTF-8')
getRecordQuerySortObject(string $direction="asc", bool $sort_by_status=false)
Returns a query-object for building the record-loader-sql-query.
getRecordQueryFilterObject( $filter_value="", ?ilDclBaseFieldModel $sort_field=null)
checkFieldCreationInput(ilPropertyFormGUI $form)
Checks input of specific fields befor saving.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setCell(int $a_row, int $a_col, $a_value, ?string $a_datatype=null)
Set cell value.
This class represents a property form user interface.
getInput(string $a_post_var, bool $ensureValidation=true)
Returns the input of an item, if item provides getInput method and as fallback the value of the HTTP-...
getItemByPostVar(string $a_post_var)
static isUtf8(string $a_str)
Check whether string is utf-8.
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: confirmReg.php:20