Settings::setTitleEditSettings()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
/**
4
 * @package Stripe
5
 * @author Iurii Makukh <[email protected]>
6
 * @copyright Copyright (c) 2017, Iurii Makukh <[email protected]>
7
 * @license https://www.gnu.org/licenses/gpl-3.0.en.html GNU General Public License 3.0
8
 */
9
10
namespace gplcart\modules\stripe\controllers;
11
12
use gplcart\core\controllers\backend\Controller;
13
use gplcart\core\models\Order;
14
15
/**
16
 * Handles incoming requests and outputs data related to Stripe module
17
 */
18
class Settings extends Controller
19
{
20
21
    /**
22
     * Order model instance
23
     * @var \gplcart\core\models\Order $order
24
     */
25
    protected $order;
26
27
    /**
28
     * Settings constructor.
29
     * @param Order $order
30
     */
31
    public function __construct(Order $order)
32
    {
33
        parent::__construct();
34
35
        $this->order = $order;
36
    }
37
38
    /**
39
     * Route page callback to display module settings form
40
     */
41
    public function editSettings()
42
    {
43
        $this->setTitleEditSettings();
44
        $this->setBreadcrumbEditSettings();
45
46
        $this->setData('statuses', $this->order->getStatuses());
47
        $this->setData('settings', $this->module->getSettings('stripe'));
48
49
        $this->submitSettings();
50
        $this->outputEditSettings();
51
    }
52
53
    /**
54
     * Saves the submitted settings
55
     */
56
    protected function submitSettings()
57
    {
58
        if ($this->isPosted('save') && $this->validateSettings()) {
59
            $this->updateSettings();
60
        }
61
    }
62
63
    /**
64
     * Updates module settings
65
     */
66
    protected function updateSettings()
67
    {
68
        $this->controlAccess('module_edit');
69
        $this->module->setSettings('stripe', $this->getSubmitted());
70
        $this->redirect('admin/module/list', $this->text('Settings have been updated'), 'success');
71
    }
72
73
    /**
74
     * Validates module settings
75
     * @return bool
76
     */
77
    protected function validateSettings()
78
    {
79
        $this->setSubmitted('settings');
80
        $this->setSubmittedBool('status');
81
        return !$this->hasErrors('settings');
82
    }
83
84
    /**
85
     * Set title on the edit module settings page
86
     */
87
    protected function setTitleEditSettings()
88
    {
89
        $title = $this->text('Edit %name settings', array('%name' => $this->text('Stripe')));
90
        $this->setTitle($title);
91
    }
92
93
    /**
94
     * Set breadcrumbs on the edit module settings page
95
     */
96
    protected function setBreadcrumbEditSettings()
97
    {
98
        $breadcrumbs = array();
99
100
        $breadcrumbs[] = array(
101
            'text' => $this->text('Dashboard'),
102
            'url' => $this->url('admin')
103
        );
104
105
        $breadcrumbs[] = array(
106
            'text' => $this->text('Modules'),
107
            'url' => $this->url('admin/module/list')
108
        );
109
110
        $this->setBreadcrumbs($breadcrumbs);
111
    }
112
113
    /**
114
     * Render and output the edit module settings page
115
     */
116
    protected function outputEditSettings()
117
    {
118
        $this->output('stripe|settings');
119
    }
120
121
}
122