Passed
Push — develop ( d30961...dd7b3a )
by Nikolay
34:55 queued 29:58
created

TimeSettingsEditForm::initialize()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 41
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 27
c 0
b 0
f 0
dl 0
loc 41
rs 9.1768
cc 5
nc 5
nop 2
1
<?php
2
3
/*
4
 * MikoPBX - free phone system for small business
5
 * Copyright © 2017-2023 Alexey Portnov and Nikolay Beketov
6
 *
7
 * This program is free software: you can redistribute it and/or modify
8
 * it under the terms of the GNU General Public License as published by
9
 * the Free Software Foundation; either version 3 of the License, or
10
 * (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License along with this program.
18
 * If not, see <https://www.gnu.org/licenses/>.
19
 */
20
21
namespace MikoPBX\AdminCabinet\Forms;
22
23
use MikoPBX\Common\Models\PbxSettings;
24
use MikoPBX\Common\Providers\TranslationProvider;
25
use Phalcon\Forms\Element\Select;
26
use Phalcon\Forms\Element\Text;
27
use Phalcon\Forms\Element\TextArea;
28
29
/**
30
 * Class TimeSettingsEditForm
31
 *
32
 * @package MikoPBX\AdminCabinet\Forms
33
 * @property TranslationProvider translation
34
 */
35
class TimeSettingsEditForm extends BaseForm
36
{
37
    public function initialize($entity = null, $options = null): void
38
    {
39
        parent::initialize($entity, $options);
40
41
        foreach ($entity as $item) {
42
            switch ($item->key) {
43
                case PbxSettings::PBX_TIMEZONE:
44
                    $ntpserver = new Select(
45
                        PbxSettings::PBX_TIMEZONE,
46
                        $options,
47
                        [
48
                            'using' => [
49
                                'id',
50
                                'name',
51
                            ],
52
                            'useEmpty' => false,
53
                            'value' => $item->value,
54
                            'class' => 'ui search selection dropdown',
55
                        ]
56
                    );
57
                    $this->add($ntpserver);
58
                    break;
59
                case PbxSettings::NTP_SERVER:
60
                    $this->add(new TextArea($item->key, ['value' => $item->value, "rows" => 4]));
61
                    break;
62
                case PbxSettings::PBX_MANUAL_TIME_SETTINGS:
63
                    $this->addCheckBox(PbxSettings::PBX_MANUAL_TIME_SETTINGS, intval($item->value) === 1);
64
                    break;
65
                default:
66
                    $this->add(
67
                        new Text(
68
                            $item->key,
69
                            [
70
                                'value' => $item->value,
71
                            ]
72
                        )
73
                    );
74
            }
75
        }
76
77
        $this->add(new Text('ManualDateTime', ['value' => '']));
78
    }
79
}
80