|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Gewaer\Api\Controllers; |
|
6
|
|
|
|
|
7
|
|
|
use Gewaer\Models\Modules; |
|
8
|
|
|
use Gewaer\CustomFields\CustomFields; |
|
9
|
|
|
use Phalcon\Http\Response; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Class LanguagesController |
|
13
|
|
|
* |
|
14
|
|
|
* @package Gewaer\Api\Controllers |
|
15
|
|
|
* |
|
16
|
|
|
*/ |
|
17
|
|
|
class ModulesController extends BaseController |
|
18
|
|
|
{ |
|
19
|
|
|
/* |
|
20
|
|
|
* fields we accept to create |
|
21
|
|
|
* |
|
22
|
|
|
* @var array |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $createFields = ['apps_id', 'name']; |
|
25
|
|
|
|
|
26
|
|
|
/* |
|
27
|
|
|
* fields we accept to create |
|
28
|
|
|
* |
|
29
|
|
|
* @var array |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $updateFields = ['apps_id', 'name']; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* set objects |
|
35
|
|
|
* |
|
36
|
|
|
* @return void |
|
37
|
|
|
*/ |
|
38
|
3 |
|
public function onConstruct() |
|
39
|
|
|
{ |
|
40
|
3 |
|
$this->model = new Modules(); |
|
41
|
3 |
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Fetch all Custom Fields of a Module |
|
45
|
|
|
* @param integer $id |
|
46
|
|
|
* @return Response |
|
47
|
|
|
*/ |
|
48
|
1 |
|
public function customFieldsByModulesId(int $id): Response |
|
49
|
|
|
{ |
|
50
|
|
|
//Verify that module exists |
|
51
|
1 |
|
$module = $this->model::findFirst([ |
|
52
|
1 |
|
'conditions' => 'id = ?0 and apps_id = ?1 and is_deleted = 0', |
|
53
|
1 |
|
'bind' => [$id, $this->app->getId()] |
|
|
|
|
|
|
54
|
|
|
]); |
|
55
|
|
|
|
|
56
|
1 |
|
if (!is_object($module)) { |
|
57
|
|
|
throw new NotFoundHttpException('Module not found'); |
|
|
|
|
|
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
//List all Custom Fields by module_id, apps and companies |
|
61
|
1 |
|
$customFields = CustomFields::find([ |
|
62
|
1 |
|
'conditions' => 'companies_id = ?0 and apps_id = ?1 and is_deleted = 0', |
|
63
|
1 |
|
'bind' => [$this->userData->default_company, $this->app->getId()] |
|
|
|
|
|
|
64
|
|
|
]); |
|
65
|
|
|
|
|
66
|
1 |
|
if (!is_object($customFields)) { |
|
67
|
|
|
throw new NotFoundHttpException('Custom Fields not found'); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
1 |
|
return $this->response($customFields); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|