Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
EditMapAction.php
1
<?php
2
3
namespace
Bitrix\Landing\History\Action
;
4
5
use
Bitrix\Landing\Block
;
6
use
Bitrix\Landing\Node
;
7
use
Bitrix\Main\Text\Encoding
;
8
use
Bitrix\Main\Web\Json
;
9
10
class
EditMapAction
extends
BaseAction
11
{
12
protected
const
JS_COMMAND
=
'editMap'
;
13
14
public
function
execute
(
bool
$undo =
true
): bool
15
{
16
$block =
new
Block
((
int
)$this->params[
'block'
]);
17
$selector = $this->params[
'selector'
] ?:
''
;
18
$position = (int)($this->params[
'position'
] ?: 0);
19
$value = $undo ? $this->params[
'valueBefore'
] : $this->params[
'valueAfter'
];
20
21
if
($selector)
22
{
23
$doc = $block->getDom();
24
$resultList = $doc->querySelectorAll($selector);
25
if
(isset($resultList[$position]))
26
{
27
Node\Map::saveNode($block, $selector, [
28
$position => $value
29
]);
30
31
$block->saveContent($doc->saveHTML());
32
33
return
$block->save();
34
}
35
}
36
37
return
false
;
38
}
39
40
public
static
function
enrichParams
(array
$params
): array
41
{
45
$block =
$params
[
'block'
];
46
47
return
[
48
'block'
=> $block->getId(),
49
'selector'
=>
$params
[
'selector'
] ?:
''
,
50
'position'
=>
$params
[
'position'
] ?: 0,
51
'lid'
=> $block->getLandingId(),
52
'valueAfter'
=>
$params
[
'valueAfter'
] ?:
''
,
53
'valueBefore'
=>
$params
[
'valueBefore'
] ?:
''
,
54
];
55
}
56
61
public
function
getJsCommand
(
bool
$undo =
true
): array
62
{
63
$params
= parent::getJsCommand($undo);
64
65
$params
[
'params'
][
'selector'
] .=
'@'
.
$params
[
'params'
][
'position'
];
66
$params
[
'params'
][
'value'
] =
67
$undo
68
?
$params
[
'params'
][
'valueBefore'
]
69
:
$params
[
'params'
][
'valueAfter'
]
70
;
71
$params
[
'params'
][
'value'
] = Encoding::convertEncoding(
$params
[
'params'
][
'value'
], SITE_CHARSET,
'UTF-8'
);
72
$params
[
'params'
][
'value'
] = Json::decode(
$params
[
'params'
][
'value'
]);
73
74
unset(
75
$params
[
'params'
][
'valueAfter'
],
76
$params
[
'params'
][
'valueBefore'
],
77
$params
[
'params'
][
'position'
],
78
);
79
80
return
$params
;
81
}
82
89
public
static
function
compareParams
(array $oldParams, array $newParams): bool
90
{
91
unset($oldParams[
'valueBefore'
], $newParams[
'valueBefore'
]);
92
93
return
$oldParams === $newParams;
94
}
95
}
Bitrix\Landing\Block
Definition
block.php:21
Bitrix\Landing\History\Action\BaseAction
Definition
BaseAction.php:5
Bitrix\Landing\History\Action\BaseAction\$params
array $params
Definition
BaseAction.php:7
Bitrix\Landing\History\Action\BaseAction\enrichParams
static enrichParams(array $params)
Bitrix\Landing\History\Action\EditMapAction
Definition
EditMapAction.php:11
Bitrix\Landing\History\Action\EditMapAction\getJsCommand
getJsCommand(bool $undo=true)
Definition
EditMapAction.php:61
Bitrix\Landing\History\Action\EditMapAction\compareParams
static compareParams(array $oldParams, array $newParams)
Definition
EditMapAction.php:89
Bitrix\Landing\History\Action\EditMapAction\execute
execute(bool $undo=true)
Definition
EditMapAction.php:14
Bitrix\Landing\History\Action\EditMapAction\JS_COMMAND
const JS_COMMAND
Definition
EditMapAction.php:12
Bitrix\Main\Text\Encoding
Definition
encoding.php:8
Bitrix\Main\Web\Json
Definition
json.php:11
Bitrix\Landing\Block
Definition
cache.php:2
Bitrix\Landing\History\Action
Definition
AddBlockAction.php:3
Bitrix\Landing\Node
Definition
component.php:2
modules
landing
lib
History
Action
EditMapAction.php
Создано системой
1.10.0