Bitrix-D7
20.5.0
sale/lib/result.php
См. документацию.
1
<?php
2
namespace
Bitrix\Sale;
3
4
use
Bitrix\Main\Entity
;
5
use
Bitrix\Main\Error
;
6
use
Bitrix\Main\ErrorCollection
;
7
8
class
Result
extends
Entity\Result
9
{
10
/** @var int */
11
protected
$id
;
12
13
protected
$warnings
= array();
14
15
/** @var bool */
16
protected
$isSuccess
=
true
;
17
18
public
function
__construct
()
19
{
20
$this->warnings =
new
ErrorCollection
();
21
parent::__construct
();
22
}
23
24
public
function
setId
($id)
25
{
26
$this->
id
=
$id
;
27
}
28
29
/**
30
* Returns id of added record
31
* @return int
32
*/
33
public
function
getId
()
34
{
35
return
$this->id;
36
}
37
38
public
function
__destruct
()
39
{
40
//just quietly die in contrast Entity\Result either checked errors or not.
41
}
42
43
public
function
addData
(array $data)
44
{
45
if
(is_array($this->data))
46
{
47
$this->data = $this->data + $data;
48
}
49
else
50
{
51
$this->data = $data;
52
}
53
}
54
55
public
function
get
($offset)
56
{
57
if
(isset($this->data[$offset]) || array_key_exists($offset, $this->data))
58
{
59
return
$this->data[$offset];
60
}
61
62
return
null
;
63
}
64
65
public
function
set
($offset, $value)
66
{
67
if
($offset ===
null
)
68
{
69
$this->data[] = $value;
70
}
71
else
72
{
73
$this->data[$offset] = $value;
74
}
75
}
76
77
/**
78
* @param Error[] $errors
79
*
80
* @return void
81
*/
82
public
function
addWarnings
(array $errors)
83
{
84
/** @var Error $error */
85
foreach
($errors as $error)
86
{
87
$this->
addWarning
(
ResultWarning::create
($error));
88
}
89
}
90
91
/**
92
* Adds the error.
93
*
94
* @param Error $error
95
*/
96
public
function
addWarning
(
Error
$error)
97
{
98
$this->warnings[] = $error;
99
}
100
101
/**
102
* Adds the error.
103
*
104
* @param Error $error
105
* @return Result
106
*/
107
public
function
addError
(
Error
$error)
108
{
109
if
($error instanceof
ResultWarning
)
110
{
111
static::addWarning($error);
112
}
113
else
114
{
115
$this->isSuccess =
false
;
116
$this->errors[] = $error;
117
}
118
119
return
$this;
120
}
121
122
/**
123
* Returns an array of Error objects.
124
*
125
* @return Error[]
126
*/
127
public
function
getWarnings
()
128
{
129
return
$this->warnings->toArray();
130
}
131
132
/**
133
* Returns array of strings with warning messages
134
*
135
* @return array
136
*/
137
public
function
getWarningMessages
()
138
{
139
$messages = array();
140
141
foreach
($this->
getWarnings
() as $warning)
142
$messages[] = $warning->getMessage();
143
144
return
$messages;
145
}
146
147
148
/**
149
* @return bool
150
*/
151
public
function
hasWarnings
()
152
{
153
return
(count($this->warnings));
154
}
155
156
157
}
158
159
class
ResultError
160
extends
Entity\EntityError
161
{
162
/**
163
* @param Error $error
164
*
165
* @return static
166
*/
167
public
static
function
create
(
Error
$error)
168
{
169
return
new
static
($error->
getMessage
(), $error->
getCode
());
170
}
171
}
172
173
class
ResultWarning
174
extends
ResultError
175
{
176
177
}
178
179
class
ResultNotice
180
extends
ResultError
181
{
182
183
}
Bitrix\Main\DB\Result
Definition:
main/lib/db/result.php:19
Bitrix\Main\ErrorCollection
Definition:
main/lib/errorcollection.php:14
Bitrix\Main\Error
Definition:
main/lib/error.php:12
Bitrix\Main\Error\getMessage
getMessage()
Returns the message of the error.
Definition:
main/lib/error.php:51
Bitrix\Main\Error\getCode
getCode()
Returns the code of the error.
Definition:
main/lib/error.php:42
Bitrix\Main\ORM\Entity
Base entity.
Definition:
main/lib/orm/entity.php:26
Bitrix\Sale\ResultError
Definition:
sale/lib/result.php:161
Bitrix\Sale\ResultError\create
static create(Error $error)
Definition:
sale/lib/result.php:167
Bitrix\Sale\Result\addError
addError(Error $error)
Adds the error.
Definition:
sale/lib/result.php:107
Bitrix\Sale\Result\__construct
__construct()
Definition:
sale/lib/result.php:18
Bitrix\Sale\Result\getId
getId()
Returns id of added record.
Definition:
sale/lib/result.php:33
Bitrix\Sale\Result\$isSuccess
$isSuccess
Definition:
sale/lib/result.php:16
Bitrix\Sale\Result\__destruct
__destruct()
Definition:
sale/lib/result.php:38
Bitrix\Sale\Result\$warnings
$warnings
Definition:
sale/lib/result.php:13
Bitrix\Sale\Result\addData
addData(array $data)
Definition:
sale/lib/result.php:43
Bitrix\Sale\Result\addWarning
addWarning(Error $error)
Adds the error.
Definition:
sale/lib/result.php:96
Bitrix\Sale\Result\setId
setId($id)
Definition:
sale/lib/result.php:24
Bitrix\Sale\Result\getWarningMessages
getWarningMessages()
Returns array of strings with warning messages.
Definition:
sale/lib/result.php:137
Bitrix\Sale\Result\addWarnings
addWarnings(array $errors)
Definition:
sale/lib/result.php:82
Bitrix\Sale\Result\getWarnings
getWarnings()
Returns an array of Error objects.
Definition:
sale/lib/result.php:127
Bitrix\Sale\Result\hasWarnings
hasWarnings()
Definition:
sale/lib/result.php:151
Bitrix\Sale\Result\$id
$id
Definition:
sale/lib/result.php:11
Bitrix\Sale\ResultNotice
Definition:
sale/lib/result.php:181
Bitrix\Sale\ResultWarning
Definition:
sale/lib/result.php:175
Bitrix\Sender\Connector\__construct
__construct(Base $connector)
Constructor.
Definition:
resultview.php:40
modules
sale
lib
result.php
Создано системой
1.9.1