ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilDclTextRecordFieldModel.php
Go to the documentation of this file.
1<?php
2
3use PhpOffice\PhpSpreadsheet\Cell\DataType;
4
11{
12
16 public function setValueFromForm($form)
17 {
18 if ($this->getField()->hasProperty(ilDclBaseFieldModel::PROP_URL)) {
19 $value = array(
20 "link" => $form->getInput("field_" . $this->getField()->getId()),
21 "title" => $form->getInput("field_" . $this->getField()->getId() . '_title'),
22 );
23 } else {
24 $value = $form->getInput("field_" . $this->getField()->getId());
25 }
26 $this->setValue($value);
27 }
28
29
35 public function fillExcelExport(ilExcel $worksheet, &$row, &$col)
36 {
37 $value = $this->getExportValue();
38
39 if ($this->getField()->getProperty(ilDclBaseFieldModel::PROP_URL)) {
40 if (is_array($value)) {
41 $worksheet->setCell($row, $col, $value['link']);
42 $col++;
43 $worksheet->setCell($row, $col, $value['title']);
44 $col++;
45 } else {
46 $worksheet->setCell($row, $col, $value);
47 $col += 2;
48 }
49 } else {
50 $worksheet->setCell($row, $col, $value, DataType::TYPE_STRING);
51 $col++;
52 }
53 }
54
55
56 public function addHiddenItemsToConfirmation(ilConfirmationGUI &$confirmation)
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
74 public function getPlainText()
75 {
76 $value = $this->getValue();
77
78 if (is_array($value)) {
79 if ($value['title']) {
80 return $value['title'];
81 }
82
83 return isset($value['link']) ? $value['link'] : '';
84 } else {
85 return $value;
86 }
87 }
88
89
93 public function getExportValue()
94 {
95 $value = $this->getValue();
96
97 // TODO: Handle line-breaks for excel
98 if (is_array($value) && !$this->getField()->getProperty(ilDclBaseFieldModel::PROP_URL)) {
99 return $value['link'];
100 } else {
101 return $value;
102 }
103 }
104
105
106 public function getValueFromExcel($excel, $row, $col)
107 {
108 $value = parent::getValueFromExcel($excel, $row, $col);
109 if ($this->getField()->hasProperty(ilDclBaseFieldModel::PROP_URL)) {
110 $title = '';
111 if ($excel->getCell(1, $col + 1) == $this->getField()->getTitle() . '_title') {
112 $title = $excel->getCell($row, $col + 1);
113 }
114 $value = array('link' => $value, 'title' => $title);
115 }
116
117 return $value;
118 }
119
120
121 public function parseValue($value)
122 {
123 if ($this->getField()->getProperty(ilDclBaseFieldModel::PROP_TEXTAREA)
124 && !$this->getField()->getProperty(ilDclBaseFieldModel::PROP_URL)
125 ) {
126 return nl2br($value);
127 }
128
129 return $value;
130 }
131
132
142 public function parseSortingValue($value, $link = true)
143 {
144 if ($this->getField()->getProperty(ilDclBaseFieldModel::PROP_URL)) {
145 if (is_array($value)) {
146 return isset($value['title']) ? $value['title'] : $value['link'];
147 } else {
148 return $value;
149 }
150 } else {
151 return $value;
152 }
153 }
154}
An exception for terminatinating execution or to throw for unit testing.
Confirmation screen class.
addHiddenItem($a_post_var, $a_value)
Add hidden item.
setValue($value, $omit_parsing=false)
Set value for record field.
Class ilDclTextRecordFieldModel.
fillExcelExport(ilExcel $worksheet, &$row, &$col)
parseValue($value)
Function to parse incoming data from form input value $value.
parseSortingValue($value, $link=true)
Returns sortable value for the specific field-types.
addHiddenItemsToConfirmation(ilConfirmationGUI &$confirmation)
setCell($a_row, $a_col, $a_value, $a_datatype=null)
Set cell value.