Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
AttachArray.php
1
<?php
2
3
namespace
Bitrix\Im\V2\Message\Param
;
4
5
use
Bitrix\Im\Text
;
6
use
Bitrix\Main\ArgumentException
;
7
use
Bitrix\Im\V2\Message\Param
;
8
use
Bitrix\Im\V2\Message\ParamArray
;
9
use
Bitrix\Im\V2\Result
;
10
11
class
AttachArray
extends
ParamArray
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
}
Bitrix\Im\Text
Definition
text.php:9
Bitrix\Im\V2\Message\Param\AttachArray
Definition
AttachArray.php:12
Bitrix\Im\V2\Message\Param\AttachArray\toPullFormat
toPullFormat()
Definition
AttachArray.php:117
Bitrix\Im\V2\Message\Param\AttachArray\setValue
setValue($values)
Definition
AttachArray.php:17
Bitrix\Im\V2\Message\Param\AttachArray\addValue
addValue($value)
Definition
AttachArray.php:49
Bitrix\Im\V2\Message\Param\AttachArray\getValue
getValue()
Definition
AttachArray.php:90
Bitrix\Im\V2\Message\Param\AttachArray\toRestFormat
toRestFormat()
Definition
AttachArray.php:108
Bitrix\Im\V2\Message\Param\Attach
Definition
Attach.php:10
Bitrix\Im\V2\Message\ParamArray
Definition
ParamArray.php:22
Bitrix\Im\V2\Message\ParamArray\getName
getName()
Definition
ParamArray.php:333
Bitrix\Im\V2\Message\ParamArray\getMessageId
getMessageId()
Definition
ParamArray.php:308
Bitrix\Im\V2\Message\ParamArray\isValid
isValid()
Definition
ParamArray.php:366
Bitrix\Im\V2\Message\ParamArray\markChanged
markChanged(?bool $state=null)
Definition
ParamArray.php:390
Bitrix\Im\V2\Message\Param\TYPE_JSON
const TYPE_JSON
Definition
Param.php:33
Bitrix\Im\V2\Result
Definition
Result.php:9
Bitrix\Main\ArgumentException
Definition
exception.php:34
Bitrix\Im\V2\Message\Param
Definition
Attach.php:3
Bitrix\Main\Type
Definition
collection.php:2
Bitrix
modules
im
lib
V2
Message
Param
AttachArray.php
Создано системой
1.10.0