Breadcrumbs::crumbDefaultFiles()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php
2
3
namespace carono\exchange1c\components;
4
5
use carono\exchange1c\models\Article;
6
use yii\base\Action;
7
use yii\helpers\ArrayHelper;
8
use yii\helpers\Html;
9
use yii\helpers\Inflector;
10
use yii\helpers\Url;
11
12
class Breadcrumbs
13
{
14
    /**
15
     * @param $action
16
     * @param $params
17
     */
18
    protected static function callCrumb($action, $params)
19
    {
20
        $name = 'crumb' . Inflector::camelize($action->controller->id . '-' . $action->id);
21
        $class = get_called_class();
22
        if (method_exists($class, $name)) {
23
            $reflectionMethod = new \ReflectionMethod($class, $name);
24
            $data = [];
25
            foreach ($reflectionMethod->getParameters() as $p) {
26
                $data[] = isset($params[$p->getName()]) ? $params[$p->getName()] : null;
27
            }
28
            $action->controller->getView()->params['breadcrumbs'] = call_user_func_array([$class, "$name"], $data);
29
        }
30
    }
31
32
    /**
33
     * @param $action
34
     * @param $params
35
     */
36
    protected static function callButton($action, $params)
37
    {
38
        $name = 'button' . Inflector::camelize($action->controller->id . '-' . $action->id);
39
        $class = get_called_class();
40
        if (method_exists($class, $name)) {
41
            $reflectionMethod = new \ReflectionMethod($class, $name);
42
            $data = [];
43
            foreach ($reflectionMethod->getParameters() as $p) {
44
                $data[] = isset($params[$p->getName()]) ? $params[$p->getName()] : null;
45
            }
46
            $action->controller->getView()->params['buttons'] = call_user_func_array([$class, $name], $data);
47
        }
48
    }
49
50
    /**
51
     * @param Action $action
52
     * @param $params
53
     */
54
    public static function formCrumbs($action, $params)
55
    {
56
        self::callCrumb($action, $params);
57
        self::callButton($action, $params);
58
    }
59
60
    public static function buttonArticleIndex()
61
    {
62
        return [
63
            [
64
                'label' => 'Добавить статью',
65
                'url' => ['article/create'],
66
                'linkOptions' => ['class' => 'btn-xs btn btn-primary']
67
            ]
68
        ];
69
    }
70
71
    /**
72
     * @param Article $article
73
     * @return array
74
     */
75
    public static function buttonArticleView($article)
76
    {
77
        return [
78
            [
79
                'label' => 'Редактировать',
80
                'url' => ['article/update', 'id' => $article->id],
81
                'linkOptions' => ['class' => 'btn-xs btn btn-primary']
82
            ],
83
            [
84
                'label' => 'Добавить подстатью',
85
                'url' => ['article/create', 'parent' => $article->id],
86
                'linkOptions' => ['class' => 'btn-xs  btn btn-primary']
87
            ],
88
            [
89
                'label' => 'Удалить',
90
                'url' => ['article/delete', 'id' => $article->id],
91
                'options' => ['data-confirm' => 'Удалить статью?'],
92
                'linkOptions' => ['class' => 'btn-xs btn btn-danger']
93
            ]
94
        ];
95
    }
96
97
    #############################################################################
98
99
    public static function crumbTestingIndex()
100
    {
101
        return [
102
            'Тестирование модуля',
103
        ];
104
    }
105
106
    /**
107
     * @param Article $article
108
     * @return array
109
     */
110
    public static function crumbArticleView($article)
111
    {
112
        $items = [
113
            ['label' => 'Старт', 'url' => ['article/index']]
114
        ];
115
        $parent = $article;
116
        while ($parent = $parent->parent) {
117
            $items[] = ['label' => $parent->name, 'url' => ['article/view', 'id' => $parent->id]];
118
        }
119
        $items[] = $article->name;
120
        return $items;
121
    }
122
123
    public static function crumbArticleUpdate($article)
124
    {
125
        $items = [
126
            ['label' => 'Старт', 'url' => ['article/index']]
127
        ];
128
        $parent = $article;
129
        while ($parent = $parent->parent) {
130
            $items[] = ['label' => $parent->name, 'url' => ['article/view', 'id' => $parent->id]];
131
        }
132
        $items[] = ['label' => $article->name, 'url' => ['article/view', 'id' => $article->id]];
133
        $items [] = 'Редактирование';
134
        return $items;
135
    }
136
137
138
    public static function crumbInterfaceCheck($variable, $class, $interfaceTest)
139
    {
140
        return [
141
            ['label' => 'Интерфейсы', 'url' => ['default/interfaces']],
142
            $class,
143
        ];
144
    }
145
146
    public static function crumbDefaultInterfaces()
147
    {
148
        return [
149
            'Интерфейсы',
150
        ];
151
    }
152
153
    public static function crumbDefaultFiles()
154
    {
155
        return [
156
            'Временные файлы',
157
        ];
158
    }
159
160
    public static function crumbDefaultSettings()
161
    {
162
        return [
163
            'Настройки модуля',
164
        ];
165
    }
166
167
    public static function crumbDefaultDocumentation()
168
    {
169
        return [
170
            'Документация по CommerceML',
171
        ];
172
    }
173
174
    public static function crumbDefaultExport()
175
    {
176
        return [
177
            'Экспорт',
178
        ];
179
    }
180
181
182
    public static function crumbDefaultImport()
183
    {
184
        return [
185
            'Импорт',
186
        ];
187
    }
188
189
    public static function crumbArticleIndex()
190
    {
191
        return [
192
            'Старт',
193
        ];
194
    }
195
}