Passed
Pull Request — master (#42)
by Rafael
06:14
created

SystemModules::getSystemModuleByModelName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Gewaer\Models;
5
6
use Phalcon\Di;
7
8
class SystemModules extends AbstractModel
9
{
10
    /**
11
     *
12
     * @var integer
13
     */
14
    public $id;
15
16
    /**
17
     *
18
     * @var integer
19
     */
20
    public $name;
21
22
    /**
23
     *
24
     * @var integer
25
     */
26
    public $slug;
27
28
    /**
29
     *
30
     * @var string
31
     */
32
    public $model_name;
33
34
    /**
35
     *
36
     * @var integer
37
     */
38
    public $apps_id;
39
40
    /**
41
     *
42
     * @var integer
43
     */
44
    public $parents_id;
45
46
    /**
47
     *
48
     * @var integer
49
     */
50
    public $menu_order;
51
52
    /**
53
     *
54
     * @var string
55
     */
56
    public $created_at;
57
58
    /**
59
     *
60
     * @var string
61
     */
62
    public $updated_at;
63
64
    /**
65
     *
66
     * @var integer
67
     */
68
    public $is_deleted;
69
70
    /**
71
     * Initialize method for model.
72
     */
73 65
    public function initialize()
74
    {
75 65
        $this->hasMany(
76 65
            'id',
77 65
            'Gewaer\Models\EmailTemplatesVariables',
78 65
            'system_modules_id',
79 65
            ['alias' => 'templateVariable']
80
        );
81
82 65
        $this->hasMany(
83 65
            'id',
84 65
            'Gewaer\Models\Webhooks',
85 65
            'system_modules_id',
86 65
            ['alias' => 'webhook']
87
        );
88
89 65
        $this->belongsTo(
90 65
            'companies_id',
91 65
            'Gewaer\Models\Companies',
92 65
            'id',
93 65
            ['alias' => 'company']
94
        );
95
96 65
        $this->belongsTo(
97 65
            'apps_id',
98 65
            'Gewaer\Models\Apps',
99 65
            'id',
100 65
            ['alias' => 'app']
101
        );
102
103 65
        $this->belongsTo(
104 65
            'company_branches_id',
105 65
            'Gewaer\Models\CompanyBranches',
106 65
            'id',
107 65
            ['alias' => 'companyBranch']
108
        );
109
110 65
        $this->setSource('user_company_apps_activities');
111 65
    }
112
113
    /**
114
     * Returns table name mapped in the model.
115
     *
116
     * @return string
117
     */
118 65
    public function getSource(): string
119
    {
120 65
        return 'system_modules';
121
    }
122
123
    /**
124
     * Get System Module by its model_name
125
     * @param string $model_name
126
     * @return SystemModules
127
     */
128 65
    public static function getSystemModuleByModelName(string $model_name):SystemModules
129
    {
130 65
        return SystemModules::findFirst([
131 65
            'conditions' => 'model_name = ?0 and apps_id = ?1',
132 65
            'bind' => [$model_name, Di::getDefault()->getApp()->getId()]
133
        ]);
134
    }
135
}
136