Passed
Push — develop ( 4a8e6d...3766e9 )
by Nikolay
06:00 queued 10s
created

PbxExtensionModules::afterSave()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * Copyright (C) MIKO LLC - All Rights Reserved
4
 * Unauthorized copying of this file, via any medium is strictly prohibited
5
 * Proprietary and confidential
6
 * Written by Nikolay Beketov, 5 2018
7
 *
8
 */
9
10
namespace MikoPBX\Common\Models;
11
12
use MikoPBX\Common\Providers\PBXConfModulesProvider;
13
use Phalcon\Validation;
14
use Phalcon\Validation\Validator\Uniqueness as UniquenessValidator;
15
16
/**
17
 * Class PbxExtensionModules
18
 *
19
 * @method static mixed findFirstByUniqid(array|string|int $parameters = null)
20
 *
21
 * @package MikoPBX\Common\Models
22
 */
23
class PbxExtensionModules extends ModelsBase
24
{
25
    /**
26
     * @Primary
27
     * @Identity
28
     * @Column(type="integer", nullable=false)
29
     */
30
    public $id;
31
32
    /**
33
     * @Column(type="string", nullable=true)
34
     */
35
    public ?string $uniqid = '';
36
37
    /**
38
     * @Column(type="string", nullable=true)
39
     */
40
    public ?string $name = '';
41
42
    /**
43
     * @Column(type="string", nullable=true)
44
     */
45
    public ?string $version = '';
46
47
    /**
48
     * @Column(type="string", nullable=true)
49
     */
50
    public ?string $developer = '';
51
52
    /**
53
     * @Column(type="string", nullable=true, column="supportemail")
54
     */
55
    public ?string $support_email = '';
56
57
    /**
58
     * @Column(type="string", nullable=true)
59
     */
60
    public ?string $path = '';
61
62
    /**
63
     * @Column(type="string", nullable=true)
64
     */
65
    public ?string $description = '';
66
67
    /**
68
     * @Column(type="string", length=1, nullable=false)
69
     */
70
    public ?string $disabled = '1';
71
72
73
    public function initialize(): void
74
    {
75
        $this->setSource('m_PbxExtensionModules');
76
        parent::initialize();
77
    }
78
79
    public function validation(): bool
80
    {
81
        $validation = new Validation();
82
        $validation->add(
83
            'uniqid',
84
            new UniquenessValidator(
85
                [
86
                    'message' => $this->t('mo_ThisUniqidMustBeUniqueForPbxExtensionModulesModels'),
87
                ]
88
            )
89
        );
90
91
        return $this->validate($validation);
92
    }
93
94
    /**
95
     * After change PBX modules need recreate shared services
96
     */
97
    public function afterSave(): void
98
    {
99
        parent::afterSave();
100
        $this->di->remove('pbxConfModules');
101
        $this->di->register(new PBXConfModulesProvider());
102
    }
103
104
    /**
105
     * After change PBX modules need recreate shared services
106
     */
107
    public function afterDelete(): void
108
    {
109
        parent::afterDelete();
110
        $this->di->remove('pbxConfModules');
111
        $this->di->register(new PBXConfModulesProvider());
112
    }
113
114
    /**
115
     * Prepares array of enabled modules params for reading
116
     * @return array
117
     */
118
    public static function getEnabledModulesArray(): array
119
    {
120
        $parameters = [
121
            'conditions' => 'disabled="0"',
122
            'cache' => [
123
                'key'=>'PbxExtensionModules-Enabled',
124
                'lifetime' => 3600,
125
            ]
126
        ];
127
        return PbxExtensionModules::find($parameters)->toArray();
128
    }
129
}
130
131