Completed
Push — master ( 682540...f9bf07 )
by Iurii
02:18
created

Main::addLibrary()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 1
1
<?php
2
3
/**
4
 * @package Bootstrap Select
5
 * @author Iurii Makukh <[email protected]>
6
 * @copyright Copyright (c) 2017, Iurii Makukh <[email protected]>
7
 * @license https://www.gnu.org/licenses/gpl-3.0.en.html GPL-3.0+
8
 */
9
10
namespace gplcart\modules\bootstrap_select;
11
12
use gplcart\core\Module,
13
    gplcart\core\Library;
14
15
/**
16
 * Main class for Bootstrap Select module
17
 */
18
class Main
19
{
20
21
    /**
22
     * Module class instance
23
     * @var \gplcart\core\Module $module
24
     */
25
    protected $module;
26
27
    /**
28
     * Library class instance
29
     * @var \gplcart\core\Library $library
30
     */
31
    protected $library;
32
33
    /**
34
     * @param Module $module
35
     * @param Library $library
36
     */
37
    public function __construct(Module $module, Library $library)
38
    {
39
        $this->module = $module;
40
        $this->library = $library;
41
    }
42
43
    /**
44
     * Implements hook "library.list"
45
     * @param array $libraries
46
     */
47
    public function hookLibraryList(array &$libraries)
48
    {
49
        $libraries['bootstrap_select'] = array(
50
            'name' => /* @text */'Bootstrap Select',
51
            'description' => /* @text */"A jQuery plugin that utilizes Bootstrap's dropdown.js to style and bring additional functionality to standard select elements",
52
            'type' => 'asset',
53
            'module' => 'bootstrap_select',
54
            'url' => 'https://github.com/silviomoreto/bootstrap-select',
55
            'download' => 'https://github.com/silviomoreto/bootstrap-select/archive/v1.12.1.zip',
56
            'version_source' => array(
57
                'file' => 'vendor/bootstrap_select/dist/js/bootstrap-select.min.js',
58
                'pattern' => '/v(\\d+\\.+\\d+\\.+\\d+)/',
59
            ),
60
            'files' => array(
61
                'vendor/bootstrap_select/dist/js/bootstrap-select.min.js',
62
                'vendor/bootstrap_select/dist/css/bootstrap-select.min.css',
63
            ),
64
            'dependencies' => array(
65
                'jquery' => '>= 1.8',
66
                'bootstrap' => '>= 3.0',
67
            ),
68
        );
69
    }
70
71
    /**
72
     * Implements hook "route.list"
73
     * @param array $routes
74
     */
75
    public function hookRouteList(array &$routes)
76
    {
77
        $routes['admin/module/settings/bootstrap_select'] = array(
78
            'access' => 'module_edit',
79
            'handlers' => array(
80
                'controller' => array('gplcart\\modules\\bootstrap_select\\controllers\\Settings', 'editSettings')
81
            )
82
        );
83
    }
84
85
    /**
86
     * Implements hook "construct.controller.backend"
87
     * @param \gplcart\core\controllers\backend\Controller $controller
88
     */
89
    public function hookConstructControllerBackend($controller)
90
    {
91
        $this->addLibrary($controller);
92
    }
93
94
    /**
95
     * Implements hook "module.enable.after"
96
     */
97
    public function hookModuleEnableAfter()
98
    {
99
        $this->library->clearCache();
100
    }
101
102
    /**
103
     * Implements hook "module.disable.after"
104
     */
105
    public function hookModuleDisableAfter()
106
    {
107
        $this->library->clearCache();
108
    }
109
110
    /**
111
     * Implements hook "module.install.after"
112
     */
113
    public function hookModuleInstallAfter()
114
    {
115
        $this->library->clearCache();
116
    }
117
118
    /**
119
     * Implements hook "module.uninstall.after"
120
     */
121
    public function hookModuleUninstallAfter()
122
    {
123
        $this->library->clearCache();
124
    }
125
126
    /**
127
     * Add Bootstrap Select library and additional assets
128
     * @param \gplcart\core\Controller $controller
129
     */
130
    public function addLibrary($controller)
131
    {
132
        $settings = $this->module->getSettings('bootstrap_select');
133
134
        $controller->setJsSettings('bootstrap_select', $settings);
135
        $controller->addAssetLibrary('bootstrap_select');
136
        $controller->setJs('system/modules/bootstrap_select/js/common.js');
137
    }
138
139
}
140