ILIAS  trunk Revision v11.0_alpha-2662-g519ff7d528f
class.ilDclTextRecordFieldModel.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
24 {
25  public function setValueFromForm(ilPropertyFormGUI $form): void
26  {
27  if ($this->getField()->hasProperty(ilDclBaseFieldModel::PROP_URL)) {
28  $value = [
29  "link" => $form->getInput("field_" . $this->getField()->getId()),
30  "title" => $form->getInput("field_" . $this->getField()->getId() . '_title'),
31  ];
32  } else {
33  $value = $form->getInput("field_" . $this->getField()->getId());
34  }
35  $this->setValue($value);
36  }
37 
38  public function fillExcelExport(ilExcel $worksheet, int &$row, int &$col): void
39  {
40  $value = $this->getExportValue();
41 
42  if ($this->getField()->getProperty(ilDclBaseFieldModel::PROP_URL)) {
43  if (is_array($value)) {
44  $worksheet->setCell($row, $col, $value['link']);
45  $col++;
46  $worksheet->setCell($row, $col, $value['title']);
47  $col++;
48  } else {
49  $worksheet->setCell($row, $col, $value);
50  $col += 2;
51  }
52  } else {
53  $worksheet->setCell($row, $col, $value, DataType::TYPE_STRING);
54  $col++;
55  }
56  }
57 
58  public function addHiddenItemsToConfirmation(ilConfirmationGUI $confirmation): void
59  {
60  if ($this->field->hasProperty(ilDclBaseFieldModel::PROP_URL)) {
61  $value = $this->getValue();
62  if (is_array($value)) {
63  $confirmation->addHiddenItem('field_' . $this->field->getId(), $value['link']);
64  $confirmation->addHiddenItem('field_' . $this->field->getId() . '_title', $value['title']);
65  }
66 
67  return;
68  }
69  parent::addHiddenItemsToConfirmation($confirmation);
70  }
71 
72  public function getPlainText(): string
73  {
74  $value = $this->getValue();
75 
76  if (is_array($value)) {
77  if ($value['title']) {
78  return $value['title'];
79  }
80 
81  return $value['link'] ?? '';
82  } else {
83  if ($value) {
84  return $value;
85  }
86  }
87  return '';
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 
111  public function getValueFromExcel(ilExcel $excel, int $row, int $col)
112  {
113  $value = parent::getValueFromExcel($excel, $row, $col);
114  if ($this->getField()->hasProperty(ilDclBaseFieldModel::PROP_URL)) {
115  $title = '';
116  if ($excel->getCell(1, $col + 1) == $this->getField()->getTitle() . '_title') {
117  $title = $excel->getCell($row, $col + 1);
118  }
119  $value = ['link' => $value, 'title' => $title];
120  }
121 
122  if ($value) {
123  return $value;
124  }
125  return "";
126  }
127 
132  public function parseSortingValue($value, bool $link = true): string
133  {
134  if ($this->getField()->getProperty(ilDclBaseFieldModel::PROP_URL)) {
135  if (is_array($value)) {
136  return $value['title'] ?? $value['link'];
137  } else {
138  return $value;
139  }
140  } else {
141  return $value;
142  }
143  }
144 
145  public function deserializeData($value)
146  {
147  $value = (string) $value;
148  if ($this->getField()->getProperty(ilDclBaseFieldModel::PROP_URL)) {
149  $deserialize = json_decode($value, true);
150  return [
151  'title' => $deserialize['title'] ?? '',
152  'link' => $deserialize['link'] ?? '',
153  ];
154  }
155 
156  return $value;
157  }
158 }
parseSortingValue($value, bool $link=true)
Returns sortable value for the specific field-types.
setValue($value, bool $omit_parsing=false)
Set value for record field.
addHiddenItemsToConfirmation(ilConfirmationGUI $confirmation)
addHiddenItem(string $a_post_var, string $a_value)
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-...
setCell(int $a_row, int $col, $value, ?string $datatype=null, bool $disable_strip_tags_for_strings=false)
Set cell value.
getCell(int $a_row, int $a_col)
Returns the value of a cell.
fillExcelExport(ilExcel $worksheet, int &$row, int &$col)
getValueFromExcel(ilExcel $excel, int $row, int $col)