1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace Canvas\Models; |
5
|
|
|
|
6
|
|
|
use Phalcon\Di; |
7
|
|
|
use Canvas\Http\Exception\InternalServerErrorException; |
8
|
|
|
use Phalcon\Mvc\ModelInterface; |
9
|
|
|
|
10
|
|
|
class SystemModules extends AbstractModel |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* |
14
|
|
|
* @var integer |
15
|
|
|
*/ |
16
|
|
|
public $id; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* |
20
|
|
|
* @var integer |
21
|
|
|
*/ |
22
|
|
|
public $name; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* |
26
|
|
|
* @var integer |
27
|
|
|
*/ |
28
|
|
|
public $slug; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
public $model_name; |
|
|
|
|
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* |
38
|
|
|
* @var integer |
39
|
|
|
*/ |
40
|
|
|
public $apps_id; |
|
|
|
|
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* |
44
|
|
|
* @var integer |
45
|
|
|
*/ |
46
|
|
|
public $parents_id; |
|
|
|
|
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* |
50
|
|
|
* @var integer |
51
|
|
|
*/ |
52
|
|
|
public $menu_order; |
|
|
|
|
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* |
56
|
|
|
* @var integer |
57
|
|
|
*/ |
58
|
|
|
public $use_elastic; |
|
|
|
|
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* |
62
|
|
|
* @var string |
63
|
|
|
*/ |
64
|
|
|
public $browse_fields; |
|
|
|
|
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* |
68
|
|
|
* @var integer |
69
|
|
|
*/ |
70
|
|
|
public $show; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* |
74
|
|
|
* @var string |
75
|
|
|
*/ |
76
|
|
|
public $created_at; |
|
|
|
|
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* |
80
|
|
|
* @var string |
81
|
|
|
*/ |
82
|
|
|
public $updated_at; |
|
|
|
|
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* |
86
|
|
|
* @var integer |
87
|
|
|
*/ |
88
|
|
|
public $is_deleted; |
|
|
|
|
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Initialize method for model. |
92
|
|
|
*/ |
93
|
|
|
public function initialize() |
94
|
|
|
{ |
95
|
|
|
$this->hasMany( |
96
|
|
|
'id', |
97
|
|
|
'Canvas\Models\EmailTemplatesVariables', |
98
|
|
|
'system_modules_id', |
99
|
|
|
['alias' => 'templateVariable'] |
100
|
|
|
); |
101
|
|
|
|
102
|
|
|
$this->hasMany( |
103
|
|
|
'id', |
104
|
|
|
'Canvas\Models\Webhooks', |
105
|
|
|
'system_modules_id', |
106
|
|
|
['alias' => 'webhook'] |
107
|
|
|
); |
108
|
|
|
|
109
|
|
|
$this->belongsTo( |
110
|
|
|
'companies_id', |
111
|
|
|
'Canvas\Models\Companies', |
112
|
|
|
'id', |
113
|
|
|
['alias' => 'company'] |
114
|
|
|
); |
115
|
|
|
|
116
|
|
|
$this->belongsTo( |
117
|
|
|
'apps_id', |
118
|
|
|
'Canvas\Models\Apps', |
119
|
|
|
'id', |
120
|
|
|
['alias' => 'app'] |
121
|
|
|
); |
122
|
|
|
|
123
|
|
|
$this->belongsTo( |
124
|
|
|
'company_branches_id', |
125
|
|
|
'Canvas\Models\CompanyBranches', |
126
|
|
|
'id', |
127
|
|
|
['alias' => 'companyBranch'] |
128
|
|
|
); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Returns table name mapped in the model. |
133
|
|
|
* |
134
|
|
|
* @return string |
135
|
|
|
*/ |
136
|
|
|
public function getSource(): string |
137
|
|
|
{ |
138
|
|
|
return 'system_modules'; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Get System Module by its model_name. |
143
|
|
|
* |
144
|
|
|
* @deprecated v2 |
145
|
|
|
* @param string $model_name |
|
|
|
|
146
|
|
|
* @return ModelInterface |
147
|
|
|
*/ |
148
|
|
|
public static function getSystemModuleByModelName(string $modelName): ModelInterface |
149
|
|
|
{ |
150
|
|
|
$module = SystemModules::findFirst([ |
151
|
|
|
'conditions' => 'model_name = ?0 and apps_id = ?1', |
152
|
|
|
'bind' => [$modelName, Di::getDefault()->getApp()->getId()] |
153
|
|
|
]); |
154
|
|
|
|
155
|
|
|
if (!is_object($module)) { |
156
|
|
|
throw new InternalServerErrorException('No system module for ' . $modelName); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
return $module; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* Get System Module by its model_name. |
164
|
|
|
* |
165
|
|
|
* @param string $model_name |
|
|
|
|
166
|
|
|
* @return ModelInterface |
167
|
|
|
*/ |
168
|
|
|
public static function getByModelName(string $modelName): ModelInterface |
169
|
|
|
{ |
170
|
|
|
return self::getSystemModuleByModelName($modelName); |
|
|
|
|
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* Get System Module by Name. |
175
|
|
|
* |
176
|
|
|
* @param string $name |
177
|
|
|
* @return ModelInterface |
|
|
|
|
178
|
|
|
*/ |
179
|
|
|
public static function getByName(string $name): ModelInterface |
180
|
|
|
{ |
181
|
|
|
return self::findFirstOrFail([ |
182
|
|
|
'conditions' => 'name = ?0 and apps_id = ?1', |
183
|
|
|
'bind' => [ |
184
|
|
|
$name, |
185
|
|
|
Di::getDefault()->getApp()->getId() |
186
|
|
|
] |
187
|
|
|
]); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* Get System Module by id. |
192
|
|
|
* |
193
|
|
|
* @param int $id |
194
|
|
|
* @return ModelInterface |
|
|
|
|
195
|
|
|
*/ |
196
|
|
|
public static function getById($id): ModelInterface |
197
|
|
|
{ |
198
|
|
|
$module = SystemModules::findFirstOrFail([ |
199
|
|
|
'conditions' => 'id = ?0 and apps_id = ?1', |
200
|
|
|
'bind' => [$id, Di::getDefault()->getApp()->getId()] |
201
|
|
|
]); |
202
|
|
|
|
203
|
|
|
return $module; |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* Get System Module by id. |
208
|
|
|
* |
209
|
|
|
* @param int $id |
|
|
|
|
210
|
|
|
* @return ModelInterface |
|
|
|
|
211
|
|
|
*/ |
212
|
|
|
public static function getBySlug(string $slug): ModelInterface |
213
|
|
|
{ |
214
|
|
|
$module = SystemModules::findFirstOrFail([ |
215
|
|
|
'conditions' => 'slug = ?0 and apps_id = ?1', |
216
|
|
|
'bind' => [$slug, Di::getDefault()->getApp()->getId()] |
217
|
|
|
]); |
218
|
|
|
|
219
|
|
|
return $module; |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* Given tell them if this system module is index in elastic. |
224
|
|
|
* |
225
|
|
|
* @return bool |
226
|
|
|
*/ |
227
|
|
|
public function useElastic(): bool |
|
|
|
|
228
|
|
|
{ |
229
|
|
|
return (bool) $this->use_elastic; |
230
|
|
|
} |
231
|
|
|
} |
232
|
|
|
|
This check examines a number of code elements and verifies that they conform to the given naming conventions.
You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.