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