Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
agentcontracttable.php
1
<?php
2
namespace
Bitrix\Catalog
;
3
4
use
Bitrix\Main\Application
;
5
use Bitrix\Main\Entity\EventResult;
6
use
Bitrix\Main\Localization\Loc
;
7
use
Bitrix\Main\ORM\Data\DataManager
;
8
use
Bitrix\Main\ORM\Event
;
9
use
Bitrix\Main\ORM\Fields\DatetimeField
;
10
use
Bitrix\Main\ORM\Fields\IntegerField
;
11
use
Bitrix\Main\ORM\Fields\StringField
;
12
use
Bitrix\Main\ORM\Fields\Validators\LengthValidator
;
13
use
Bitrix\Main\Type\DateTime
;
14
use
Bitrix\Main\ORM\Fields\Relations\Reference
;
15
use
Bitrix\Main\ORM\Query\Join
;
16
use
Bitrix\Main\UserTable
;
17
use
Bitrix\Main\Type\Collection
;
18
use
Bitrix\Main\ORM\Query\Query
;
19
use
Bitrix\Catalog\v2\Contractor
;
20
51
class
AgentContractTable
extends
DataManager
52
{
58
public
static
function
getTableName
(): string
59
{
60
return
'b_catalog_agent_contract'
;
61
}
62
68
public
static
function
getMap
(): array
69
{
70
return
[
71
'ID'
=>
new
IntegerField
(
72
'ID'
,
73
[
74
'primary'
=>
true
,
75
'autocomplete'
=>
true
,
76
'title'
=>
Loc::getMessage
(
'CATALOG_AGENT_CONTRACT_ENTITY_ID_FIELD'
),
77
]
78
),
79
'AGENT_PRODUCT'
=>
new
Reference
(
80
'AGENT_PRODUCT'
,
81
AgentProductTable::class,
82
Join::on(
'this.ID'
,
'ref.CONTRACT_ID'
)
83
),
84
'TITLE'
=>
new
StringField
(
85
'TITLE'
,
86
[
87
'required'
=>
true
,
88
'validation'
=>
function
()
89
{
90
return
[
91
new
LengthValidator
(
null
, 255),
92
];
93
},
94
'title'
=>
Loc::getMessage
(
'CATALOG_AGENT_CONTRACT_ENTITY_TITLE_FIELD'
),
95
]
96
),
97
'CONTRACTOR_ID'
=>
new
IntegerField
(
98
'CONTRACTOR_ID'
,
99
[
100
'title'
=>
Loc::getMessage
(
'CATALOG_AGENT_CONTRACT_ENTITY_CONTRACTOR_ID_FIELD'
),
101
]
102
),
103
'CONTRACTOR'
=>
new
Reference
(
104
'CONTRACTOR'
,
105
ContractorTable::class,
106
Join::on(
'this.CONTRACTOR_ID'
,
'ref.ID'
)
107
),
108
'DATE_MODIFY'
=>
new
DatetimeField
(
109
'DATE_MODIFY'
,
110
[
111
'title'
=>
Loc::getMessage
(
'CATALOG_AGENT_CONTRACT_ENTITY_DATE_MODIFY_FIELD'
),
112
]
113
),
114
'DATE_CREATE'
=>
new
DatetimeField
(
115
'DATE_CREATE'
,
116
[
117
'title'
=>
Loc::getMessage
(
'CATALOG_AGENT_CONTRACT_ENTITY_DATE_CREATE_FIELD'
),
118
'default_value'
=>
new
DateTime
(),
119
]
120
),
121
'MODIFIED_BY'
=>
new
IntegerField
(
122
'MODIFIED_BY'
,
123
[
124
'title'
=>
Loc::getMessage
(
'CATALOG_AGENT_CONTRACT_ENTITY_MODIFIED_BY_FIELD'
),
125
]
126
),
127
'MODIFIED_BY_USER'
=>
new
Reference
(
128
'MODIFIED_BY_USER'
,
129
UserTable::class,
130
Join::on(
'this.MODIFIED_BY'
,
'ref.ID'
)
131
),
132
'CREATED_BY'
=>
new
IntegerField
(
133
'CREATED_BY'
,
134
[
135
'title'
=>
Loc::getMessage
(
'CATALOG_AGENT_CONTRACT_ENTITY_CREATED_BY_FIELD'
),
136
]
137
),
138
'CREATED_BY_USER'
=>
new
Reference
(
139
'CREATED_BY_USER'
,
140
UserTable::class,
141
Join::on(
'this.CREATED_BY'
,
'ref.ID'
)
142
),
143
];
144
}
145
146
public
static
function
withProductList
(
Query
$query, array $productIds)
147
{
148
Collection::normalizeArrayValuesByInt($productIds);
149
if
(empty($productIds))
150
{
151
return
;
152
}
153
154
$tableName =
AgentProductTable::getTableName
();
155
$whereExpression =
'(PRODUCT_ID IN ('
. implode(
','
, $productIds) .
'))'
;
156
157
$connection =
Application::getConnection
();
158
$helper = $connection->getSqlHelper();
159
$productType = $helper->forSql(
AgentProductTable::PRODUCT_TYPE_PRODUCT
);
160
161
$query->whereExpr(
"
162
(
163
CASE WHEN EXISTS (
164
SELECT ID
165
FROM {$tableName}
166
WHERE CONTRACT_ID = %s
167
AND PRODUCT_TYPE = '{$productType}'
168
AND {$whereExpression}
169
)
170
THEN 1
171
ELSE 0
172
END
173
) = 1
174
"
, [
'ID'
]);
175
}
176
177
public
static
function
withSectionList
(
Query
$query, array $sectionIds)
178
{
179
Collection::normalizeArrayValuesByInt($sectionIds);
180
if
(empty($sectionIds))
181
{
182
return
;
183
}
184
185
$tableName =
AgentProductTable::getTableName
();
186
$whereExpression =
'(PRODUCT_ID IN ('
. implode(
','
, $sectionIds) .
'))'
;
187
188
$connection =
Application::getConnection
();
189
$helper = $connection->getSqlHelper();
190
$productType = $helper->forSql(
AgentProductTable::PRODUCT_TYPE_SECTION
);
191
192
$query->whereExpr(
"
193
(
194
CASE WHEN EXISTS (
195
SELECT ID
196
FROM {$tableName}
197
WHERE CONTRACT_ID = %s
198
AND PRODUCT_TYPE = '{$productType}'
199
AND {$whereExpression}
200
)
201
THEN 1
202
ELSE 0
203
END
204
) = 1
205
"
, [
'ID'
]);
206
}
207
208
public
static
function
onBeforeAdd
(
Event
$event)
209
{
210
$result =
new
EventResult
;
211
$data = $event->
getParameter
(
'fields'
);
212
213
if
(empty($data[
'TITLE'
]))
214
{
215
$result->modifyFields([
216
'TITLE'
=>
Loc::getMessage
(
'CATALOG_AGENT_CONTRACT_ENTITY_TITLE_DEFAULT'
),
217
]);
218
}
219
220
return
$result;
221
}
222
223
public
static
function
onAfterAdd
(
Event
$event)
224
{
225
$data = $event->
getParameters
();
226
$id = $event->
getParameter
(
'id'
);
227
228
if
($data[
'fields'
][
'TITLE'
] ===
Loc::getMessage
(
'CATALOG_AGENT_CONTRACT_ENTITY_TITLE_DEFAULT'
))
229
{
230
$title =
Loc::getMessage
(
231
'CATALOG_AGENT_CONTRACT_ENTITY_TITLE_DEFAULT'
,
232
[
233
'#'
=> $id,
234
]
235
);
236
237
self::update
(
238
$id,
239
[
240
'TITLE'
=> $title,
241
]
242
);
243
}
244
}
245
246
public
static
function
onAfterDelete
(
Event
$event)
247
{
248
$result =
new
EventResult
();
249
250
$id = (int)$event->
getParameter
(
'primary'
)[
'ID'
];
251
252
$contractorsProvider = Contractor\Provider\Manager::getActiveProvider(
253
Contractor\
Provider
\Manager::PROVIDER_AGENT_CONTRACT
254
);
255
if
($contractorsProvider)
256
{
257
$contractorsProvider::onAfterDocumentDelete($id);
258
}
259
260
// delete files
261
AgentContractFileTable::deleteFilesByContractId
($id);
262
263
return
$result;
264
}
265
}
Bitrix\Catalog\AgentContractFileTable\deleteFilesByContractId
static deleteFilesByContractId(int $contractId)
Definition
agentcontractfiletable.php:94
Bitrix\Catalog\AgentContractTable
Definition
agentcontracttable.php:52
Bitrix\Catalog\AgentContractTable\withProductList
static withProductList(Query $query, array $productIds)
Definition
agentcontracttable.php:146
Bitrix\Catalog\AgentContractTable\getMap
static getMap()
Definition
agentcontracttable.php:68
Bitrix\Catalog\AgentContractTable\withSectionList
static withSectionList(Query $query, array $sectionIds)
Definition
agentcontracttable.php:177
Bitrix\Catalog\AgentContractTable\onAfterAdd
static onAfterAdd(Event $event)
Definition
agentcontracttable.php:223
Bitrix\Catalog\AgentContractTable\onBeforeAdd
static onBeforeAdd(Event $event)
Definition
agentcontracttable.php:208
Bitrix\Catalog\AgentContractTable\onAfterDelete
static onAfterDelete(Event $event)
Definition
agentcontracttable.php:246
Bitrix\Catalog\AgentContractTable\getTableName
static getTableName()
Definition
agentcontracttable.php:58
Bitrix\Catalog\AgentProductTable\PRODUCT_TYPE_SECTION
const PRODUCT_TYPE_SECTION
Definition
agentproducttable.php:42
Bitrix\Catalog\AgentProductTable\PRODUCT_TYPE_PRODUCT
const PRODUCT_TYPE_PRODUCT
Definition
agentproducttable.php:41
Bitrix\Catalog\AgentProductTable\getTableName
static getTableName()
Definition
agentproducttable.php:49
Bitrix\Catalog\Model\Event
Definition
event.php:11
Bitrix\Catalog\Model\EventResult
Definition
eventresult.php:7
Bitrix\Iblock\ORM\Query
Definition
query.php:23
Bitrix\Main\Application
Definition
application.php:28
Bitrix\Main\Application\getConnection
static getConnection($name="")
Definition
application.php:611
Bitrix\Main\Event
Definition
event.php:5
Bitrix\Main\Event\getParameters
getParameters()
Definition
event.php:66
Bitrix\Main\Event\getParameter
getParameter($key)
Definition
event.php:80
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Definition
loc.php:29
Bitrix\Main\ORM\Data\DataManager
Definition
datamanager.php:33
Bitrix\Main\ORM\Data\DataManager\update
static update($primary, array $data)
Definition
datamanager.php:1246
Bitrix\Main\ORM\Fields\DatetimeField
Definition
datetimefield.php:22
Bitrix\Main\ORM\Fields\IntegerField
Definition
integerfield.php:20
Bitrix\Main\ORM\Fields\Relations\Reference
Definition
reference.php:26
Bitrix\Main\ORM\Fields\StringField
Definition
stringfield.php:20
Bitrix\Main\ORM\Fields\Validators\LengthValidator
Definition
lengthvalidator.php:19
Bitrix\Main\ORM\Objectify\Collection
Definition
collection.php:33
Bitrix\Main\ORM\Query\Join
Definition
join.php:19
Bitrix\Main\ORM\Query\Query
Definition
query.php:118
Bitrix\Main\Type\DateTime
Definition
datetime.php:9
Bitrix\Main\UserTable
Definition
user.php:46
Bitrix\Rest\OAuth\Provider
Definition
provider.php:11
Bitrix\Catalog\v2\Contractor
Definition
IConverter.php:3
Bitrix\Catalog
modules
catalog
lib
agentcontracttable.php
Создано системой
1.10.0