TestdataButtons::hideButtons()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 7
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace XoopsModules\Myiframe\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\{
26
    Module\Admin,
27
    Request,
28
    Yaml
29
};
30
use XoopsModules\Myiframe\{
31
    Helper
32
};
33
34
/** @var Helper $helper */
35
36
/**
37
 * Class TestdataButtons
38
 *
39
 * Contains methods to create the Test buttons and change their visibility
40
 */
41
class TestdataButtons
42
{
43
    /** Button status constants */
44
    private const SHOW_BUTTONS = 1;
45
    private const HIDE_BUTTONS = 0;
46
47
    /**
48
     * Load the test button configuration
49
     *
50
     * @param \Xmf\Module\Admin $adminObject
51
     *
52
     * @return void
53
     */
54
    public static function loadButtonConfig($adminObject): void
55
    {
56
        $moduleDirName      = \basename(\dirname(__DIR__, 2));
57
        $moduleDirNameUpper = \mb_strtoupper($moduleDirName);
58
        $helper             = Helper::getInstance();
59
        $yamlFile           = $helper->path('/config/admin.yml');
60
        /** @var array $config */
61
        $config              = Yaml::readWrapped($yamlFile); // work with phpmyadmin YAML dumps
62
        $displaySampleButton = $config['displaySampleButton'];
63
64
        if (self::SHOW_BUTTONS == $displaySampleButton) {
65
            \xoops_loadLanguage('admin/modulesadmin', 'system');
66
            $adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'LOAD_SAMPLEDATA'), $helper->url('testdata/index.php?op=load'), 'add');
67
            $adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'SAVE_SAMPLEDATA'), $helper->url('testdata/index.php?op=save'), 'add');
68
            $adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'CLEAR_SAMPLEDATA'), $helper->url('testdata/index.php?op=clear'), 'alert');
69
            //    $adminObject->addItemButton(constant('CO_' . $moduleDirNameUpper . '_' . 'EXPORT_SCHEMA'), $helper->url( 'testdata/index.php?op=exportschema'), 'add');
70
            $adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'HIDE_SAMPLEDATA_BUTTONS'), '?op=hide_buttons', 'delete');
71
        } else {
72
            $adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'SHOW_SAMPLEDATA_BUTTONS'), '?op=show_buttons', 'add');
73
            // $displaySampleButton = $config['displaySampleButton'];
74
        }
75
    }
76
77
    /**
78
     * Hide the test buttons
79
     *
80
     * @return void
81
     */
82
    public static function hideButtons(): void
83
    {
84
        $yamlFile                   = \dirname(__DIR__, 2) . '/config/admin.yml';
85
        $app                        = [];
86
        $app['displaySampleButton'] = 0;
87
        Yaml::save($app, $yamlFile);
88
        \redirect_header('index.php', 0, '');
89
    }
90
91
    /**
92
     * Show the test buttons
93
     *
94
     * @return void
95
     */
96
    public static function showButtons(): void
97
    {
98
        $yamlFile                   = \dirname(__DIR__, 2) . '/config/admin.yml';
99
        $app                        = [];
100
        $app['displaySampleButton'] = 1;
101
        Yaml::save($app, $yamlFile);
102
        \redirect_header('index.php', 0, '');
103
    }
104
}
105