Issues (538)

programs/Ctrl/AppCtrlAddonConfiguration.php (1 issue)

Labels
Severity
1
<?php
2
//-------------------------------------------------------------------------
3
// OVIDENTIA http://www.ovidentia.org
4
// Ovidentia is free software; you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation; either version 2, or (at your option)
7
// any later version.
8
//
9
// This program is distributed in the hope that it will be useful, but
10
// WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
// See the GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with this program; if not, write to the Free Software
16
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
17
// USA.
18
//-------------------------------------------------------------------------
19
/**
20
 * @license http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL)
21
 * @copyright Copyright (c) 2022 by SI4YOU ({@link https://www.siforyou.com})
22
 */
23
namespace Capwelton\LibApp\Ctrl;
24
25
use Capwelton\LibApp\Exceptions\AppAccessException;
26
use Capwelton\LibApp\Ui\AppUi;
27
use Capwelton\LibApp\Ui\AppEditor;
28
use Capwelton\Widgets\Widgets\Item\WidgetLink;
0 ignored issues
show
The type Capwelton\Widgets\Widgets\Item\WidgetLink was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
29
30
/**
31
 * This controller manages actions that can be performed on addon configuration
32
 * @method self proxy()
33
 */
34
class AppCtrlAddonConfiguration extends AppController
35
{
36
    public function display()
37
    {
38
        $App = $this->App();
39
        if(!bab_isUserAdministrator()) {
40
            throw new AppAccessException($App->translate('You do not have access to this page'));
41
        }
42
        
43
        $W = bab_Widgets();
44
        $App->includeUi();
45
        $Ui = new AppUi($App);
46
        $page = $Ui->Page();
47
        
48
        $configurationFrame = $W->Frame()
49
        ->setLayout($W->VBoxLayout()->setVerticalSpacing(1, 'em'))
50
        ->addClass(\Func_Icons::ICON_LEFT_48);
51
        
52
        $configurationFrame->addItem($W->Title($App->translate('LibApp configuration'), 1));
53
        
54
        $page->addItem($configurationFrame);
55
        
56
        $configurationFrame->addItem(
57
            $box = $W->FlowItems()
58
            ->setHorizontalSpacing(1, 'em')
59
            ->setVerticalSpacing(1, 'em')
60
            ->setVerticalAlign('top')
61
        );
62
        
63
        $box->addItem(
64
            $W->FlowItems(
65
                $W->Link(
66
                    $App->translate('SSE'),
67
                    $this->proxy()->configureSSE()
68
                )->setOpenMode(WidgetLink::OPEN_DIALOG)
69
            )->addClass('icon', \Func_Icons::ACTIONS_VIEW_LIST_DETAILS)->setSizePolicy('widget-25pc')
70
        );
71
        
72
        return $page;
73
    }
74
    
75
    public function configureSSE()
76
    {
77
        $App = $this->App();
78
        if(!bab_isUserAdministrator()) {
79
            throw new AppAccessException($App->translate('You do not have access to this page'));
80
        }
81
        
82
        $W = bab_Widgets();
83
        $App->includeUi();
84
        $Ui = new AppUi($App);
85
        $page = $Ui->Page();
86
        $page->setTitle($App->translate('SSE'));
87
        
88
        $registry = app_getRegistry();
89
        $registry->changeDirectory('configuration');
90
        $registry->changeDirectory('SSE');
91
        $enabled = $registry->getValue('enabled', false);
92
        $refreshFrequency = $registry->getValue('refreshFrequency', 3);
93
        
94
        $editor = new AppEditor($App);
95
        $editor->setName('data');
96
        $editor->setHiddenValue('tg', bab_rp('tg'));
97
        $editor->isAjax = true;
98
        
99
        $editor->addItem(
100
            $W->LabelledWidget(
101
                $App->translate('Enable SSE'),
102
                $enableSSE = $W->CheckBox()->setCheckedValue('1')->setValue($enabled),
103
                'enabled'
104
            )
105
        );
106
        
107
        $editor->addItem(
108
            $sseRefreshFrequency = $W->LabelledWidget(
109
                $App->translate('Refresh frequency (in seconds)'),
110
                $W->NumberEdit()->setMin(1)->setValue($refreshFrequency),
111
                'refreshFrequency'
112
            )
113
        );
114
        
115
        $enableSSE->setAssociatedDisplayable($sseRefreshFrequency, array(1, '1'));
116
        
117
        $editor->setSaveAction($this->proxy()->saveSSE());
118
        
119
        $page->addItem($editor);
120
        
121
        return $page;
122
    }
123
    
124
    public function saveSSE($data = null)
125
    {
126
        $this->requireSaveMethod();
127
        
128
        $registry = app_getRegistry();
129
        $registry->changeDirectory('configuration');
130
        $registry->changeDirectory('SSE');
131
        
132
        $enabled = isset($data['enabled']) && $data['enabled'];
133
        $registry->setKeyValue('enabled', $enabled);
134
        
135
        $refreshFrequency = isset($data['refreshFrequency']) && $data['refreshFrequency'] >= 1 ? $data['refreshFrequency'] : 1;
136
        $registry->setKeyValue('refreshFrequency', $refreshFrequency);
137
        
138
        return true;
139
    }
140
}