ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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()) {
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()) {
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  {
169  }
170 
171 
177  protected function checkRegexAndLength($value)
178  {
180  if (substr($regex, 0, 1) != "/") {
181  $regex = "/" . $regex;
182  }
183  if (substr($regex, -1) != "/") {
184  $regex .= "/";
185  }
186 
187  if ($this->getProperty(ilDclBaseFieldModel::PROP_LENGTH) < $this->strlen($value, 'UTF-8')
188  && is_numeric($this->getProperty(ilDclBaseFieldModel::PROP_LENGTH))
189  ) {
191  }
192 
193  if ($this->getProperty(ilDclBaseFieldModel::PROP_REGEX) != null) {
194  try {
195  $preg_match = preg_match($regex, $value);
196  } catch (ErrorException $e) {
198  }
199 
200  if ($preg_match == false) {
202  }
203  }
204  }
205 
206 
213  public function strlen($value, $encoding = 'UTF-8')
214  {
215  switch (true) {
216  case function_exists('mb_strlen'):
217  return mb_strlen($value, $encoding);
218  case function_exists('iconv_strlen'):
219  return iconv_strlen($value, $encoding);
220  default:
221  return strlen($value);
222  }
223  }
224 
225 
226  public function fillHeaderExcel(ilExcel $worksheet, &$row, &$col)
227  {
228  parent::fillHeaderExcel($worksheet, $row, $col);
230  $worksheet->setCell($row, $col, $this->getTitle() . '_title');
231  $col++;
232  }
233  }
234 
235 
240  public function checkTitlesForImport(array &$titles, array &$import_fields)
241  {
242  foreach ($titles as $k => $title) {
243  if (!ilStr::isUtf8($title)) {
244  $title = utf8_encode($title);
245  }
246  if ($title == $this->getTitle()) {
247  $import_fields[$k] = $this;
248  if ($this->hasProperty(ilDclBaseFieldModel::PROP_URL) && $titles[$k + 1] == $this->getTitle() . '_title') {
249  unset($titles[$k + 1]);
250  }
251  }
252  }
253  }
254 }
Class ilDclBaseFieldModel.
fillHeaderExcel(ilExcel $worksheet, &$row, &$col)
getItemByPostVar($a_post_var)
Get Item by POST variable.
checkValidity($value, $record_id=null)
This class represents a property form user interface.
checkTitlesForImport(array &$titles, array &$import_fields)
Class ilDclRecordQueryObject.
global $DIC
Definition: saml.php:7
Class ilDclBaseFieldModel.
checkFieldCreationInput(ilPropertyFormGUI $form)
checkValidityFromForm(ilPropertyFormGUI &$form, $record_id=null)
static getTableCache($table_id=0)
if(isset($_POST['submit'])) $form
$lng
hasProperty($key)
Checks if a certain property for a field is set.
$values
const PROP_LENGTH
General properties.
setCell($a_row, $a_col, $a_value, $a_datatype=null)
Set cell value.
getRecordQueryFilterObject($filter_value="", ilDclBaseFieldModel $sort_field=null)
getInput($a_post_var, $ensureValidation=true)
Returns the value of a HTTP-POST variable, identified by the passed id.
$row
getProperty($key)
Returns a certain property of a field.
checkValidityOfURLField($value, $record_id)
strlen($value, $encoding='UTF-8')
global $ilDB
Class ilDclTextRecordQueryObject.
if(empty($password)) $table
Definition: pwgen.php:24
getRecordQuerySortObject($direction="asc", $sort_by_status=false)
Class ilDclTextFieldModel.
static isUtf8($a_str)
Check whether string is utf-8.