Passed
Push — master ( 00b675...b5f4af )
by Gabor
06:20
created

IndexAction::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
/**
3
 * WebHemi.
4
 *
5
 * PHP version 7.1
6
 *
7
 * @copyright 2012 - 2017 Gixx-web (http://www.gixx-web.com)
8
 * @license   https://opensource.org/licenses/MIT The MIT License (MIT)
9
 *
10
 * @link      http://www.gixx-web.com
11
 */
12
declare(strict_types = 1);
13
14
namespace WebHemi\Middleware\Action\Admin\ControlPanel\Themes;
15
16
use RuntimeException;
17
use WebHemi\Configuration\ServiceInterface as ConfigurationInterface;
18
use WebHemi\Environment\ServiceInterface as EnvironmentInterface;
19
use WebHemi\Middleware\Action\AbstractMiddlewareAction;
20
21
/**
22
 * Class IndexAction
23
 */
24
class IndexAction extends AbstractMiddlewareAction
25
{
26
    /** @var ConfigurationInterface */
27
    private $configuration;
28
    /** @var EnvironmentInterface */
29
    private $environment;
30
31
    /**
32
     * IndexAction constructor.
33
     *
34
     * @param ConfigurationInterface $configuration
35
     * @param EnvironmentInterface   $environment
36
     */
37
    public function __construct(ConfigurationInterface $configuration, EnvironmentInterface $environment)
38
    {
39
        $this->configuration = $configuration;
40
        $this->environment = $environment;
41
    }
42
43
    /**
44
     * Gets template map name or template file path.
45
     *
46
     * @return string
47
     */
48
    public function getTemplateName() : string
49
    {
50
        return 'admin-control-panel-themes-list';
51
    }
52
53
    /**
54
     * Gets template data.
55
     *
56
     * @return array
57
     */
58
    public function getTemplateData() : array
59
    {
60
        $themes = $usedThemes = [];
61
62
        foreach ($this->configuration->getData('applications') as $application) {
63
            $usedThemes[$application['theme']] = $application['theme'];
64
        }
65
66
        // Make the default theme read-only.
67
        $usedThemes['default'] = 'default';
68
69
        foreach ($this->configuration->getData('themes') as $themeName => $themeData) {
70
            $themeStaticPath = '/resources/'.
71
                ($themeName == 'default' ? 'default_theme' : 'vendor_themes/' . $themeName)
72
                . '/static/';
73
74
75
            $themes[$themeName] = [
76
                'name' => $themeName,
77
                'title' => $themeData['legal']['title'] ?? $themeName,
78
                'description' => $themeData['legal']['description'] ?? '',
79
                'version' => $themeData['legal']['version'] ?? '',
80
                'author' => $themeData['legal']['author'] ?? 'Unknown',
81
                'homepage' => $themeData['legal']['homepage'] ?? '',
82
                'license' => $themeData['legal']['license'] ?? '',
83
                'read_only' => isset($usedThemes[$themeName]),
84
                'feature_website' => isset($themeData['features']['website_support'])
85
                    ? (bool)$themeData['features']['website_support']
86
                    : false,
87
                'feature_login' => isset($themeData['features']['admin_login_support'])
88
                    ? (bool)$themeData['features']['admin_login_support']
89
                    : false,
90
                'feature_admin' => isset($themeData['features']['admin_support'])
91
                    ? (bool)$themeData['features']['admin_support']
92
                    : false,
93
                'logo' => isset($themeData['legal']['logo'])
94
                    ? $themeStaticPath . $themeData['legal']['logo']
95
                    : '',
96
                'preview' => isset($themeData['legal']['preview'])
97
                    ? $themeStaticPath . $themeData['legal']['preview']
98
                    : '',
99
            ];
100
        }
101
102
        ksort($themes);
103
104
        return [
105
            'themes' => $themes
106
        ];
107
    }
108
}
109