Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
lastused.php
1<?php
3
8
9class LastUsed extends Stepper
10{
11 const OPTION_CODE = 'update_landing_lastused';
12
17 protected static $moduleId = 'landing';
18
24 private static function massInsertBlocks(int $userId): void
25 {
26 $sql = "DELETE FROM b_landing_block_last_used WHERE USER_ID={$userId};";
27 Application::getConnection()->query($sql);
28
29 $sql = "INSERT INTO b_landing_block_last_used (USER_ID, CODE, DATE_CREATE)
30 SELECT
31 CREATED_BY_ID as USER_ID, CODE, MAX(DATE_CREATE) DATE_CREATE
32 FROM
33 b_landing_block
34 WHERE
35 CREATED_BY_ID={$userId}
36 AND PUBLIC='N'
37 AND DELETED='N'
38 GROUP BY
39 CREATED_BY_ID, CODE
40 ORDER BY
41 DATE_CREATE DESC
42 ;";
43 Application::getConnection()->query($sql);
44 }
45
51 public function execute(array &$option): bool
52 {
53 $lastId = Option::get('landing', self::OPTION_CODE, 0);
54
55 if (!isset($option['steps']))
56 {
57 $option['steps'] = 0;
58 }
59
60 // total counts
61 $option['count'] = count(BlockTable::getList([
62 'select' => [
63 'CREATED_BY_ID',
65 'CNT', 'COUNT(*)'
66 )
67 ],
68 'filter' => [
69 '=PUBLIC' => 'N'
70 ],
71 'group' => [
72 'CREATED_BY_ID'
73 ]
74 ])->fetchAll());
75
76 // current step
77 $finished = true;
78 $resBlocks = BlockTable::getList([
79 'select' => [
80 'CREATED_BY_ID'
81 ],
82 'filter' => [
83 '=PUBLIC' => 'N',
84 '>CREATED_BY_ID' => $option['steps']
85 ],
86 'group' => [
87 'CREATED_BY_ID'
88 ],
89 'order' => [
90 'CREATED_BY_ID' => 'asc'
91 ]
92 ]);
93 if ($row = $resBlocks->fetch())
94 {
95 $finished = false;
96 $option['steps']++;
97 self::massInsertBlocks($row['CREATED_BY_ID']);
98 }
99
100 if (!$finished)
101 {
102 Option::set('landing', self::OPTION_CODE, $lastId);
103 return true;
104 }
105 else
106 {
107 Option::delete('landing', ['name' => self::OPTION_CODE]);
108 return false;
109 }
110 }
111}
static getConnection($name="")