TestdataButtons   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 4
eloc 27
c 2
b 1
f 0
dl 0
loc 62
rs 10

3 Methods

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