ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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
19 public function getValue()
20 {
21 if ($this->getField()->isMulti() && !is_array($this->value)) {
22 return array($this->value);
23 }
24 if (!$this->getField()->isMulti() && is_array($this->value)) {
25 return (count($this->value) == 1) ? array_shift($this->value) : '';
26 }
27 return $this->value;
28 }
29
30
31 public function setValueFromForm($form)
32 {
33 parent::setValueFromForm($form); // TODO: Change the autogenerated stub
34 }
35
36
42 public function parseExportValue($value)
43 {
45 return is_array($values) ? implode("; ", $values) : $values;
46 }
47
48
56 public function getValueFromExcel($excel, $row, $col)
57 {
58 global $DIC;
59 $lng = $DIC['lng'];
60 $string = parent::getValueFromExcel($excel, $row, $col);
61 $old = $string;
62 if ($this->getField()->isMulti()) {
63 $string = $this->getMultipleValuesFromString($string);
64 $has_value = count($string);
65 } else {
66 $string = $this->getValueFromString($string);
67 $has_value = $string;
68 }
69
70 if (!$has_value && $old) {
71 $warning = "(" . $row . ", " . ilDataCollectionImporter::getExcelCharForInteger($col+1) . ") " . $lng->txt("dcl_no_such_reference") . " "
72 . $old;
73 return array('warning' => $warning);
74 }
75
76 return $string;
77 }
78
88 protected function getMultipleValuesFromString($stringValues)
89 {
90 $delimiter = strpos($stringValues, '; ') ? '; ' : ', ';
91 $slicedStrings = explode($delimiter, $stringValues);
92 $slicedReferences = array();
93 $resolved = 0;
94 for ($i = 0; $i < count($slicedStrings); $i++) {
95 //try to find a reference since the last resolved value separated by a comma.
96 // $i = 1; $resolved = 0; $string = "hello, world, gaga" -> try to match "hello, world".
97 $searchString = implode(array_slice($slicedStrings, $resolved, $i - $resolved + 1));
98 if ($ref = $this->getValueFromString($searchString)) {
99 $slicedReferences[] = $ref;
100 $resolved = $i;
101 continue;
102 }
103
104 //try to find a reference with the current index.
105 // $i = 1; $resolved = 0; $string = "hello, world, gaga" -> try to match "world".
106 $searchString = $slicedStrings[$i];
107 if ($ref = $this->getValueFromString($searchString)) {
108 $slicedReferences[] = $ref;
109 $resolved = $i;
110 continue;
111 }
112 }
113 return $slicedReferences;
114 }
115
116
124 protected function getValueFromString($string)
125 {
126 $options = $this->getField()->getProperty(static::PROP_SELECTION_OPTIONS);
127 foreach ($options as $opt) {
129 if ($opt->getValue() == $string) {
130 return $opt->getOptId();
131 }
132 }
133 return null;
134 }
135}
$warning
Definition: X509warning.php:13
if(!isset( $_REQUEST[ 'ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Definition: as_login.php:20
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
if(isset($_POST['submit'])) $form
$old
global $DIC
Definition: saml.php:7
$delimiter
Definition: showstats.php:16