Passed
Push — master ( ac9a19...e11ae0 )
by Michael
13:36 queued 09:25
created

TestdataButtons::hideButtons()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 2
b 0
f 0
nc 1
nop 0
dl 0
loc 7
rs 10
1
<?php declare(strict_types=1);
2
3
namespace XoopsModules\Xoopspoll\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\Xoopspoll\Helper;
24
25
/** @var Helper $helper */
26
27
/**
28
 * Class TestdataButtons
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(\Xmf\Module\Admin $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
        /** @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
     * @return void
70
     */
71
    public static function hideButtons(): void
72
    {
73
        $yamlFile                   = \dirname(__DIR__, 2) . '/config/admin.yml';
74
        $app                        = [];
75
        $app['displaySampleButton'] = self::HIDE_BUTTONS;
76
        Yaml::save($app, $yamlFile);
77
        \redirect_header('index.php', 0, '');
78
    }
79
80
    /**
81
     * Show the test buttons
82
     *
83
     * @return void
84
     */
85
    public static function showButtons(): void
86
    {
87
        $yamlFile                   = \dirname(__DIR__, 2) . '/config/admin.yml';
88
        $app                        = [];
89
        $app['displaySampleButton'] = self::SHOW_BUTTONS;
90
        Yaml::save($app, $yamlFile);
91
        \redirect_header('index.php', 0, '');
92
    }
93
}
94