1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
AttachArray.php
См. документацию.
1<?php
2
3namespace Bitrix\Im\V2\Message\Param;
4
5use Bitrix\Im\Text;
6use Bitrix\Main\ArgumentException;
7use Bitrix\Im\V2\Message\Param;
8use Bitrix\Im\V2\Message\ParamArray;
9use Bitrix\Im\V2\Result;
10
12{
17 public function setValue($values): self
18 {
19 if (!is_array($values) || \Bitrix\Main\Type\Collection::isAssociative($values))
20 {
21 $values = [$values];
22 }
23
24 foreach ($this as $param)
25 {
26 $param->markDrop();
27 }
28
29 foreach ($values as $value)
30 {
31 if (!$value instanceof \CIMMessageParamAttach)
32 {
33 $value = \CIMMessageParamAttach::GetAttachByJson($value);
34 }
35
36 $this->addValue($value);
37 }
38
39 $this->markChanged();
40
41 return $this;
42 }
43
44
49 public function addValue($value): self
50 {
51 if (!$value instanceof \CIMMessageParamAttach)
52 {
53 $value = \CIMMessageParamAttach::GetAttachByJson($value);
54 }
55
56 $param = new Attach();
57 $param
58 ->setName($this->getName())
59 ->setType(Param::TYPE_JSON)
60 ->setValue($value)
61 ;
62
63 if (!$param->hasValue())
64 {
65 return $this;
66 }
67
68 if ($this->getMessageId())
69 {
70 $param->setMessageId($this->getMessageId());
71 }
72
73 if ($param->getPrimaryId())
74 {
75 $param->setRegistry($this);
76 }
77 else
78 {
79 $this[] = $param;
80 }
81
82 $this->markChanged();
83
84 return $this;
85 }
86
90 public function getValue(): array
91 {
92 $values = [];
93 foreach ($this as $param)
94 {
95 if ($param->isDeleted())
96 {
97 continue;
98 }
99 $values[] = $param->getValue();
100 }
101
102 return $values;
103 }
104
108 public function toRestFormat(): ?array
109 {
110 return $this->getValue();
111 }
112
113
117 public function toPullFormat(): array
118 {
119 $values = [];
120 foreach ($this as $param)
121 {
122 if ($param->isDeleted() || !$param->hasValue())
123 {
124 continue;
125 }
126 $values[] = \CIMMessageParamAttach::PrepareAttach($param->getValue());
127 }
128
129 return $values;
130 }
131
132 public function isValid(): Result
133 {
134 $result = new Result();
135
137 foreach ($this as $attach)
138 {
139 $checkAttachResult = $attach->isValid();
140 if (!$checkAttachResult->isSuccess())
141 {
142 $result->addErrors($checkAttachResult->getErrors());
143 }
144 }
145
146 return $result;
147 }
148}
markChanged(?bool $state=null)
Определения ParamArray.php:394
Определения result.php:20
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
const TYPE_JSON
Определения Param.php:20
Определения collection.php:2