Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
commandtrait.php
1<?php
2
4
5
9
10trait CommandTrait
11{
12 public static function reset(int $userId = 0, array $types = [], array $logIds = [], array $groupIds = [], array $exceptGroups = []): void
13 {
14 $where = [];
15
16 if ($userId)
17 {
18 $where[] = 'USER_ID = ' . $userId;
19 }
20
21 if (!empty($types))
22 {
23 $where[] = "TYPE IN ('". implode("','", $types) ."')";
24 }
25
26 if (!empty($logIds))
27 {
28 $where[] = "SONET_LOG_ID IN (". implode(",", $logIds) .")";
29 }
30
31 if (!empty($groupIds))
32 {
33 $where[] = "GROUP_ID IN (". implode(",", $groupIds) .")";
34 }
35
36 if (!empty($exceptGroups))
37 {
38 $where[] = "GROUP_ID NOT IN (". implode(",", $exceptGroups) .")";
39 }
40
41 $where = (!empty($where)) ? ('WHERE ' . implode(' AND ', $where)) : '';
42
43 $sql = "
44 DELETE
46 {$where}
47 ";
48
49 Application::getConnection()->query($sql);
50 }
51
52 private function saveFlag(int $userId): void
53 {
54 $sql = "
55 INSERT INTO ". CounterTable::getTableName() ."
56 (USER_ID, SONET_LOG_ID, GROUP_ID, TYPE, VALUE)
57 VALUES ({$userId}, 0, 0, '". CounterDictionary::COUNTER_FLAG_COUNTED ."', 1)
58 ";
59 Application::getConnection()->query($sql);
60 }
61
62 private function batchInsert(array $data): void
63 {
64 $req = [];
65 foreach ($data as $row)
66 {
67 $row['TYPE'] = "'". $row['TYPE'] ."'";
68 $req[] = implode(',', $row);
69 }
70
71 if (empty($req))
72 {
73 return;
74 }
75
76 $sql = "
77 INSERT INTO ". CounterTable::getTableName(). "
78 (USER_ID, SONET_LOG_ID, GROUP_ID, TYPE, VALUE)
79 VALUES
80 (". implode("),(", $req) .")
81 ";
82
83 Application::getConnection()->query($sql);
84 }
85}
static getConnection($name="")