ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
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 
44  public function checkValidityFromForm(ilPropertyFormGUI &$form, ?int $record_id = null): void
45  {
47  $value = [
48  'link' => $form->getInput("field_" . $this->getId()),
49  'title' => $form->getInput("field_" . $this->getId() . "_title"),
50  ];
51  } else {
52  $value = $form->getInput('field_' . $this->getId());
53  }
54  $this->checkValidity($value, $record_id);
55  }
56 
57  public function checkValidity($value, ?int $record_id = null): bool
58  {
59  if (isset($value['link'])) {
60  $value = $value['link'];
61  $link = (substr($value, 0, 3) === 'www') ? 'https://' . $value : $value;
62  if (!filter_var($link, FILTER_VALIDATE_URL) && !filter_var($link, FILTER_VALIDATE_EMAIL) && $link != '') {
64  }
65  }
66  $this->checkRegexAndLength($value);
67  return parent::checkValidity($value, $record_id);
68  }
69 
70  protected function areEqual($value_1, $value_2): bool
71  {
72  return parent::areEqual($value_1['link'] ?? $value_1, $value_2['link'] ?? $value_2);
73  }
74 
78  public function getValidFieldProperties(): array
79  {
80  return [
85  ];
86  }
87 
88  protected function checkRegexAndLength(string $value): void
89  {
90  if ($this->getProperty(ilDclBaseFieldModel::PROP_LENGTH) < $this->strlen($value)) {
92  }
93 
94  if ($this->getProperty(ilDclBaseFieldModel::PROP_REGEX) != null) {
96  if (substr($regex, 0, 1) != "/") {
97  $regex = "/" . $regex;
98  }
99  if (substr($regex, -1) != "/") {
100  $regex .= "/";
101  }
102 
103  try {
104  $preg_match = preg_match($regex, $value);
105  } catch (ErrorException) {
107  }
108 
109  if ($preg_match === false) {
111  }
112  }
113  }
114 
115  public function strlen(string $value, string $encoding = 'UTF-8'): int
116  {
117  switch (true) {
118  case function_exists('mb_strlen'):
119  return mb_strlen($value, $encoding);
120  case function_exists('iconv_strlen'):
121  return iconv_strlen($value, $encoding);
122  default:
123  return strlen($value);
124  }
125  }
126 
127  public function fillHeaderExcel(ilExcel $worksheet, int &$row, int &$col): void
128  {
129  parent::fillHeaderExcel($worksheet, $row, $col);
131  $worksheet->setCell($row, $col, $this->getTitle() . '_title');
132  $col++;
133  }
134  }
135 
136  public function checkTitlesForImport(array &$titles, array &$import_fields): void
137  {
138  foreach ($titles as $k => $title) {
139  if (!mb_detect_encoding($title, "UTF-8", true) == "UTF-8") {
140  $title = mb_convert_encoding($title, 'UTF-8', 'ISO-8859-1');
141  }
142  if ($title == $this->getTitle()) {
143  $import_fields[$k] = $this;
144  if ($this->hasProperty(ilDclBaseFieldModel::PROP_URL) && $titles[$k + 1] == $this->getTitle() . '_title') {
145  unset($titles[$k + 1]);
146  }
147  }
148  }
149  }
150 }
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)
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-...
setCell(int $a_row, int $col, $value, ?string $datatype=null, bool $disable_strip_tags_for_strings=false)
Set cell value.
strlen(string $value, string $encoding='UTF-8')
const PROP_LENGTH
General properties.
checkValidityFromForm(ilPropertyFormGUI &$form, ?int $record_id=null)
areEqual($value_1, $value_2)