ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilDclTextFieldModel Class Reference

Class ilDclTextFieldModel. More...

+ Inheritance diagram for ilDclTextFieldModel:
+ Collaboration diagram for ilDclTextFieldModel:

Public Member Functions

 getRecordQueryFilterObject ($filter_value="", ilDclBaseFieldModel $sort_field=null)
 
 getRecordQuerySortObject ($direction="asc", $sort_by_status=false)
 
 checkValidityFromForm (ilPropertyFormGUI &$form, $record_id=NULL)
 
 checkValidity ($value, $record_id=NULL)
 
 checkFieldCreationInput (ilPropertyFormGUI $form)
 
 getValidFieldProperties ()
 
 strlen ($value, $encoding='UTF-8')
 
 fillHeaderExcel (ilExcel $worksheet, &$row, &$col)
 
 checkTitlesForImport (array &$titles, array &$import_fields)
 
- Public Member Functions inherited from ilDclBaseFieldModel
 __construct ($a_id=0)
 
 setId ($a_id)
 Set field id. More...
 
 getId ()
 Get field id. More...
 
 setTableId ($a_id)
 Set table id. More...
 
 getTableId ()
 Get table id. More...
 
 setTitle ($a_title)
 Set title. More...
 
 getTitle ()
 Get title. More...
 
 setDescription ($a_desc)
 Set description. More...
 
 getDescription ()
 Get description. More...
 
 setDatatypeId ($a_id)
 Set datatype id. More...
 
 getDatatypeId ()
 Get datatype_id. More...
 
 setRequired ($a_required)
 Set Required. More...
 
 getRequired ()
 Get Required Required. More...
 
 isUnique ()
 
 setUnique ($unique)
 
 getDatatype ()
 
 getDatatypeTitle ()
 
 getStorageLocation ()
 Get storage location for the model. More...
 
 getExportable ()
 
 toArray ()
 
 isStandardField ()
 
 doRead ()
 Read field. More...
 
 buildFromDBRecord ($rec)
 Builds model from db record. More...
 
 doCreate ()
 Create new field. More...
 
 doUpdate ()
 Update field. More...
 
 updateProperties ()
 Update properties of this field in Database. More...
 
 doDelete ()
 Remove field and properties. More...
 
 getFieldSettings ()
 
 getOrder ()
 
 setOrder ($order)
 
 hasProperty ($key)
 Checks if a certain property for a field is set. More...
 
 getProperty ($key)
 Returns a certain property of a field. More...
 
 getPropertyInstance ($key)
 Return ActiveRecord of property. More...
 
 setProperty ($key, $value)
 Set a property for a field (does not save) More...
 
 getValidFieldProperties ()
 Returns all valid properties for a field-type. More...
 
 setLocked ($locked)
 
 getLocked ()
 
 checkValidityFromForm (ilPropertyFormGUI &$form, $record_id=NULL)
 
 checkValidity ($value, $record_id=NULL)
 Check if input is valid. More...
 
 cloneStructure ($original_id)
 
 afterClone ($records)
 
 cloneProperties (ilDclBaseFieldModel $originalField)
 
 setExportable ($exportable)
 
 allowFilterInListView ()
 
 getRecordQuerySortObject ($direction="asc", $sort_by_status=false)
 Returns a query-object for building the record-loader-sql-query. More...
 
 getRecordQueryFilterObject ($filter_value="", ilDclBaseFieldModel $sort_field=null)
 Returns a query-object for building the record-loader-sql-query. More...
 
 getSortField ()
 Returns the sort-field id. More...
 
 hasNumericSorting ()
 Set to true, when the sorting should be handled numerical. More...
 
 checkFieldCreationInput (ilPropertyFormGUI $form)
 Checks input of specific fields befor saving. More...
 
 getStorageLocationOverride ()
 
 setStorageLocationOverride ($storage_location_override)
 
 fillHeaderExcel (ilExcel $worksheet, &$row, &$col)
 
 checkTitlesForImport (array &$titles, array &$import_fields)
 

Protected Member Functions

 checkValidityOfURLField ($value, $record_id)
 
 checkRegexAndLength ($value)
 
- Protected Member Functions inherited from ilDclBaseFieldModel
 loadDatatype ()
 Load datatype for model. More...
 
 loadTableFieldSetting ()
 loadTableFieldSetting More...
 
 addToTableViews ()
 create ilDclTableViewFieldSettings for this field in each tableview More...
 
 updateTableFieldSetting ()
 update exportable and fieldorder More...
 
 loadProperties ()
 Get all properties of a field. More...
 
 normalizeValue ($value)
 

Additional Inherited Members

- Static Public Member Functions inherited from ilDclBaseFieldModel
static _getTitleInvalidChars ($a_as_regex=true)
 All valid chars for filed titles. More...
 
static _getFieldIdByTitle ($title, $table_id)
 
- Data Fields inherited from ilDclBaseFieldModel
const PROP_LENGTH = "lenght"
 General properties. More...
 
const PROP_REGEX = "regex"
 
const PROP_REFERENCE = "table_id"
 
const PROP_URL = "url"
 
const PROP_TEXTAREA = "text_area"
 
const PROP_REFERENCE_LINK = "reference_link"
 
const PROP_WIDTH = "width"
 
const PROP_HEIGHT = "height"
 
const PROP_LEARNING_PROGRESS = "learning_progress"
 
const PROP_ILIAS_REFERENCE_LINK = "ILIAS_reference_link"
 
const PROP_N_REFERENCE = "multiple_selection"
 
const PROP_FORMULA_EXPRESSION = "expression"
 
const PROP_DISPLAY_COPY_LINK_ACTION_MENU = "display_action_menu"
 
const PROP_LINK_DETAIL_PAGE_TEXT = "link_detail_page"
 
const PROP_SUPPORTED_FILE_TYPES = "supported_file_types"
 
const PROP_PLUGIN_HOOK_NAME = "plugin_hook_name"
 
const EDIT_VIEW = 2
 
const EXPORTABLE_VIEW = 4
 
- Protected Attributes inherited from ilDclBaseFieldModel
 $id
 
 $table_id
 
 $title
 
 $description
 
 $datatypeId
 
 $required
 
 $order
 
 $unique
 
 $locked
 
 $property = array()
 
 $exportable
 
 $datatype
 
 $storage_location_override = null
 

Detailed Description

Class ilDclTextFieldModel.

Author
Michael Herren mh@st.nosp@m.uder.nosp@m.-raim.nosp@m.ann..nosp@m.ch
Version
1.0.0

Definition at line 12 of file class.ilDclTextFieldModel.php.

Member Function Documentation

◆ checkFieldCreationInput()

ilDclTextFieldModel::checkFieldCreationInput ( ilPropertyFormGUI  $form)

Definition at line 140 of file class.ilDclTextFieldModel.php.

References $DIC, $lng, ilPropertyFormGUI\getInput(), ilPropertyFormGUI\getItemByPostVar(), ilDclBaseFieldModel\PROP_LENGTH, and ilDclBaseFieldModel\PROP_TEXTAREA.

140  {
141  global $DIC;
142  $lng = $DIC['lng'];
143 
144  $return = true;
145  // Additional check for text fields: The length property should be max 200 if the textarea option is not set
146  if ((int)$form->getInput('prop_' . ilDclBaseFieldModel::PROP_LENGTH) > 200 && !$form->getInput('prop_' . ilDclBaseFieldModel::PROP_TEXTAREA)) {
147  $inputObj = $form->getItemByPostVar('prop_' . ilDclBaseFieldModel::PROP_LENGTH);
148  $inputObj->setAlert($lng->txt("form_msg_value_too_high"));
149  $return = false;
150  }
151 
152  return $return;
153  }
getItemByPostVar($a_post_var)
Get Item by POST variable.
const PROP_LENGTH
General properties.
getInput($a_post_var, $ensureValidation=true)
Returns the value of a HTTP-POST variable, identified by the passed id.
global $lng
Definition: privfeed.php:17
global $DIC
+ Here is the call graph for this function:

◆ checkRegexAndLength()

ilDclTextFieldModel::checkRegexAndLength (   $value)
protected
Parameters
$value
Exceptions
ilDclInputException

Definition at line 169 of file class.ilDclTextFieldModel.php.

References ilDclBaseFieldModel\getProperty(), ilDclInputException\LENGTH_EXCEPTION, ilDclBaseFieldModel\PROP_LENGTH, ilDclBaseFieldModel\PROP_REGEX, ilDclInputException\REGEX_CONFIG_EXCEPTION, ilDclInputException\REGEX_EXCEPTION, and strlen().

Referenced by checkValidity(), and checkValidityOfURLField().

169  {
171  if (substr($regex, 0, 1) != "/") {
172  $regex = "/" . $regex;
173  }
174  if (substr($regex, - 1) != "/") {
175  $regex .= "/";
176  }
177 
178  if ($this->getProperty(ilDclBaseFieldModel::PROP_LENGTH) < $this->strlen($value, 'UTF-8')
179  && is_numeric($this->getProperty(ilDclBaseFieldModel::PROP_LENGTH))
180  ) {
182  }
183 
184  if ($this->getProperty(ilDclBaseFieldModel::PROP_REGEX) != NULL) {
185  try {
186  $preg_match = preg_match($regex, $value);
187  } catch (ErrorException $e) {
189  }
190 
191  if ($preg_match == false) {
193  }
194  }
195  }
Class ilDclBaseFieldModel.
const PROP_LENGTH
General properties.
getProperty($key)
Returns a certain property of a field.
strlen($value, $encoding='UTF-8')
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkTitlesForImport()

ilDclTextFieldModel::checkTitlesForImport ( array $titles,
array $import_fields 
)
Parameters
array$titles
array$import_fields

Definition at line 226 of file class.ilDclTextFieldModel.php.

References ilDclBaseFieldModel\$title, ilDclBaseFieldModel\getTitle(), ilDclBaseFieldModel\hasProperty(), ilStr\isUtf8(), and ilDclBaseFieldModel\PROP_URL.

226  {
227  foreach ($titles as $k => $title) {
228  if (!ilStr::isUtf8($title)) {
229  $title = utf8_encode($title);
230  }
231  if ($title == $this->getTitle()) {
232  $import_fields[$k] = $this;
233  if ($this->hasProperty(ilDclBaseFieldModel::PROP_URL) && $titles[$k+1] == $this->getTitle().'_title') {
234  unset($titles[$k+1]);
235  }
236  }
237  }
238 
239  }
hasProperty($key)
Checks if a certain property for a field is set.
static isUtf8($a_str)
Check whether string is utf-8.
+ Here is the call graph for this function:

◆ checkValidity()

ilDclTextFieldModel::checkValidity (   $value,
  $record_id = NULL 
)

Definition at line 66 of file class.ilDclTextFieldModel.php.

References checkRegexAndLength(), checkValidityOfURLField(), ilDclBaseFieldModel\getId(), ilDclBaseFieldModel\getProperty(), ilDclCache\getTableCache(), ilDclBaseFieldModel\getTableId(), ilDclBaseFieldModel\isUnique(), ilDclBaseFieldModel\normalizeValue(), ilDclBaseFieldModel\PROP_URL, and ilDclInputException\UNIQUE_EXCEPTION.

66  {
67  $has_url_property = $this->getProperty(ilDclBaseFieldModel::PROP_URL);
68  if ($has_url_property) {
69  return $this->checkValidityOfURLField($value, $record_id);
70  }
71 
72  //Don't check empty values
73  if ($value == NULL) {
74  return true;
75  }
76 
77  $this->checkRegexAndLength($value);
78 
79  if ($this->isUnique()) {
80  $table = ilDclCache::getTableCache($this->getTableId());
81  foreach ($table->getRecords() as $record) {
82  //for text it has to be case insensitive.
83  $record_value = $record->getRecordFieldValue($this->getId());
84 
85  if (strtolower($this->normalizeValue($record_value)) == strtolower($this->normalizeValue(nl2br($value)))
86  && ($record->getId() != $record_id
87  || $record_id == 0)
88  ) {
90  }
91  }
92  }
93  }
Class ilDclBaseFieldModel.
static getTableCache($table_id=0)
getProperty($key)
Returns a certain property of a field.
checkValidityOfURLField($value, $record_id)
+ Here is the call graph for this function:

◆ checkValidityFromForm()

ilDclTextFieldModel::checkValidityFromForm ( ilPropertyFormGUI $form,
  $record_id = NULL 
)
Parameters
ilPropertyFormGUI$form
null$record_id

Definition at line 49 of file class.ilDclTextFieldModel.php.

References array, checkValidityOfURLField(), ilPropertyFormGUI\getInput(), ilDclBaseFieldModel\getProperty(), and ilDclBaseFieldModel\PROP_URL.

49  {
50  $has_url_property = $this->getProperty(ilDclBaseFieldModel::PROP_URL);
51  if ($has_url_property) {
52  $values = array(
53  'link' => $form->getInput("field_" . $this->getId()),
54  'title' => $form->getInput("field_" . $this->getId() . "_title")
55  );
56  $this->checkValidityOfURLField($values, $record_id);
57  } else {
58  parent::checkValidityFromForm($form, $record_id);
59  }
60  }
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)
+ Here is the call graph for this function:

◆ checkValidityOfURLField()

ilDclTextFieldModel::checkValidityOfURLField (   $value,
  $record_id 
)
protected
Parameters
$value
$record_id
Returns
bool
Exceptions
ilDclInputException

Definition at line 103 of file class.ilDclTextFieldModel.php.

References array, checkRegexAndLength(), ilDclBaseFieldModel\getId(), ilDclCache\getTableCache(), ilDclBaseFieldModel\getTableId(), ilDclBaseFieldModel\isUnique(), ilDclInputException\NOT_URL, and ilDclInputException\UNIQUE_EXCEPTION.

Referenced by checkValidity(), and checkValidityFromForm().

103  {
104  // TODO: value should always be an array with url fields, can we remove the check & json_decode?
105  if (!is_array($value)) {
106  $value = array( 'link' => $value, 'title' => '');
107  }
108 
109  //Don't check empty values
110  if (!$value['link']) {
111  return true;
112  }
113 
114  $this->checkRegexAndLength($value['link']);
115 
116  //check url/email
117  $link = (substr($value['link'], 0, 3) === 'www') ? 'http://' . $value['link'] : $value['link'];
118  if (! filter_var($link, FILTER_VALIDATE_URL) && ! filter_var($link, FILTER_VALIDATE_EMAIL) && $link != '') {
120  }
121 
122  if ($this->isUnique()) {
123  $table = ilDclCache::getTableCache($this->getTableId());
124  foreach ($table->getRecords() as $record) {
125  $record_value = $record->getRecordFieldValue($this->getId());
126 
127  if ($record_value == $value
128  && ($record->getId() != $record_id
129  || $record_id == 0)
130  ) {
132  }
133  }
134  }
135  }
Class ilDclBaseFieldModel.
static getTableCache($table_id=0)
Create styles array
The data for the language used.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fillHeaderExcel()

ilDclTextFieldModel::fillHeaderExcel ( ilExcel  $worksheet,
$row,
$col 
)

Definition at line 214 of file class.ilDclTextFieldModel.php.

References $row, ilDclBaseFieldModel\getProperty(), ilDclBaseFieldModel\getTitle(), ilDclBaseFieldModel\PROP_URL, and ilExcel\setCell().

214  {
215  parent::fillHeaderExcel($worksheet, $row, $col);
217  $worksheet->setCell($row, $col, $this->getTitle() . '_title');
218  $col++;
219  }
220  }
setCell($a_row, $a_col, $a_value)
Set cell value.
getProperty($key)
Returns a certain property of a field.
+ Here is the call graph for this function:

◆ getRecordQueryFilterObject()

ilDclTextFieldModel::getRecordQueryFilterObject (   $filter_value = "",
ilDclBaseFieldModel  $sort_field = null 
)

Definition at line 17 of file class.ilDclTextFieldModel.php.

References $DIC, $ilDB, and ilDclBaseFieldModel\getId().

17  {
18  global $DIC;
19  $ilDB = $DIC['ilDB'];
20 
21  $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 = "
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  }
Class ilDclRecordQueryObject.
global $ilDB
global $DIC
+ Here is the call graph for this function:

◆ getRecordQuerySortObject()

ilDclTextFieldModel::getRecordQuerySortObject (   $direction = "asc",
  $sort_by_status = false 
)

Definition at line 35 of file class.ilDclTextFieldModel.php.

References ilDclBaseFieldModel\hasProperty(), and ilDclBaseFieldModel\PROP_URL.

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  }
hasProperty($key)
Checks if a certain property for a field is set.
Class ilDclTextRecordQueryObject.
+ Here is the call graph for this function:

◆ getValidFieldProperties()

◆ strlen()

ilDclTextFieldModel::strlen (   $value,
  $encoding = 'UTF-8' 
)
Parameters
$value
string$encoding
Returns
int

Definition at line 203 of file class.ilDclTextFieldModel.php.

Referenced by checkRegexAndLength().

203  {
204  switch (true) {
205  case function_exists('mb_strlen'):
206  return mb_strlen($value, $encoding);
207  case function_exists('iconv_strlen'):
208  return iconv_strlen($value, $encoding);
209  default:
210  return strlen($value);
211  }
212  }
strlen($value, $encoding='UTF-8')
+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: