21 if (!isset($doc->attributes->attr[$oAttr->id])) {
22 throw new \Dcp\AttributeValue\Exception(
'VALUE0101', $oAttr->id, $doc->fromname, $doc->
getTitle());
25 return self::getMultipleValues($doc, $oAttr);
27 if ($oAttr->type ==
"array") {
28 return self::getArrayValues($doc, $oAttr);
31 return self::castValue($oAttr->type, $rawValue);
37 return self::getMultiple2Values($doc, $oAttr);
41 $typedValues = array();
42 foreach ($rawValues as $rawValue) {
43 $typedValues[] = self::castValue(
$type, $rawValue);
47 foreach ($typedValues as & $v) {
48 $v = str_replace(
'<BR>',
"\n", $v);
60 $typedValues = array();
61 foreach ($rawValues as $rawValue) {
62 $finalValues = ($rawValue !==
'') ? explode(
'<BR>', $rawValue) : array();
63 $finalTypedValues = array();
64 foreach ($finalValues as $finalValue) {
65 $finalTypedValues[] = self::castValue(
$type, $finalValue);
67 $typedValues[] = $finalTypedValues;
78 private static function castValue(
$type, $rawValue)
80 if ($rawValue === null || $rawValue ===
'')
return null;
83 $typedValue = intval($rawValue);
88 $typedValue = doubleval($rawValue);
94 if (strlen($rawValue) == 16) {
97 $typedValue = new \DateTime($isoDate);
101 $typedValue = $rawValue;
102 if (strlen($rawValue) == 5) {
108 $typedValue = $rawValue;
112 private static function typed2string(
$type, $typedValue)
114 if ($typedValue === null || $typedValue ===
'')
return null;
116 if (is_array($typedValue)) {
117 $arrayString = array();
118 foreach ($typedValue as $k => $aSingleValue) {
119 $arrayString[$k] = self::singleTyped2string(
$type, $aSingleValue);
123 return self::singleTyped2string(
$type, $typedValue);
126 private static function singleTyped2string(
$type, $typedValue)
128 if ($typedValue === null || $typedValue ===
'') {
134 if (!is_string($typedValue) && !is_int($typedValue)) {
135 throw new \Dcp\AttributeValue\Exception(
'VALUE0200', print_r($typedValue,
true) , gettype($typedValue));
141 if (!is_string($typedValue) && !is_int($typedValue) && !is_double($typedValue)) {
142 throw new \Dcp\AttributeValue\Exception(
'VALUE0201', print_r($typedValue,
true) , gettype($typedValue));
147 if (is_a($typedValue,
"DateTime")) {
151 $typedValue = $typedValue->format(
'Y-m-d\TH:i:s');
157 if (is_a($typedValue,
"DateTime")) {
161 $typedValue = $typedValue->format(
'Y-m-d');
169 if (!is_scalar($typedValue)) {
170 throw new \Dcp\AttributeValue\Exception(
'VALUE0202', print_r($typedValue,
true) , gettype($typedValue));
177 if ($oAttr->type ==
"array") {
178 $ta = $doc->attributes->getArrayElements($oAttr->id);
182 foreach ($ta as $k => $v) {
183 $tv[$k] = self::getMultipleValues($doc, $doc->
getAttribute($k));
184 $ix = max($ix, count($tv[$k]));
186 for ($i = 0; $i < $ix; $i++) {
189 foreach ($ta as $k => $v) {
190 for ($i = 0; $i < $ix; $i++) {
192 $k => isset($tv[$k][$i]) ? $tv[$k][$i] : null
198 throw new \Dcp\AttributeValue\Exception(
'VALUE0100', $oAttr->id, $doc->title, $doc->fromname);
204 foreach ($value as $row) {
205 if (!is_array($row)) {
206 throw new \Dcp\AttributeValue\Exception(
'VALUE0009', $oAttr->id, $doc->fromname, $doc->
getTitle() , print_r($row,
true));
208 foreach ($row as $columnName => & $columnValue) {
211 $columnValue = self::typed2string($cAttr->type, $columnValue);
217 throw new \Dcp\AttributeValue\Exception(
'VALUE0007', $oAttr->id, $doc->fromname, $doc->
getTitle() ,
$err);
231 if (!isset($doc->attributes->attr[$oAttr->id])) {
232 throw new \Dcp\AttributeValue\Exception(
'VALUE0004', $oAttr->id, $doc->fromname, $doc->
getTitle());
236 if ($value === null) {
237 if ($oAttr->type ==
"array") {
238 self::setTypedArrayValue($doc, $oAttr, array());
244 if (!is_array($value)) {
245 $e = new \Dcp\AttributeValue\Exception(
'VALUE0002', print_r($value,
true) , $oAttr->id, $doc->fromname, $doc->
getTitle());
246 $e->attributeId = $oAttr->id;
249 if ($value === array()) {
253 $rawValues = array();
254 foreach ($value as $k => $rowValues) {
255 if (is_array($rowValues)) {
256 $rawValues[$k] = implode(
'<BR>', $rowValues);
258 if ($rowValues === null) {
261 $e = new \Dcp\AttributeValue\Exception(
'VALUE0003', print_r($value,
true) , $oAttr->id, $doc->fromname, $doc->
getTitle());
262 $e->attributeId = $oAttr->id;
267 $err = $doc->
setValue($oAttr->id, self::typed2string($oAttr->type, $rawValues) , -1, $kindex);
269 $err = $doc->
setValue($oAttr->id, self::typed2string($oAttr->type, $value) , -1, $kindex);
272 } elseif ($oAttr->type ==
"array") {
273 if (!is_array($value)) {
274 $e = new \Dcp\AttributeValue\Exception(
'VALUE0008', $oAttr->id, $doc->fromname, $doc->
getTitle() , print_r($value,
true));
275 $e->attributeId = $oAttr->id;
278 self::setTypedArrayValue($doc, $oAttr, $value);
280 if (is_array($value)) {
281 $e = new \Dcp\AttributeValue\Exception(
'VALUE0006', $oAttr->id, $doc->fromname, $doc->
getTitle() , print_r($value,
true));
282 $e->attributeId = $oAttr->id;
286 $err = $doc->
setValue($oAttr->id, self::typed2string($oAttr->type, $value) , -1, $kindex);
289 $e = new \Dcp\AttributeValue\Exception(
'VALUE0005', $oAttr->id, $doc->fromname, $doc->
getTitle() , $e->getMessage());
290 $e->attributeId = $oAttr->id;
295 $e = new \Dcp\AttributeValue\Exception(
'VALUE0001', $oAttr->id, $doc->fromname, $doc->
getTitle() ,
$err);
296 $e->originalError =
$err;
297 $e->attributeId = $oAttr->id;
clearArrayValues($idAttr)
& getAttribute($idAttr, &$oa=null, $useMask=true)
stringDateToIso($date, $format=false, $withT=false)
static setTypedValue(\Doc &$doc,\NormalAttribute &$oAttr, $value)
addArrayRow($idAttr, $tv, $index=-1)
setValue($attrid, $value, $index=-1, &$kvalue=null)
getMultipleRawValues($idAttr, $def="", $index=-1)
getTitle($id="-1", $def="", $latest=false)
static getTypedValue(\Doc &$doc,\NormalAttribute &$oAttr)
if($file) if($subject==""&&$file) if($subject=="") $err
getRawValue($idAttr, $def="")