TestdataButtons::showButtons()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

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