Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
lastused.php
1
<?php
2
namespace
Bitrix\Landing\Update\Block
;
3
4
use
Bitrix\Landing\Internals\BlockTable
;
5
use
Bitrix\Main\Application
;
6
use
Bitrix\Main\Config\Option
;
7
use
Bitrix\Main\Update\Stepper
;
8
9
class
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'
,
64
new
\
Bitrix
\Main\
Entity
\
ExpressionField
(
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
}
Bitrix\Landing\Internals\BlockTable
Definition
block.php:26
Bitrix\Landing\Update\Block\LastUsed
Definition
lastused.php:10
Bitrix\Landing\Update\Block\LastUsed\OPTION_CODE
const OPTION_CODE
Definition
lastused.php:11
Bitrix\Landing\Update\Block\LastUsed\execute
execute(array &$option)
Definition
lastused.php:51
Bitrix\Landing\Update\Block\LastUsed\$moduleId
static $moduleId
Definition
lastused.php:17
Bitrix\Main\Application
Definition
application.php:28
Bitrix\Main\Application\getConnection
static getConnection($name="")
Definition
application.php:611
Bitrix\Main\Config\Option
Definition
option.php:15
Bitrix\Main\ORM\Entity
Definition
entity.php:26
Bitrix\Main\ORM\Fields\ExpressionField
Definition
expressionfield.php:25
Bitrix\Main\Update\Stepper
Definition
stepper.php:27
Bitrix\Landing\Update\Block
Definition
buttons.php:3
Bitrix
modules
landing
lib
update
block
lastused.php
Создано системой
1.10.0