ToolbarHelper::apply()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 11
Ratio 100 %

Importance

Changes 0
Metric Value
dl 11
loc 11
rs 9.9
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
/**
3
 * CakeCMS Core
4
 *
5
 * This file is part of the of the simple cms based on CakePHP 3.
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 *
9
 * @package     Core
10
 * @license     MIT
11
 * @copyright   MIT License http://www.opensource.org/licenses/mit-license.php
12
 * @link        https://github.com/CakeCMS/Core".
13
 * @author      Sergey Kalistratov <[email protected]>
14
 */
15
16
namespace Core\Toolbar;
17
18
use Core\Utility\Toolbar;
19
20
/**
21
 * Class ToolbarHelper
22
 *
23
 * @package Core\Toolbar
24
 */
25
class ToolbarHelper
26
{
27
28
    const ACTION_DELETE = 'delete';
29
    const ACTION_SAVE   = 'save';
30
    const ACTION_APPLY  = 'apply';
31
32
    /**
33
     * Toolbar instance name.
34
     *
35
     * @var string
36
     */
37
    protected static $_toolbar = Toolbar::DEFAULT_NAME;
38
39
    /**
40
     * Create add link.
41
     *
42
     * @param string|null $title
43
     * @param array|string $url
44
     * @param string $icon
45
     * @param array $options
46
     * @return void
47
     */
48 View Code Duplication
    public static function add($title = null, $url = ['action' => 'add'], $icon = 'plus', array $options = [])
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...
49
    {
50
        $toolbar = Toolbar::getInstance(self::$_toolbar);
51
        $options += [
52
            'icon'   => $icon,
53
            'button' => 'green lighten-2'
54
        ];
55
56
        $toolbar->appendButton('Core.link', $title, $url, $options);
57
    }
58
59
    /**
60
     * Apply form button.
61
     *
62
     * @param null|string $title
63
     * @return void
64
     */
65 View Code Duplication
    public static function apply($title = null)
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...
66
    {
67
        $toolbar = Toolbar::getInstance(self::$_toolbar);
68
        $title   = (empty($title)) ? __d('core', 'Apply') : $title;
69
70
        $toolbar->appendButton('Core.action', $title, self::ACTION_APPLY, [
71
            'class'  => 'jsFormButton',
72
            'icon'   => 'check-square-o',
73
            'button' => 'green lighten-2',
74
        ]);
75
    }
76
77
    /**
78
     * Cancel form button.
79
     *
80
     * @param string|null $title
81
     * @param null|string|array $url
82
     * @param array $options
83
     * @return void
84
     */
85
    public static function cancel($title = null, $url = null, array $options = [])
86
    {
87
        $toolbar = Toolbar::getInstance(self::$_toolbar);
88
        $options += [
89
            'icon'      => 'close',
90
            'iconClass' => 'ckTextRed',
91
            'button'    => 'grey lighten-3'
92
        ];
93
94
        if (empty($url)) {
95
            $url = ['action' => 'index'];
96
        }
97
98
        $title = (empty($title)) ? __d('core', 'Cancel') : $title;
99
100
        $toolbar->appendButton('Core.link', $title, $url, $options);
101
    }
102
103
    /**
104
     * Delete for process form.
105
     *
106
     * @param string|null $title
107
     * @return void
108
     */
109
    public static function delete($title = null)
110
    {
111
        $toolbar = Toolbar::getInstance(self::$_toolbar);
112
        $title   = (empty($title)) ? __d('core', 'Delete') : $title;
113
114
        $toolbar->appendButton('Core.action', $title, self::ACTION_DELETE, []);
115
    }
116
117
    /**
118
     * Create link output.
119
     *
120
     * @param string $title
121
     * @param string|array $url
122
     * @param array $options
123
     */
124 View Code Duplication
    public static function link($title, $url, array $options = [])
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...
125
    {
126
        $toolbar = Toolbar::getInstance(self::$_toolbar);
127
        $options += [
128
            'icon'   => 'link',
129
            'button' => 'grey lighten-3'
130
        ];
131
132
        $toolbar->appendButton('Core.link', $title, $url, $options);
133
    }
134
135
    /**
136
     * Save form button.
137
     *
138
     * @param null|string $title
139
     * @return void
140
     */
141 View Code Duplication
    public static function save($title = null)
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...
142
    {
143
        $toolbar = Toolbar::getInstance(self::$_toolbar);
144
        $title   = (empty($title)) ? __d('core', 'Save') : $title;
145
146
        $toolbar->appendButton('Core.action', $title, self::ACTION_SAVE, [
147
            'icon'      => 'check',
148
            'class'     => 'jsFormButton',
149
            'iconClass' => 'ckTextGreen',
150
            'button'    => 'grey lighten-3',
151
        ]);
152
    }
153
154
    /**
155
     * Setup toolbar instance name.
156
     *
157
     * @param string $name
158
     * @return void
159
     */
160
    public static function setToolbar($name)
161
    {
162
        self::$_toolbar = $name;
163
    }
164
}
165