Completed
Push — master ( 704127...e81237 )
by Nekrasov
02:27
created

AdminActions::deleteIBlockElement()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 11
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
c 1
b 0
f 0
nc 2
nop 3
dl 11
loc 11
rs 9.4285
1
<?php
2
3
namespace Arrilot\BitrixBlade;
4
5
use CBitrixComponentTemplate;
6
use CIBlock;
7
use InvalidArgumentException;
8
9
class AdminActions
10
{
11
    protected static $panelButtons = [];
12
13
    /**
14
     * Get edit area id for specific type
15
     *
16
     * @param CBitrixComponentTemplate $template
17
     * @param $type
18
     * @param $element
19
     * @return string
20
     */
21
    public static function getEditArea($template, $type, $element)
22
    {
23
        return $template->GetEditAreaId($type . '_' . $element['ID']);
24
    }
25
26
    /**
27
     * @param CBitrixComponentTemplate $template
28
     * @param $element
29
     */
30 View Code Duplication
    public static function editIBlockElement($template, $element)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
31
    {
32
        if (!$element["IBLOCK_ID"] || !$element['ID']) {
33
            throw new InvalidArgumentException('Element must include ID and IBLOCK_ID');
34
        }
35
36
        $buttons = static::getIBlockElementPanelButtons($element);
37
        $link = $buttons["edit"]["edit_element"]["ACTION_URL"];
38
39
        $template->AddEditAction('iblock_element_' . $element['ID'], $link, CIBlock::GetArrayByID($element["IBLOCK_ID"], "ELEMENT_EDIT"));
40
    }
41
    
42
    /**
43
     * @param CBitrixComponentTemplate $template
44
     * @param $element
45
     * @param string $confirm
46
     */
47 View Code Duplication
    public static function deleteIBlockElement($template, $element, $confirm = 'Вы уверены что хотите удалить элемент?')
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
48
    {
49
        if (!$element["IBLOCK_ID"] || !$element['ID']) {
50
            throw new InvalidArgumentException('Element must include ID and IBLOCK_ID');
51
        }
52
    
53
        $buttons = static::getIBlockElementPanelButtons($element);
54
        $link = $buttons["edit"]["delete_element"]["ACTION_URL"];
55
56
        $template->AddDeleteAction('iblock_element_' . $element['ID'], $link, CIBlock::GetArrayByID($element["IBLOCK_ID"], "ELEMENT_DELETE"), array("CONFIRM" => $confirm));
57
    }
58
59
    /**
60
     * @param CBitrixComponentTemplate $template
61
     * @param $section
62
     */
63 View Code Duplication
    public static function editIBlockSection($template, $section)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
64
    {
65
        if (!$section["IBLOCK_ID"] || !$section['ID']) {
66
            throw new InvalidArgumentException('Section must include ID and IBLOCK_ID');
67
        }
68
    
69
        $buttons = static::getIBlockSectionPanelButtons($section);
70
        $link = $buttons["edit"]["edit_section"]["ACTION_URL"];
71
72
        $template->AddEditAction('iblock_section_' . $section['ID'], $link, CIBlock::GetArrayByID($section["IBLOCK_ID"], "SECTION_EDIT"));
73
    }
74
75
    /**
76
     * @param CBitrixComponentTemplate $template
77
     * @param $section
78
     * @param string $confirm
79
     */
80 View Code Duplication
    public static function deleteIBlockSection($template, $section, $confirm = 'Вы уверены что хотите удалить раздел?')
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
81
    {
82
        if (!$section["IBLOCK_ID"] || !$section['ID']) {
83
            throw new InvalidArgumentException('Section must include ID and IBLOCK_ID');
84
        }
85
    
86
        $buttons = static::getIBlockSectionPanelButtons($section);
87
        $link = $buttons["edit"]["delete_section"]["ACTION_URL"];
88
89
        $template->AddDeleteAction('iblock_section_' . $section['ID'], $link, CIBlock::GetArrayByID($section["IBLOCK_ID"], "SECTION_DELETE"), array("CONFIRM" => $confirm));
90
    }
91
    
92
    /**
93
     * @param CBitrixComponentTemplate $template
94
     * @param $element
95
     * @param string $label
96
     */
97 View Code Duplication
    public static function editHLBlockElement($template, $element, $label = 'Изменить элемент')
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
98
    {
99
        if (!$element["HLBLOCK_ID"] || !$element['ID']) {
100
            throw new InvalidArgumentException('Element must include ID and HLBLOCK_ID');
101
        }
102
103
        $linkTemplate = '/bitrix/admin/highloadblock_row_edit.php?ENTITY_ID=%s&ID=%s&lang=ru&bxpublic=Y';
104
        $link = sprintf($linkTemplate, (int) $element["HLBLOCK_ID"], (int) $element["ID"]);
105
106
        $template->AddEditAction('hlblock_element_' . $element['ID'], $link, $label);
107
    }
108
    
109
    /**
110
     * @param CBitrixComponentTemplate $template
111
     * @param $element
112
     * @param string $label
113
     * @param string $confirm
114
     */
115 View Code Duplication
    public static function deleteHLBlockElement($template, $element, $label = 'Удалить элемент', $confirm = 'Вы уверены что хотите удалить элемент?')
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
116
    {
117
        if (!$element["HLBLOCK_ID"] || !$element['ID']) {
118
            throw new InvalidArgumentException('Element must include ID and HLBLOCK_ID');
119
        }
120
121
        $linkTemplate = '/bitrix/admin/highloadblock_row_edit.php?action=delete&ENTITY_ID=%s&ID=%s&lang=ru&sessid=%s';
122
        $link = sprintf($linkTemplate, (int) $element["HLBLOCK_ID"], (int) $element["ID"], bitrix_sessid_get());
123
    
124
        $template->AddDeleteAction('hlblock_element_' . $element['ID'], $link, $label, array("CONFIRM" => $confirm));
125
    }
126
127
    /**
128
     * @param $element
129
     * @return array
130
     */
131 View Code Duplication
    protected static function getIBlockElementPanelButtons($element)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
132
    {
133
        if (!isset(static::$panelButtons['iblock_element'][$element['ID']])) {
134
            static::$panelButtons['iblock_element'][$element['ID']] = CIBlock::GetPanelButtons(
135
                $element["IBLOCK_ID"],
136
                $element['ID'],
137
                0,
138
                []
139
            );
140
        }
141
142
        return static::$panelButtons['iblock_element'][$element['ID']];
143
    }
144
145
    /**
146
     * @param $section
147
     * @return array
148
     */
149 View Code Duplication
    protected static function getIBlockSectionPanelButtons($section)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
150
    {
151
        if (!isset(static::$panelButtons['iblock_section'][$section['ID']])) {
152
            static::$panelButtons['iblock_section'][$section['ID']] = CIBlock::GetPanelButtons(
153
                $section["IBLOCK_ID"],
154
                0,
155
                $section['ID'],
156
                []
157
            );
158
        }
159
160
        return static::$panelButtons['iblock_section'][$section['ID']];
161
    }
162
}
163