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