ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 = "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 = "
21  . $ilDB->quote($this->getId(), 'integer') . ") ";
22  $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 "
23  . $ilDB->quote("%$filter_value%", 'text') . ") ";
24 
25  $sql_obj = new ilDclRecordQueryObject();
26  $sql_obj->setJoinStatement($join_str);
27 
28  return $sql_obj;
29  }
30 
34  public function getRecordQuerySortObject($direction = "asc", $sort_by_status = false)
35  {
36  // use custom record sorting for url-fields
38  return new ilDclTextRecordQueryObject();
39  } else {
40  return parent::getRecordQuerySortObject($direction, $sort_by_status);
41  }
42  }
43 
44 
49  public function checkValidityFromForm(ilPropertyFormGUI &$form, $record_id = null)
50  {
51  $has_url_property = $this->getProperty(ilDclBaseFieldModel::PROP_URL);
52  if ($has_url_property) {
53  $values = array(
54  'link' => $form->getInput("field_" . $this->getId()),
55  'title' => $form->getInput("field_" . $this->getId() . "_title")
56  );
57  $this->checkValidityOfURLField($values, $record_id);
58  } else {
59  parent::checkValidityFromForm($form, $record_id);
60  }
61  }
62 
63 
67  public function checkValidity($value, $record_id = null)
68  {
69  $has_url_property = $this->getProperty(ilDclBaseFieldModel::PROP_URL);
70  if ($has_url_property) {
71  return $this->checkValidityOfURLField($value, $record_id);
72  }
73 
74  //Don't check empty values
75  if ($value == null) {
76  return true;
77  }
78 
79  $this->checkRegexAndLength($value);
80 
81  if ($this->isUnique()) {
83  foreach ($table->getRecords() as $record) {
84  //for text it has to be case insensitive.
85  $record_value = $record->getRecordFieldValue($this->getId());
86 
87  if (strtolower($this->normalizeValue($record_value)) == strtolower($this->normalizeValue(nl2br($value)))
88  && ($record->getId() != $record_id
89  || $record_id == 0)
90  ) {
92  }
93  }
94  }
95  }
96 
97 
105  protected function checkValidityOfURLField($value, $record_id)
106  {
107  // TODO: value should always be an array with url fields, can we remove the check & json_decode?
108  if (!is_array($value)) {
109  $value = array( 'link' => $value, 'title' => '');
110  }
111 
112  //Don't check empty values
113  if (!$value['link']) {
114  return true;
115  }
116 
117  $this->checkRegexAndLength($value['link']);
118 
119  //check url/email
120  $link = (substr($value['link'], 0, 3) === 'www') ? 'http://' . $value['link'] : $value['link'];
121  if (!filter_var($link, FILTER_VALIDATE_URL) && !filter_var($link, FILTER_VALIDATE_EMAIL) && $link != '') {
123  }
124 
125  if ($this->isUnique()) {
127  foreach ($table->getRecords() as $record) {
128  $record_value = $record->getRecordFieldValue($this->getId());
129 
130  if ($record_value == $value
131  && ($record->getId() != $record_id
132  || $record_id == 0)
133  ) {
135  }
136  }
137  }
138  }
139 
144  {
145  global $DIC;
146  $lng = $DIC['lng'];
147 
148  $return = true;
149  // Additional check for text fields: The length property should be max 200 if the textarea option is not set
150  if ((int) $form->getInput('prop_' . ilDclBaseFieldModel::PROP_LENGTH) > 200 && !$form->getInput('prop_' . ilDclBaseFieldModel::PROP_TEXTAREA)) {
151  $inputObj = $form->getItemByPostVar('prop_' . ilDclBaseFieldModel::PROP_LENGTH);
152  $inputObj->setAlert($lng->txt("form_msg_value_too_high"));
153  $return = false;
154  }
155 
156  return $return;
157  }
158 
159 
163  public function getValidFieldProperties()
164  {
166  }
167 
168 
174  protected function checkRegexAndLength($value)
175  {
177  if (substr($regex, 0, 1) != "/") {
178  $regex = "/" . $regex;
179  }
180  if (substr($regex, -1) != "/") {
181  $regex .= "/";
182  }
183 
184  if ($this->getProperty(ilDclBaseFieldModel::PROP_LENGTH) < $this->strlen($value, 'UTF-8')
185  && is_numeric($this->getProperty(ilDclBaseFieldModel::PROP_LENGTH))
186  ) {
188  }
189 
190  if ($this->getProperty(ilDclBaseFieldModel::PROP_REGEX) != null) {
191  try {
192  $preg_match = preg_match($regex, $value);
193  } catch (ErrorException $e) {
195  }
196 
197  if ($preg_match == false) {
199  }
200  }
201  }
202 
203 
209  public function strlen($value, $encoding = 'UTF-8')
210  {
211  switch (true) {
212  case function_exists('mb_strlen'):
213  return mb_strlen($value, $encoding);
214  case function_exists('iconv_strlen'):
215  return iconv_strlen($value, $encoding);
216  default:
217  return strlen($value);
218  }
219  }
220 
221  public function fillHeaderExcel(ilExcel $worksheet, &$row, &$col)
222  {
223  parent::fillHeaderExcel($worksheet, $row, $col);
225  $worksheet->setCell($row, $col, $this->getTitle() . '_title');
226  $col++;
227  }
228  }
229 
234  public function checkTitlesForImport(array &$titles, array &$import_fields)
235  {
236  foreach ($titles as $k => $title) {
237  if (!ilStr::isUtf8($title)) {
238  $title = utf8_encode($title);
239  }
240  if ($title == $this->getTitle()) {
241  $import_fields[$k] = $this;
242  if ($this->hasProperty(ilDclBaseFieldModel::PROP_URL) && $titles[$k+1] == $this->getTitle() . '_title') {
243  unset($titles[$k+1]);
244  }
245  }
246  }
247  }
248 }
Class ilDclBaseFieldModel.
fillHeaderExcel(ilExcel $worksheet, &$row, &$col)
$worksheet
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
hasProperty($key)
Checks if a certain property for a field is set.
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.
Create styles array
The data for the language used.
getProperty($key)
Returns a certain property of a field.
checkValidityOfURLField($value, $record_id)
global $lng
Definition: privfeed.php:17
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.