TestdataButtons::showButtons()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 7
rs 10
1
<?php declare(strict_types=1);
2
3
namespace XoopsModules\Xhelp\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
 * @author          XOOPS Development Team <https://xoops.org>
17
 * @copyright       {@link https://xoops.org/ XOOPS Project}
18
 * @license         GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html)
19
 */
20
21
use Xmf\Yaml;
22
use XoopsModules\Xhelp\Helper;
23
24
/**
25
 * Class TestdataButtons
26
 */
27
class TestdataButtons
28
{    /** Button status constants */
29
    private const SHOW_BUTTONS = 1;
30
    private const HIDE_BUTTONS = 0;
31
32
    /**
33
     * Load the test button configuration
34
     *
35
     * @param \Xmf\Module\Admin $adminObject
36
     *
37
     * @return void
38
     */
39
    public static function loadButtonConfig(\Xmf\Module\Admin $adminObject): void
40
    {
41
        $moduleDirName       = \basename(\dirname(__DIR__, 2));
42
        $moduleDirNameUpper  = \mb_strtoupper($moduleDirName);
43
        $yamlFile            = \dirname(__DIR__, 2) . '/config/admin.yml';
44
        $config[]            = Yaml::readWrapped($yamlFile); // work with phpmyadmin YAML dumps
0 ignored issues
show
Comprehensibility Best Practice introduced by
$config was never initialized. Although not strictly required by PHP, it is generally a good practice to add $config = array(); before regardless.
Loading history...
45
        $displaySampleButton = $config[0]['displaySampleButton'];
46
        $helper              = Helper::getInstance();
47
48
        if (self::SHOW_BUTTONS == $displaySampleButton) {
49
            \xoops_loadLanguage('admin/modulesadmin', 'system');
50
            $adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'LOAD_SAMPLEDATA'), $helper->url('testdata/index.php?op=load'), 'add');
51
            $adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'SAVE_SAMPLEDATA'), $helper->url('testdata/index.php?op=save'), 'add');
52
            $adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'CLEAR_SAMPLEDATA'), $helper->url('testdata/index.php?op=clear'), 'alert');
53
            //    $adminObject->addItemButton(constant('CO_' . $moduleDirNameUpper . '_' . 'EXPORT_SCHEMA'), $helper->url( 'testdata/index.php?op=exportschema'), 'add');
54
            $adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'HIDE_SAMPLEDATA_BUTTONS'), '?op=hide_buttons', 'delete');
55
        } else {
56
            $adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'SHOW_SAMPLEDATA_BUTTONS'), '?op=show_buttons', 'add');
57
            // $displaySampleButton = $config['displaySampleButton'];
58
        }
59
    }
60
61
    /**
62
     * Hide the test buttons
63
     *
64
     * @return void
65
     */
66
    public static function hideButtons(): void
67
    {
68
        $yamlFile                   = \dirname(__DIR__, 2) . '/config/admin.yml';
69
        $app                        = [];
70
        $app['displaySampleButton'] = self::HIDE_BUTTONS;
71
        Yaml::save($app, $yamlFile);
72
        \redirect_header('index.php', 0, '');
73
    }
74
75
    /**
76
     * Show the test buttons
77
     *
78
     * @return void
79
     */
80
    public static function showButtons(): void
81
    {
82
        $yamlFile                   = \dirname(__DIR__, 2) . '/config/admin.yml';
83
        $app                        = [];
84
        $app['displaySampleButton'] = self::SHOW_BUTTONS;
85
        Yaml::save($app, $yamlFile);
86
        \redirect_header('index.php', 0, '');
87
    }
88
}
89