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