Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
numeratorsequence.php
1
<?php
2
namespace
Bitrix\Main\Numerator\Model
;
3
4
use
Bitrix\Main\DB\SqlQueryException
;
5
use Bitrix\Main\Entity\DataManager;
6
use Bitrix\Main\Entity\IntegerField;
7
use Bitrix\Main\Entity\StringField;
8
use
Bitrix\Main\Application
;
9
use
Bitrix\Main\Result
;
10
28
class
NumeratorSequenceTable
extends
DataManager
29
{
33
public
static
function
getTableName
()
34
{
35
return
'b_numerator_sequence'
;
36
}
37
42
public
static
function
getMap
()
43
{
44
return
[
45
(
new
IntegerField(
'NUMERATOR_ID'
))
46
->configureRequired(
true
)
47
->configurePrimary(
true
)
48
,
49
(
new
StringField(
'KEY'
))
50
->configureRequired(
true
)
51
->configurePrimary(
true
)
52
,
53
(
new
StringField(
'TEXT_KEY'
))
54
->configureRequired(
true
)
55
,
56
(
new
IntegerField(
'NEXT_NUMBER'
)),
57
(
new
IntegerField(
'LAST_INVOCATION_TIME'
))
58
->configureRequired(
true
)
59
,
60
];
61
}
62
71
public
static
function
updateSettings
($numeratorId, $numberHash, $fields, $whereNextNumber =
null
)
72
{
73
if
($whereNextNumber)
74
{
75
$conn =
Application::getConnection
();
76
$helper = $conn->getSqlHelper();
77
$update = $helper->prepareUpdate(static::getTableName(), $fields);
78
$query =
'UPDATE '
. $helper->quote(static::getTableName())
79
.
' SET '
. $update[0]
80
.
' WHERE NUMERATOR_ID = '
. intval($numeratorId)
81
.
' AND '
. $helper->quote(
'KEY'
) .
' = '
. $helper->convertToDbString(md5($numberHash))
82
.
' AND NEXT_NUMBER = '
. intval($whereNextNumber);
83
$conn->query($query);
84
85
return
$conn->getAffectedRowsCount();
86
}
87
$res = static::update([
88
'NUMERATOR_ID'
=> intval($numeratorId),
89
'KEY'
=> md5($numberHash),
90
], $fields);
91
if
($res->isSuccess())
92
{
93
return
$res->getAffectedRowsCount();
94
}
95
96
return
0;
97
}
98
103
public
static
function
deleteByNumeratorId
($id)
104
{
105
$result =
new
Result
();
106
107
$list = static::getList([
108
'filter'
=> [
109
'=NUMERATOR_ID'
=> (
int
)$id,
110
]
111
]);
112
while
($row = $list->fetchObject())
113
{
114
$deleteResult = $row->delete();
115
if
(!$deleteResult->isSuccess())
116
{
117
$result->addErrors($deleteResult->getErrors());
118
}
119
}
120
121
return
$result;
122
}
123
132
public
static
function
getSettings
($numeratorId, $numberHash)
133
{
134
$sequenceSettings = static::getList([
135
'select'
=> [
'NEXT_NUMBER'
,
'LAST_INVOCATION_TIME'
],
136
'filter'
=> [
'=NUMERATOR_ID'
=> $numeratorId,
'=KEY'
=> md5($numberHash),],
137
])->fetch();
138
return
$sequenceSettings;
139
}
140
149
public
static
function
setSettings
($numeratorId, $numberHash, $defaultNumber, $lastInvocationTime)
150
{
151
try
152
{
153
$result = static::add([
154
'NUMERATOR_ID'
=> $numeratorId,
155
'KEY'
=> md5($numberHash),
156
'TEXT_KEY'
=> mb_substr($numberHash, 0, 50),
157
'LAST_INVOCATION_TIME'
=> $lastInvocationTime,
158
'NEXT_NUMBER'
=> $defaultNumber,
159
]);
160
if
($result->isSuccess())
161
{
162
return
$result->getData();
163
}
164
return
[];
165
}
166
catch
(
SqlQueryException
$exc)
167
{
168
if
(mb_stripos($exc->getMessage(),
"Duplicate entry"
) !==
false
)
169
{
170
return
[];
171
}
172
throw
$exc;
173
}
174
}
175
}
Bitrix\Main\Application
Definition
application.php:28
Bitrix\Main\Application\getConnection
static getConnection($name="")
Definition
application.php:611
Bitrix\Main\DB\SqlQueryException
Definition
sqlexception.php:24
Bitrix\Main\Numerator\Model\NumeratorSequenceTable
Definition
numeratorsequence.php:29
Bitrix\Main\Numerator\Model\NumeratorSequenceTable\getMap
static getMap()
Definition
numeratorsequence.php:42
Bitrix\Main\Numerator\Model\NumeratorSequenceTable\setSettings
static setSettings($numeratorId, $numberHash, $defaultNumber, $lastInvocationTime)
Definition
numeratorsequence.php:149
Bitrix\Main\Numerator\Model\NumeratorSequenceTable\deleteByNumeratorId
static deleteByNumeratorId($id)
Definition
numeratorsequence.php:103
Bitrix\Main\Numerator\Model\NumeratorSequenceTable\getSettings
static getSettings($numeratorId, $numberHash)
Definition
numeratorsequence.php:132
Bitrix\Main\Numerator\Model\NumeratorSequenceTable\updateSettings
static updateSettings($numeratorId, $numberHash, $fields, $whereNextNumber=null)
Definition
numeratorsequence.php:71
Bitrix\Main\Numerator\Model\NumeratorSequenceTable\getTableName
static getTableName()
Definition
numeratorsequence.php:33
Bitrix\Main\ORM\Data\Result
Definition
result.php:16
Bitrix\Main\Result
Definition
result.php:14
Bitrix\Main\Numerator\Model
Definition
numerator.php:2
modules
main
lib
numerator
model
numeratorsequence.php
Создано системой
1.10.0