TestdataButtons   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 25
c 1
b 0
f 0
dl 0
loc 42
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A hideButtons() 0 7 1
A loadButtonConfig() 0 18 2
A showButtons() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace XoopsModules\Xlanguage\Common;
6
7
/*
8
 You may not change or alter any portion of this comment or credits
9
 of supporting developers from this source code or any supporting source code
10
 which is considered copyrighted (c) material of the original comment or credit authors.
11
 
12
 This program is distributed in the hope that it will be useful,
13
 but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
*/
16
17
/**
18
 *
19
 * @category        Module
20
 * @author          XOOPS Development Team <https://xoops.org>
21
 * @copyright       {@link https://xoops.org/ XOOPS Project}
22
 * @license         GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html)
23
 */
24
25
use Xmf\Request;
26
use Xmf\Yaml;
27
use XoopsModules\Xlanguage\Helper;
28
/** @var Helper $helper */
29
30
/**
31
 * Class SysUtility
32
 */
33
class TestdataButtons
34
{
35
36
    //functions for import buttons
37
    public static function loadButtonConfig($adminObject)
38
    {
39
        $moduleDirName      = \basename(\dirname(__DIR__, 2));
40
        $moduleDirNameUpper = mb_strtoupper($moduleDirName);
41
        $yamlFile           = \dirname(__DIR__, 2) . '/config/admin.yml';
42
        $config             = Yaml::readWrapped($yamlFile); // work with phpmyadmin YAML dumps
43
        $displaySampleButton = $config['displaySampleButton'];
44
        $helper = Helper::getInstance();
45
46
        if (1 == $displaySampleButton) {
47
            \xoops_loadLanguage('admin/modulesadmin', 'system');
48
            $adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'LOAD_SAMPLEDATA'), $helper->url('testdata/index.php?op=load'), 'add');
49
            $adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'SAVE_SAMPLEDATA'), $helper->url('testdata/index.php?op=save'), 'add');
50
            $adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'CLEAR_SAMPLEDATA'), $helper->url('testdata/index.php?op=clear'), 'alert');
51
            //    $adminObject->addItemButton(constant('CO_' . $moduleDirNameUpper . '_' . 'EXPORT_SCHEMA'), $helper->url( 'testdata/index.php?op=exportschema'), 'add');
52
            $adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'HIDE_SAMPLEDATA_BUTTONS'), '?op=hide_buttons', 'delete');
53
        } else {
54
            $adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'SHOW_SAMPLEDATA_BUTTONS'), '?op=show_buttons', 'add');
55
            // $displaySampleButton = $config['displaySampleButton'];
56
        }
57
    }
58
59
    public static function hideButtons()
60
    {
61
        $yamlFile            = \dirname(__DIR__, 2) . '/config/admin.yml';
62
        $app                        = [];
63
        $app['displaySampleButton'] = 0;
64
        Yaml::save($app, $yamlFile);
65
        \redirect_header('index.php', 0, '');
66
    }
67
68
    public static function showButtons()
69
    {
70
        $yamlFile            = \dirname(__DIR__, 2) . '/config/admin.yml';
71
        $app                        = [];
72
        $app['displaySampleButton'] = 1;
73
        Yaml::save($app, $yamlFile);
74
        \redirect_header('index.php', 0, '');
75
    }
76
}
77