Passed
Pull Request — master (#799)
by Stefano
02:55
created

AppearenceController   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 10
c 1
b 0
f 0
dl 0
loc 39
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A index() 0 5 1
A save() 0 8 1
1
<?php
2
/**
3
 * BEdita, API-first content management framework
4
 * Copyright 2022 Atlas Srl, Chialab Srl
5
 *
6
 * This file is part of BEdita: you can redistribute it and/or modify
7
 * it under the terms of the GNU Lesser General Public License as published
8
 * by the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * See LICENSE.LGPL or <http://gnu.org/licenses/lgpl-3.0.html> for more details.
12
 */
13
namespace App\Controller\Admin;
14
15
use Cake\Http\Response;
16
use Cake\Utility\Hash;
17
18
/**
19
 * Appearence Controller
20
 *
21
 * @property \App\Controller\Component\ConfigComponent $Config
22
 */
23
class AppearenceController extends AdministrationBaseController
24
{
25
    /**
26
     * Resource type in use
27
     *
28
     * @var string
29
     */
30
    protected $resourceType = 'config';
31
32
    /**
33
     * @inheritDoc
34
     */
35
    protected $readonly = false;
36
37
    /**
38
     * Index method
39
     *
40
     * @return \Cake\Http\Response|null
41
     */
42
    public function index(): ?Response
43
    {
44
        $this->set('modules', $this->Config->read('Modules'));
45
46
        return null;
47
    }
48
49
    /**
50
     * Save data
51
     *
52
     * @return \Cake\Http\Response|null
53
     */
54
    public function save(): ?Response
55
    {
56
        $this->getRequest()->allowMethod(['post']);
57
        $data = (array)$this->getRequest()->getData();
58
        $modules = (string)Hash::get($data, 'Modules');
59
        $this->Config->save('Modules', (array)json_decode($modules, true));
60
61
        return $this->redirect(['_name' => 'admin:list:appearence']);
62
    }
63
}
64