Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
contactlistupdateservice.php
1<?php
2
4
10
12{
22 public function updateByCollection(UpdateContactDtoCollection $collection, int $listId): void
23 {
24 $codesByType = [];
25 foreach ($collection->all() as $updateItem)
26 {
27 $codesByType[$updateItem->typeId][] = $updateItem->code;
28 }
29 $sqlHelper = Application::getConnection()->getSqlHelper();
30
31 foreach ($codesByType as $typeId => $allCodes)
32 {
33 $typeId = (int)$typeId;
34 $listId = (int)$listId;
35 $contactTableName = ContactTable::getTableName();
36 $contactListTableName = ContactListTable::getTableName();
37 foreach (SqlBatch::divide($allCodes) as $codes)
38 {
39 $codes = SqlBatch::getInString($codes);
40
41 $fields = '(CONTACT_ID, LIST_ID) ';
42 $subSelect = "SELECT ID AS CONTACT_ID, $listId as LIST_ID ";
43 $subSelect .= "FROM $contactTableName ";
44 $subSelect .= "WHERE TYPE_ID=$typeId AND CODE in ($codes)";
45 $sql = $sqlHelper->getInsertIgnore($contactListTableName, $fields, $subSelect);
46 Application::getConnection()->query($sql);
47 }
48 }
49 }
50}
static getConnection($name="")
updateByCollection(UpdateContactDtoCollection $collection, int $listId)