1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Canvas\Api\Controllers; |
6
|
|
|
|
7
|
|
|
use Canvas\Models\Apps; |
8
|
|
|
use Canvas\Dto\AppsSettings; |
9
|
|
|
use Phalcon\Http\Response; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class LanguagesController. |
13
|
|
|
* |
14
|
|
|
* @package Canvas\Api\Controllers |
15
|
|
|
* |
16
|
|
|
*/ |
17
|
|
|
class AppsSettingsController extends BaseController |
18
|
|
|
{ |
19
|
|
|
/* |
20
|
|
|
* fields we accept to create |
21
|
|
|
* |
22
|
|
|
* @var array |
23
|
|
|
*/ |
24
|
|
|
protected $createFields = []; |
25
|
|
|
|
26
|
|
|
/* |
27
|
|
|
* fields we accept to create |
28
|
|
|
* |
29
|
|
|
* @var array |
30
|
|
|
*/ |
31
|
|
|
protected $updateFields = []; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* set objects. |
35
|
|
|
* |
36
|
|
|
* @return void |
37
|
|
|
*/ |
38
|
|
|
public function onConstruct() |
39
|
|
|
{ |
40
|
|
|
$this->model = new Apps(); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Format output. |
45
|
|
|
* |
46
|
|
|
* @param [type] $results |
|
|
|
|
47
|
|
|
* @return void |
48
|
|
|
*/ |
49
|
|
|
protected function processOutput($results) |
50
|
|
|
{ |
51
|
|
|
//DTOAppsSettings |
52
|
|
|
$this->dtoConfig->registerMapping(Apps::class, AppsSettings::class) |
53
|
|
|
->forMember('settings', function (Apps $app) { |
54
|
|
|
$settings = []; |
55
|
|
|
foreach ($app->settingsApp->toArray() as $setting) { |
56
|
|
|
$settings[$setting['name']] = $setting['value']; |
57
|
|
|
} |
58
|
|
|
return $settings; |
59
|
|
|
}); |
60
|
|
|
|
61
|
|
|
return is_iterable($results) ? |
62
|
|
|
$this->mapper->mapMultiple(iterator_to_array($results), AppsSettings::class) |
63
|
|
|
: $this->mapper->map($results, AppsSettings::class); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* get item. |
68
|
|
|
* |
69
|
|
|
* @param mixed $id |
70
|
|
|
* |
71
|
|
|
* @method GET |
72
|
|
|
* @url /v1/data/{id} |
73
|
|
|
* |
74
|
|
|
* @return \Phalcon\Http\Response |
75
|
|
|
*/ |
76
|
|
|
public function getByKey($key = null): Response |
77
|
|
|
{ |
78
|
|
|
//find the info |
79
|
|
|
$record = $this->model->findFirst([ |
80
|
|
|
'key = ?0 AND is_deleted = 0', |
81
|
|
|
'bind' => [$key], |
82
|
|
|
]); |
83
|
|
|
|
84
|
|
|
//get the results and append its relationships |
85
|
|
|
$result = $this->appendRelationshipsToResult($this->request, $record); |
86
|
|
|
|
87
|
|
|
return $this->response($this->processOutput($result)); |
|
|
|
|
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|