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