Settings   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 34
dl 0
loc 78
rs 10
c 0
b 0
f 0
wmc 9

4 Methods

Rating   Name   Duplication   Size   Complexity  
A doActions() 0 6 2
A doSaveAction() 0 32 2
A addNotices() 0 4 2
A __invoke() 0 10 3
1
<?php
2
/**
3
 * Settings page controller class file
4
 *
5
 * @package    EBloodBank
6
 * @subpackage Controllers
7
 * @since      1.0
8
 */
9
namespace EBloodBank\Controllers;
10
11
use InvalidArgumentException;
12
use EBloodBank as EBB;
13
use EBloodBank\Options;
14
use EBloodBank\Notices;
15
16
/**
17
 * Settings page controller class
18
 *
19
 * @since 1.0
20
 */
21
class Settings extends Controller
22
{
23
    /**
24
     * @return void
25
     * @since 1.0
26
     */
27
    public function __invoke()
28
    {
29
        if ($this->hasAuthenticatedUser() && $this->getAcl()->isUserAllowed($this->getAuthenticatedUser(), 'Setting', 'edit')) {
30
            $this->doActions();
31
            $this->addNotices();
32
            $view = $this->viewFactory->forgeView('settings');
33
        } else {
34
            $view = $this->viewFactory->forgeView('error-403');
35
        }
36
        $view();
37
    }
38
39
    /**
40
     * @return void
41
     * @since 1.0
42
     */
43
    protected function doActions()
44
    {
45
        switch (filter_input(INPUT_POST, 'action')) {
46
            case 'save_settings':
47
                $this->doSaveAction();
48
                break;
49
        }
50
    }
51
52
    /**
53
     * @return void
54
     * @since 1.0
55
     */
56
    protected function addNotices()
57
    {
58
        if (filter_has_var(INPUT_GET, 'flag-saved')) {
59
            Notices::addNotice('saved', __('Settings saved.'), 'success');
60
        }
61
    }
62
63
    /**
64
     * @return void
65
     * @since 1.0
66
     */
67
    protected function doSaveAction()
68
    {
69
        try {
70
            /* General Options */
71
            Options::submitOption('site_url', filter_input(INPUT_POST, 'site_url'), true);
72
            Options::submitOption('site_name', filter_input(INPUT_POST, 'site_name'), true);
73
            Options::submitOption('site_slogan', filter_input(INPUT_POST, 'site_slogan'), true);
74
            Options::submitOption('site_email', filter_input(INPUT_POST, 'site_email'), true);
75
            Options::submitOption('site_locale', filter_input(INPUT_POST, 'site_locale'), true);
76
            Options::submitOption('site_theme', filter_input(INPUT_POST, 'site_theme'), true);
77
78
            /* Users Options */
79
            Options::submitOption('self_registration', filter_input(INPUT_POST, 'self_registration'), true);
80
            Options::submitOption('new_user_role', filter_input(INPUT_POST, 'new_user_role'), true);
81
            Options::submitOption('new_user_status', filter_input(INPUT_POST, 'new_user_status'), true);
82
83
            /* Donors Options */
84
            Options::submitOption('default_donor_email_visibility', filter_input(INPUT_POST, 'default_donor_email_visibility'), true);
85
            Options::submitOption('default_donor_phone_visibility', filter_input(INPUT_POST, 'default_donor_phone_visibility'), true);
86
87
            /* Reading Options */
88
            Options::submitOption('site_publication', filter_input(INPUT_POST, 'site_publication'), true);
89
            Options::submitOption('entities_per_page', filter_input(INPUT_POST, 'entities_per_page'), true);
90
91
            EBB\redirect(
0 ignored issues
show
Bug introduced by
The function redirect was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

91
            /** @scrutinizer ignore-call */ 
92
            EBB\redirect(
Loading history...
92
                EBB\addQueryArgs(
0 ignored issues
show
Bug introduced by
The function addQueryArgs was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

92
                /** @scrutinizer ignore-call */ 
93
                EBB\addQueryArgs(
Loading history...
93
                    EBB\getSettingsURL(),
0 ignored issues
show
Bug introduced by
The function getSettingsURL was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

93
                    /** @scrutinizer ignore-call */ 
94
                    EBB\getSettingsURL(),
Loading history...
94
                    ['flag-saved' => true]
95
                )
96
            );
97
        } catch (InvalidArgumentException $ex) {
98
            Notices::addNotice('invalid_option', $ex->getMessage());
99
        }
100
    }
101
}
102