ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilDclTextFieldModel.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22{
27 $filter_value = "",
28 ?ilDclBaseFieldModel $sort_field = null
30 $join_str
31 = "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 = "
32 . $this->db->quote($this->getId(), 'integer') . ") ";
33 $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 "
34 . $this->db->quote("%$filter_value%", 'text') . ") ";
35
36 $sql_obj = new ilDclRecordQueryObject();
37 $sql_obj->setJoinStatement($join_str);
38
39 return $sql_obj;
40 }
41
45 public function checkValidityFromForm(ilPropertyFormGUI &$form, ?int $record_id): void
46 {
47 if ($this->getProperty(ilDclBaseFieldModel::PROP_URL)) {
48 $value = [
49 'link' => $form->getInput("field_" . $this->getId()),
50 'title' => $form->getInput("field_" . $this->getId() . "_title"),
51 ];
52 } else {
53 $value = $form->getInput('field_' . $this->getId());
54 }
55 $this->checkValidity($value, $record_id);
56 }
57
58 public function checkValidity($value, ?int $record_id): bool
59 {
60 $this->checkUnique($value, $record_id);
61 if (isset($value['link'])) {
62 $value = $value['link'];
63 $link = (substr($value, 0, 3) === 'www') ? 'https://' . $value : $value;
64 if (!filter_var($link, FILTER_VALIDATE_URL) && !filter_var($link, FILTER_VALIDATE_EMAIL) && $link != '') {
66 }
67 }
68 $this->checkRegexAndLength($value);
69 return parent::checkValidity($value, $record_id);
70 }
71
72 protected function areEqual($value_1, $value_2): bool
73 {
74 return parent::areEqual($value_1['link'] ?? $value_1, $value_2['link'] ?? $value_2);
75 }
76
77 public function checkFieldCreationInput(ilPropertyFormGUI $form): bool
78 {
79 return parent::checkFieldCreationInput($form) && $this->checkUniqueProp($form);
80 }
81
85 public function getValidFieldProperties(): array
86 {
87 return [
93 ];
94 }
95
96 protected function checkRegexAndLength(string $value): void
97 {
98 if ($this->getProperty(ilDclBaseFieldModel::PROP_LENGTH) < $this->strlen($value)) {
100 }
101
102 if ($this->getProperty(ilDclBaseFieldModel::PROP_REGEX) != null) {
103 $regex = $this->getProperty(ilDclBaseFieldModel::PROP_REGEX);
104 if (substr($regex, 0, 1) != "/") {
105 $regex = "/" . $regex;
106 }
107 if (substr($regex, -1) != "/") {
108 $regex .= "/";
109 }
110
111 try {
112 $preg_match = preg_match($regex, $value);
113 } catch (ErrorException) {
115 }
116
117 if ($preg_match === false) {
119 }
120 }
121 }
122
123 public function strlen(string $value, string $encoding = 'UTF-8'): int
124 {
125 switch (true) {
126 case function_exists('mb_strlen'):
127 return mb_strlen($value, $encoding);
128 case function_exists('iconv_strlen'):
129 return iconv_strlen($value, $encoding);
130 default:
131 return strlen($value);
132 }
133 }
134
135 public function fillHeaderExcel(ilExcel $worksheet, int &$row, int &$col): void
136 {
137 parent::fillHeaderExcel($worksheet, $row, $col);
138 if ($this->getProperty(ilDclBaseFieldModel::PROP_URL)) {
139 $worksheet->setCell($row, $col, $this->getTitle() . '_title');
140 $col++;
141 }
142 }
143
144 public function checkTitlesForImport(array &$titles, array &$import_fields): void
145 {
146 foreach ($titles as $k => $title) {
147 if (!mb_detect_encoding($title, "UTF-8", true) == "UTF-8") {
148 $title = mb_convert_encoding($title, 'UTF-8', 'ISO-8859-1');
149 }
150 if ($title == $this->getTitle()) {
151 $import_fields[$k] = $this;
152 if ($this->hasProperty(ilDclBaseFieldModel::PROP_URL) && $titles[$k + 1] == $this->getTitle() . '_title') {
153 unset($titles[$k + 1]);
154 }
155 }
156 }
157 }
158}
const PROP_LENGTH
General properties.
checkTitlesForImport(array &$titles, array &$import_fields)
areEqual($value_1, $value_2)
checkValidityFromForm(ilPropertyFormGUI &$form, ?int $record_id)
fillHeaderExcel(ilExcel $worksheet, int &$row, int &$col)
strlen(string $value, string $encoding='UTF-8')
checkValidity($value, ?int $record_id)
Check if input is valid.
getRecordQueryFilterObject( $filter_value="", ?ilDclBaseFieldModel $sort_field=null)
checkFieldCreationInput(ilPropertyFormGUI $form)
Checks input of specific fields befor saving.
setCell(int $a_row, int $col, $value, ?string $datatype=null, bool $disable_strip_tags_for_strings=false)
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-...