ILIAS  release_8 Revision v8.24
class.ilDclTextRecordFieldModel.php
Go to the documentation of this file.
1<?php
2
19use PhpOffice\PhpSpreadsheet\Cell\DataType;
20
22{
23 public function setValueFromForm(ilPropertyFormGUI $form): void
24 {
25 if ($this->getField()->hasProperty(ilDclBaseFieldModel::PROP_URL)) {
26 $value = array(
27 "link" => $form->getInput("field_" . $this->getField()->getId()),
28 "title" => $form->getInput("field_" . $this->getField()->getId() . '_title'),
29 );
30 } else {
31 $value = $form->getInput("field_" . $this->getField()->getId());
32 }
33 $this->setValue($value);
34 }
35
36 public function fillExcelExport(ilExcel $worksheet, int &$row, int &$col): void
37 {
38 $value = $this->getExportValue();
39
40 if ($this->getField()->getProperty(ilDclBaseFieldModel::PROP_URL)) {
41 if (is_array($value)) {
42 $worksheet->setCell($row, $col, $value['link']);
43 $col++;
44 $worksheet->setCell($row, $col, $value['title']);
45 $col++;
46 } else {
47 $worksheet->setCell($row, $col, $value);
48 $col += 2;
49 }
50 } else {
51 $worksheet->setCell($row, $col, $value, DataType::TYPE_STRING);
52 $col++;
53 }
54 }
55
56 public function addHiddenItemsToConfirmation(ilConfirmationGUI $confirmation): void
57 {
58 if ($this->field->hasProperty(ilDclBaseFieldModel::PROP_URL)) {
59 $value = $this->getValue();
60 if (is_array($value)) {
61 $confirmation->addHiddenItem('field_' . $this->field->getId(), $value['link']);
62 $confirmation->addHiddenItem('field_' . $this->field->getId() . '_title', $value['title']);
63 }
64
65 return;
66 }
67 parent::addHiddenItemsToConfirmation($confirmation);
68 }
69
70 public function getPlainText(): string
71 {
72 $value = $this->getValue();
73
74 if (is_array($value)) {
75 if ($value['title']) {
76 return $value['title'];
77 }
78
79 return $value['link'] ?? '';
80 } else {
81 if ($value) {
82 return $value;
83 }
84 }
85 return '';
86 }
87
91 public function getExportValue()
92 {
93 $value = $this->getValue();
94
95 // TODO: Handle line-breaks for excel
96 if (is_array($value) && !$this->getField()->getProperty(ilDclBaseFieldModel::PROP_URL)) {
97 return $value['link'];
98 } else {
99 return $value;
100 }
101 }
102
109 public function getValueFromExcel(ilExcel $excel, int $row, int $col)
110 {
111 $value = parent::getValueFromExcel($excel, $row, $col);
112 if ($this->getField()->hasProperty(ilDclBaseFieldModel::PROP_URL)) {
113 $title = '';
114 if ($excel->getCell(1, $col + 1) == $this->getField()->getTitle() . '_title') {
115 $title = $excel->getCell($row, $col + 1);
116 }
117 $value = ['link' => $value, 'title' => $title];
118 }
119
120 if ($value) {
121 return $value;
122 }
123 return "";
124 }
125
129 public function parseValue($value)
130 {
131 if ($this->getField()->getProperty(ilDclBaseFieldModel::PROP_TEXTAREA)
132 && !$this->getField()->getProperty(ilDclBaseFieldModel::PROP_URL)
133 ) {
134 return $value;
135 }
136
137 return $value;
138 }
139
144 public function parseSortingValue($value, bool $link = true): string
145 {
146 if ($this->getField()->getProperty(ilDclBaseFieldModel::PROP_URL)) {
147 if (is_array($value)) {
148 return $value['title'] ?? $value['link'];
149 } else {
150 return $value;
151 }
152 } else {
153 return $value;
154 }
155 }
156
157 public function deserializeData($value)
158 {
159 $value = (string) $value;
160 if ($this->getField()->getProperty(ilDclBaseFieldModel::PROP_URL)) {
161 $deserialize = json_decode($value, true);
162 return [
163 'title' => $deserialize['title'] ?? '',
164 'link' => $deserialize['link'] ?? '',
165 ];
166 }
167
168 return $value;
169 }
170}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addHiddenItem(string $a_post_var, string $a_value)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setValue($value, bool $omit_parsing=false)
Set value for record field.
fillExcelExport(ilExcel $worksheet, int &$row, int &$col)
getValueFromExcel(ilExcel $excel, int $row, int $col)
deserializeData($value)
Deserialize data before applying to field.
parseSortingValue($value, bool $link=true)
Returns sortable value for the specific field-types.
addHiddenItemsToConfirmation(ilConfirmationGUI $confirmation)
getCell(int $a_row, int $a_col)
Returns the value of a cell.
setCell(int $a_row, int $a_col, $a_value, ?string $a_datatype=null)
Set cell value.
This class represents a property form user interface.
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-...