Passed
Push — master ( a29a7e...12a432 )
by Mihail
08:06
created

ActionSettings   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 27
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A settings() 0 20 4
1
<?php
2
3
namespace Apps\Controller\Admin\Main;
4
5
use Apps\Model\Admin\Main\FormSettings;
6
use Ffcms\Core\App;
7
use Ffcms\Core\Arch\View;
8
use Ffcms\Core\Network\Request;
9
use Ffcms\Core\Network\Response;
10
11
/**
12
 * Trait ActionSettings
13
 * @package Apps\Controller\Admin\Main
14
 * @property Request $request
15
 * @property Response $response
16
 * @property View $view
17
 */
18
trait ActionSettings
19
{
20
    /**
21
     * Manage settings in web
22
     * @return string
23
     * @throws \Ffcms\Core\Exception\SyntaxException
24
     */
25
    public function settings()
26
    {
27
        // init settings model and process post send
28
        $model = new FormSettings(true);
29
        if ($model->send()) {
30
            if ($model->validate()) {
31
                if ($model->makeSave()) {
32
                    // show message about successful save and take system some time ;)
33
                    return $this->view->render('settings_save');
34
                } else {
35
                    App::$Session->getFlashBag()->add('error', __('Configuration file is not writable! Check /Private/Config/ dir and files'));
36
                }
37
            } else {
38
                App::$Session->getFlashBag()->add('error', __('Validation of form data is failed!'));
39
            }
40
        }
41
42
        // render output view
43
        return $this->view->render('settings', [
44
            'model' => $model
45
        ]);
46
    }
47
}
48