ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilDclTextFieldModel.php
Go to the documentation of this file.
1 <?php
2 
18 declare(strict_types=1);
19 
21 {
25  public function getRecordQueryFilterObject(
26  $filter_value = "",
27  ?ilDclBaseFieldModel $sort_field = null
29  $join_str
30  = "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 = "
31  . $this->db->quote($this->getId(), 'integer') . ") ";
32  $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 "
33  . $this->db->quote("%$filter_value%", 'text') . ") ";
34 
35  $sql_obj = new ilDclRecordQueryObject();
36  $sql_obj->setJoinStatement($join_str);
37 
38  return $sql_obj;
39  }
40 
41  public function checkValidityFromForm(ilPropertyFormGUI &$form, ?int $record_id = null): void
42  {
44  $value = [
45  'link' => $form->getInput("field_" . $this->getId()),
46  'title' => $form->getInput("field_" . $this->getId() . "_title"),
47  ];
48  } else {
49  $value = $form->getInput('field_' . $this->getId());
50  }
51  $this->checkValidity($value, $record_id);
52  }
53 
54  public function checkValidity($value, ?int $record_id = null): bool
55  {
56  if (isset($value['link'])) {
57  $value = $value['link'];
58  $link = (substr($value, 0, 3) === 'www') ? 'https://' . $value : $value;
59  if (!filter_var($link, FILTER_VALIDATE_URL) && !filter_var($link, FILTER_VALIDATE_EMAIL) && $link != '') {
61  }
62  }
63  $this->checkRegexAndLength($value);
64  return parent::checkValidity($value, $record_id);
65  }
66 
67  protected function areEqual($value_1, $value_2): bool
68  {
69  return parent::areEqual($value_1['link'] ?? $value_1, $value_2['link'] ?? $value_2);
70  }
71 
72  public function checkFieldCreationInput(ilPropertyFormGUI $form): bool
73  {
74  $return = true;
75  if ((int) $form->getInput('prop_' . ilDclBaseFieldModel::PROP_LENGTH) > 200 && !$form->getInput('prop_' . ilDclBaseFieldModel::PROP_TEXTAREA)) {
76  $inputObj = $form->getItemByPostVar('prop_' . ilDclBaseFieldModel::PROP_LENGTH);
77  $inputObj->setAlert($this->lng->txt("form_msg_value_too_high"));
78  $return = false;
79  }
80 
81  return $return;
82  }
83 
87  public function getValidFieldProperties(): array
88  {
89  return [
95  ];
96  }
97 
98  protected function checkRegexAndLength(string $value): void
99  {
100  if ($this->getProperty(ilDclBaseFieldModel::PROP_LENGTH) < $this->strlen($value)
101  && is_numeric($this->getProperty(ilDclBaseFieldModel::PROP_LENGTH))
102  ) {
104  }
105 
106  if ($this->getProperty(ilDclBaseFieldModel::PROP_REGEX) != null) {
108  if (substr($regex, 0, 1) != "/") {
109  $regex = "/" . $regex;
110  }
111  if (substr($regex, -1) != "/") {
112  $regex .= "/";
113  }
114 
115  try {
116  $preg_match = preg_match($regex, $value);
117  } catch (ErrorException) {
119  }
120 
121  if ($preg_match === false) {
123  }
124  }
125  }
126 
127  public function strlen(string $value, string $encoding = 'UTF-8'): int
128  {
129  switch (true) {
130  case function_exists('mb_strlen'):
131  return mb_strlen($value, $encoding);
132  case function_exists('iconv_strlen'):
133  return iconv_strlen($value, $encoding);
134  default:
135  return strlen($value);
136  }
137  }
138 
139  public function fillHeaderExcel(ilExcel $worksheet, int &$row, int &$col): void
140  {
141  parent::fillHeaderExcel($worksheet, $row, $col);
143  $worksheet->setCell($row, $col, $this->getTitle() . '_title');
144  $col++;
145  }
146  }
147 
148  public function checkTitlesForImport(array &$titles, array &$import_fields): void
149  {
150  foreach ($titles as $k => $title) {
151  if (!mb_detect_encoding($title, "UTF-8", true) == "UTF-8") {
152  $title = mb_convert_encoding($title, 'UTF-8', 'ISO-8859-1');
153  }
154  if ($title == $this->getTitle()) {
155  $import_fields[$k] = $this;
156  if ($this->hasProperty(ilDclBaseFieldModel::PROP_URL) && $titles[$k + 1] == $this->getTitle() . '_title') {
157  unset($titles[$k + 1]);
158  }
159  }
160  }
161  }
162 }
hasProperty(string $key)
Checks if a certain property for a field is set.
fillHeaderExcel(ilExcel $worksheet, int &$row, int &$col)
checkTitlesForImport(array &$titles, array &$import_fields)
getItemByPostVar(string $a_post_var)
checkFieldCreationInput(ilPropertyFormGUI $form)
setCell(int $a_row, int $a_col, $a_value, ?string $a_datatype=null)
Set cell value.
getRecordQueryFilterObject( $filter_value="", ?ilDclBaseFieldModel $sort_field=null)
checkValidity($value, ?int $record_id=null)
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-...
strlen(string $value, string $encoding='UTF-8')
const PROP_LENGTH
General properties.
checkValidityFromForm(ilPropertyFormGUI &$form, ?int $record_id=null)
areEqual($value_1, $value_2)