ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilDclSelectionRecordFieldModel.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
10{
11
12 // those should be overwritten by subclasses
15
16
20 public function getValue()
21 {
22 if ($this->getField()->isMulti() && !is_array($this->value)) {
23 return array($this->value);
24 }
25 if (!$this->getField()->isMulti() && is_array($this->value)) {
26 return (count($this->value) == 1) ? array_shift($this->value) : '';
27 }
28
29 return $this->value;
30 }
31
32
33 public function setValueFromForm($form)
34 {
35 parent::setValueFromForm($form); // TODO: Change the autogenerated stub
36 }
37
38
44 public function parseExportValue($value)
45 {
47
48 return is_array($values) ? implode("; ", $values) : $values;
49 }
50
51
59 public function getValueFromExcel($excel, $row, $col)
60 {
61 global $DIC;
62 $lng = $DIC['lng'];
63 $string = parent::getValueFromExcel($excel, $row, $col);
64 $old = $string;
65 if ($this->getField()->isMulti()) {
66 $string = $this->getMultipleValuesFromString($string);
67 $has_value = count($string);
68 } else {
69 $string = $this->getValueFromString($string);
70 $has_value = $string;
71 }
72
73 if (!$has_value && $old) {
74 $warning = "(" . $row . ", " . ilDataCollectionImporter::getExcelCharForInteger($col + 1) . ") " . $lng->txt("dcl_no_such_reference") . " "
75 . $old;
76
77 return array('warning' => $warning);
78 }
79
80 return $string;
81 }
82
83
95 protected function getMultipleValuesFromString($stringValues)
96 {
97 $delimiter = strpos($stringValues, '; ') ? '; ' : ', ';
98 $slicedStrings = explode($delimiter, $stringValues);
99 $slicedReferences = array();
100 $resolved = 0;
101 for ($i = 0; $i < count($slicedStrings); $i++) {
102 //try to find a reference since the last resolved value separated by a comma.
103 // $i = 1; $resolved = 0; $string = "hello, world, gaga" -> try to match "hello, world".
104 $searchString = implode(array_slice($slicedStrings, $resolved, $i - $resolved + 1));
105 if ($ref = $this->getValueFromString($searchString)) {
106 $slicedReferences[] = $ref;
107 $resolved = $i;
108 continue;
109 }
110
111 //try to find a reference with the current index.
112 // $i = 1; $resolved = 0; $string = "hello, world, gaga" -> try to match "world".
113 $searchString = $slicedStrings[$i];
114 if ($ref = $this->getValueFromString($searchString)) {
115 $slicedReferences[] = $ref;
116 $resolved = $i;
117 continue;
118 }
119 }
120
121 return $slicedReferences;
122 }
123
124
132 protected function getValueFromString($string)
133 {
134 $options = $this->getField()->getProperty(static::PROP_SELECTION_OPTIONS);
135 foreach ($options as $opt) {
137 if ($opt->getValue() == $string) {
138 return $opt->getOptId();
139 }
140 }
141
142 return null;
143 }
144}
$warning
Definition: X509warning.php:13
An exception for terminatinating execution or to throw for unit testing.
static getValues($field_id, $opt_ids)
Class ilDclSelectionRecordFieldModel.
getMultipleValuesFromString($stringValues)
Copied from reference field and slightly adjusted.
$i
Definition: disco.tpl.php:19
$row
if(isset($_POST['submit'])) $form
global $DIC
Definition: saml.php:7
$delimiter
Definition: showstats.php:16
$values