Issues (13)

src/Module/SSConfiguration.php (2 issues)

1
<?php
2
3
namespace BiffBangPow\SSMonitor\Client\Module;
4
5
use BiffBangPow\SSMonitor\Client\Core\ClientCommon;
6
use SilverStripe\Control\Director;
7
use SilverStripe\Core\Config\Configurable;
8
use BiffBangPow\SSMonitor\Client\Core\ClientInterface;
9
use SilverStripe\Core\Environment;
10
use SilverStripe\ORM\ArrayList;
11
use SilverStripe\SiteConfig\SiteConfig;
12
use SilverStripe\View\ArrayData;
13
use SilverStripe\View\SSViewer;
14
15
class SSConfiguration implements ClientInterface
16
{
17
    use ClientCommon;
18
    use Configurable;
19
20
    /**
21
     * @var string
22
     */
23
    private string $clientName = 'silverstripeconfig';
0 ignored issues
show
The private property $clientName is not used, and could be removed.
Loading history...
24
25
    /**
26
     * @config
27
     * @var string
28
     */
29
    private static $client_title = 'Silverstripe Configuration';
0 ignored issues
show
The private property $client_title is not used, and could be removed.
Loading history...
30
31
32
    public function getResult($config = null)
33
    {
34
        $admin_user = Environment::getEnv('SS_DEFAULT_ADMIN_USERNAME');
35
        $admin_pass = Environment::getEnv('SS_DEFAULT_ADMIN_PASSWORD');
36
37
        $res = [
38
            'sitename' => [
39
                'label' => _t(__CLASS__ . '.sitename', 'Site Name'),
40
                'value' => SiteConfig::current_site_config()->Title
41
            ],
42
            'envtype' => [
43
                'label' => _t(__CLASS__ . '.envtype', 'Environment Type'),
44
                'value' => Environment::getEnv('SS_ENVIRONMENT_TYPE')
45
            ],
46
            'baseurl' => [
47
                'label' => _t(__CLASS__ . '.baseurl', 'Base URL'),
48
                'value' => Director::absoluteBaseURL()
49
            ],
50
            'defaultadmin' => [
51
                'label' => _t(__CLASS__ . '.defaultadmin', 'Default admin set'),
52
                'value' => ($admin_pass || $admin_user)
53
            ]
54
        ];
55
56
        return [
57
            $this->getClientName() => $res
58
        ];
59
    }
60
61
    public function forTemplate()
62
    {
63
        $data = $this->getResult()[$this->getClientName()];
64
        $variables = ArrayList::create();
65
66
        if (isset($data['defaultadmin'])) {
67
            $data['defaultadmin']['value'] = ($data['defaultadmin']['value']) ? _t(__CLASS__ . '.yes', "Yes") : _t(__CLASS__ . '.no', "No");
68
        }
69
70
        foreach ($data as $id => $values) {
71
            $variables->push(ArrayData::create([
72
                'Variable' => $values['label'],
73
                'Value' => $values['value']
74
            ]));
75
        }
76
77
        $viewer = new SSViewer('BiffBangPow/SSMonitor/Client/Module/SSConfiguration');
78
        $html = $viewer->process(ArrayData::create([
79
            'Title' => $this->getClientTitle(),
80
            'Variables' => $variables
81
        ]));
82
83
        return $html;
84
    }
85
86
}
87