Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
usertypefield.php
1<?php
11
20{
22 protected $isMultiple = false;
23
30 public function cast($value)
31 {
32 if ($this->isMultiple)
33 {
34 if ($value !== false && $value !== null) // empty value for multiple field
35 {
36 //if (!\is_iterable($value)) PHP 7
37 if (!is_array($value) && !($value instanceof \Traversable))
38 {
39 throw new ArgumentException(sprintf(
40 'Expected iterable value for multiple field, but got `%s` instead', gettype($value)
41 ));
42 }
43
44 // array of values
45 foreach ($value as &$_value)
46 {
47 $_value = $this->valueField->getUtmField()->cast($_value);
48 }
49 }
50
51 return $value;
52 }
53 else
54 {
55 return parent::cast($value);
56 }
57 }
58
62 public function getTypeMask()
63 {
65 }
66
72 public function configureMultiple($isMultiple = true)
73 {
74 $this->isMultiple = (bool) $isMultiple;
75 return $this;
76 }
77
81 public function isMultiple()
82 {
83 return $this->isMultiple;
84 }
85
92 public function convertValueToDb($value)
93 {
94 return $this->isMultiple
95 ? $this->getConnection()->getSqlHelper()->convertToDbString($value) // serialized values
96 : parent::convertValueToDb($value);
97 }
98
99 public function getFetchDataModifiers()
100 {
101 $srcField = $this->getBuildFromChains()[0]->getLastElement()->getValue();
102
103 return array_merge(parent::getFetchDataModifiers(), $srcField->getFetchDataModifiers());
104 }
105
106 public function getSaveDataModifiers()
107 {
108 $srcField = $this->getBuildFromChains()[0]->getLastElement()->getValue();
109
110 return array_merge(parent::getSaveDataModifiers(), $srcField->getSaveDataModifiers());
111 }
112}