Completed
Push — master ( 814aa1...dee795 )
by Nikita
13:52
created

Application   A

Complexity

Total Complexity 33

Size/Duplication

Total Lines 119
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 3
Bugs 1 Features 1
Metric Value
wmc 33
c 3
b 1
f 1
lcom 1
cbo 6
dl 0
loc 119
rs 9.4

9 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 11 1
B buildUrl() 0 11 5
A updateTemplate() 0 5 2
A initUrl() 0 12 4
B initResources() 0 13 6
A __base() 0 5 1
A oldMainRenderer() 0 10 4
C oldMenuRenderer() 0 25 7
A oldGetTitle() 0 7 3
1
<?php 
2
namespace samsoncms\cms;
3
4
use samson\activerecord\dbQuery;
5
use samson\core\CompressableExternalModule;
6
use samson\pager\Pager;
7
use samsonphp\event\Event;
8
9
/**
10
 * SamsonCMS external compressible application for integrating
11
 * @author Vitaly Iegorov <[email protected]>
12
 */
13
class Application extends CompressableExternalModule {
14
    /** @var string Module identifier */
15
    protected $id = 'cms';
16
17
    protected $isCMS = false;
18
19
    public function init( array $params = array() ) {
20
        Event::subscribe('core.security', array($this, 'updateTemplate'));
21
        // Old applications main page rendering
22
        Event::subscribe('template.main.rendered', array($this, 'oldMainRenderer'));
23
        // Old applications menu rendering
24
        Event::subscribe('template.menu.rendered', array($this, 'oldMenuRenderer'));
25
26
        Event::subscribe('samson.url.build', array($this, 'buildUrl'));
27
        // Call parent initialization
28
        return parent::init( $params );
29
    }
30
31
    public function buildUrl(& $urlObj, & $httpHost, & $urlParams)
32
    {
33
        $index = 0;
34
        if (isset($urlParams[$index]) && (\samson\core\SamsonLocale::current() == $urlParams[$index])) {
35
            $index = 1;
36
        }
37
        if ( isset( $urlParams[$index] ) && ( strpos($urlParams[$index], 'cms-') === 0 ) ) {
38
            $urlParams[$index] = str_replace('cms-', '', $urlParams[$index]);
39
            array_unshift($urlParams, 'cms');
40
        }
41
    }
42
43
    public function updateTemplate($core, $securityResult) {
0 ignored issues
show
Unused Code introduced by
The parameter $securityResult is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
44
        if ($this->isCMS) {
45
            $core->template($this->path().'app/view/index.php', true);
46
        }
47
    }
48
49
    public function initUrl( & $urlObj, & $urlArgs ) {
0 ignored issues
show
Unused Code introduced by
The parameter $urlObj is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
50
        if($urlArgs[0] == 'cms') {
51
            $this->isCMS = true;
52
            if (isset($urlArgs[1])) {
53
                if (strpos($urlArgs[1], 'samsoncms_') !== 0){
54
                    $urlArgs[1] = 'cms-'.$urlArgs[1];
55
                }
56
                unset($urlArgs[0]);
57
                $urlArgs = array_values($urlArgs);
58
            }
59
        }
60
    }
61
62
    public function initResources(& $resourceRouter, $moduleId, & $approve)
0 ignored issues
show
Unused Code introduced by
The parameter $resourceRouter is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
63
    {
64
        if ($moduleId == 'core') return true;
65
        if ($this->isCMS) {
66
            $approve = false;
67
            if (isset(m($moduleId)->composerParameters['composerName'])&&
68
                isset(m('cms')->composerParameters['required'])&&
69
                in_array(m($moduleId)->composerParameters['composerName'], m('cms')->composerParameters['required'])){
70
                $approve = true;
71
            }
72
        }
73
74
    }
75
76
    public function __base()
77
    {
78
        s()->active(m('template'));
79
        m('template')->__handler();
80
    }
81
82
    public function oldMainRenderer(&$html)
83
    {
84
        // Render application main page block
85
        foreach (\samsoncms\Application::loaded() as $app) {
0 ignored issues
show
Deprecated Code introduced by
The method samsoncms\Application::loaded() has been deprecated.

This method has been deprecated.

Loading history...
86
            // Show only visible apps
87
            if ($app->hide == false && $app->findView('sub_menu')) {
88
                $html .= $app->main();
89
            }
90
        }
91
    }
92
    /**
93
     * @deprecated All application should draw menu block via events
94
     */
95
    public function oldMenuRenderer(&$html, &$subMenu)
96
    {
97
        // Iterate loaded samson\cms\application
98
        foreach (\samsoncms\Application::loaded() as $app) {
0 ignored issues
show
Deprecated Code introduced by
The method samsoncms\Application::loaded() has been deprecated.

This method has been deprecated.

Loading history...
99
            // Show only visible apps
100
            if ($app->hide == false) {
101
                // Render application menu item
102
                $html .= m('template')
103
                    ->view('menu/item')
104
                    ->active(url()->module == $app->id() ? 'active' : '')
105
                    ->app($app)
106
                    ->icon($app->icon)
107
                    ->name(isset($app->name{0}) ? $app->name : '')
108
                    ->output();
109
            }
110
        }
111
        $subMenu = '';
112
        // Find current SamsonCMS application
113
        if (\samsoncms\Application::find(url()->module, $app/*@var $app App*/)) {
114
            // If module has sub_menu view - render it
115
            if ($app->findView('sub_menu')) {
116
                $subMenu .= $app->view('sub_menu')->output();
117
            }
118
        }
119
    }
120
    /**
121
     * @deprecated
122
     * @return string Page title
123
     */
124
    public function oldGetTitle()
125
    {
126
        $local = m('local');
127
        $current = m();
128
        return isset($current['title']) ? $current['title'] :
129
            (isset($local['title']) ? $local['title'] : '');
130
    }
131
}