Total Complexity | 5 |
Total Lines | 141 |
Duplicated Lines | 0 % |
Coverage | 93.94% |
Changes | 0 |
1 | <?php |
||
7 | class Apps extends \Baka\Auth\Models\Apps |
||
8 | { |
||
9 | /** |
||
10 | * |
||
11 | * @var integer |
||
12 | */ |
||
13 | public $id; |
||
14 | |||
15 | /** |
||
16 | * |
||
17 | * @var string |
||
18 | */ |
||
19 | public $name; |
||
20 | |||
21 | /** |
||
22 | * |
||
23 | * @var string |
||
24 | */ |
||
25 | public $description; |
||
26 | |||
27 | /** |
||
28 | * |
||
29 | * @var string |
||
30 | */ |
||
31 | public $url; |
||
32 | |||
33 | /** |
||
34 | * |
||
35 | * @var integer |
||
36 | */ |
||
37 | public $default_apps_plan_id; |
||
38 | |||
39 | /** |
||
40 | * |
||
41 | * @var integer |
||
42 | */ |
||
43 | public $is_actived; |
||
44 | |||
45 | /** |
||
46 | * |
||
47 | * @var string |
||
48 | */ |
||
49 | public $created_at; |
||
50 | |||
51 | /** |
||
52 | * |
||
53 | * @var string |
||
54 | */ |
||
55 | public $updated_at; |
||
56 | |||
57 | /** |
||
58 | * |
||
59 | * @var integer |
||
60 | */ |
||
61 | public $is_deleted; |
||
62 | |||
63 | /** |
||
64 | * Ecosystem default app |
||
65 | * @var string |
||
66 | */ |
||
67 | const GEWAER_DEFAULT_APP_ID = 0; |
||
68 | const GEWAER_DEFAULT_APP_NAME = 'Default'; |
||
69 | |||
70 | /** |
||
71 | * Model Settings Trait |
||
72 | */ |
||
73 | use ModelSettingsTrait; |
||
74 | |||
75 | /** |
||
76 | * Initialize method for model. |
||
77 | */ |
||
78 | 85 | public function initialize() |
|
79 | { |
||
80 | 85 | parent::initialize(); |
|
81 | |||
82 | 85 | $this->setSource('apps'); |
|
83 | |||
84 | 85 | $this->hasOne( |
|
85 | 85 | 'default_apps_plan_id', |
|
86 | 85 | 'Gewaer\Models\AppsPlans', |
|
87 | 85 | 'id', |
|
88 | 85 | ['alias' => 'plan'] |
|
89 | ); |
||
90 | |||
91 | 85 | $this->hasMany( |
|
92 | 85 | 'id', |
|
93 | 85 | 'Gewaer\Models\AppsPlans', |
|
94 | 85 | 'apps_id', |
|
95 | 85 | ['alias' => 'plans'] |
|
96 | ); |
||
97 | |||
98 | 85 | $this->hasMany( |
|
99 | 85 | 'id', |
|
100 | 85 | 'Gewaer\Models\UserWebhooks', |
|
101 | 85 | 'apps_id', |
|
102 | 85 | ['alias' => 'user-webhooks'] |
|
103 | ); |
||
104 | |||
105 | 85 | $this->hasMany( |
|
106 | 85 | 'id', |
|
107 | 85 | 'Gewaer\Models\AppsSettings', |
|
108 | 85 | 'apps_id', |
|
109 | 85 | ['alias' => 'settings'] |
|
110 | ); |
||
111 | 85 | } |
|
112 | |||
113 | /** |
||
114 | * You can only get 2 variations or default in DB or the api app |
||
115 | * |
||
116 | * @param string $name |
||
117 | * @return Apps |
||
118 | */ |
||
119 | 11 | public static function getACLApp(string $name): Apps |
|
120 | { |
||
121 | 11 | if (trim($name) == self::GEWAER_DEFAULT_APP_NAME) { |
|
122 | 10 | $app = self::findFirst(0); |
|
123 | } else { |
||
124 | 1 | $app = self::findFirst(\Phalcon\DI::getDefault()->getConfig()->app->id); |
|
125 | } |
||
126 | |||
127 | 11 | return $app; |
|
128 | } |
||
129 | |||
130 | /** |
||
131 | * Is active? |
||
132 | * |
||
133 | * @return boolean |
||
134 | */ |
||
135 | public function isActive(): bool |
||
138 | } |
||
139 | |||
140 | /** |
||
141 | * Returns table name mapped in the model. |
||
142 | * |
||
143 | * @return string |
||
144 | */ |
||
145 | 85 | public function getSource() : string |
|
148 | } |
||
149 | } |
||
150 |