TestdataButtons::loadButtonConfig()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

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