Passed
Pull Request — master (#11)
by Michael
11:08
created

TestdataButtons::showButtons()   A

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
2
3
declare(strict_types=1);
4
5
namespace XoopsModules\Xoopsfaq\Common;
6
7
/*
8
 You may not change or alter any portion of this comment or credits
9
 of supporting developers from this source code or any supporting source code
10
 which is considered copyrighted (c) material of the original comment or credit authors.
11
 
12
 This program is distributed in the hope that it will be useful,
13
 but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
*/
16
17
/**
18
 *
19
 * @category        Module
20
 * @author          XOOPS Development Team <https://xoops.org>
21
 * @copyright       {@link https://xoops.org/ XOOPS Project}
22
 * @license         GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html)
23
 */
24
25
use Xmf\Module\Admin;
26
use Xmf\Request;
27
use Xmf\Yaml;
28
use XoopsModules\Xoopsfaq\{
29
    Helper
30
};
31
/** @var Helper $helper */
32
33
/**
34
 * Class TestdataButtons
35
 */
36
class TestdataButtons
37
{
38
39
    //functions for import buttons
40
    public static function loadButtonConfig(Admin $adminObject): void
41
    {
42
        $moduleDirName      = \basename(\dirname(__DIR__, 2));
43
        $moduleDirNameUpper = \mb_strtoupper($moduleDirName);
44
        $yamlFile           = \dirname(__DIR__, 2) . '/config/admin.yml';
45
        $config             = Yaml::readWrapped($yamlFile); // work with phpmyadmin YAML dumps
46
        $displaySampleButton = $config['displaySampleButton'];
47
        $helper = Helper::getInstance();
48
49
        if (1 === $displaySampleButton) {
50
            \xoops_loadLanguage('admin/modulesadmin', 'system');
51
            $adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'LOAD_SAMPLEDATA'), $helper->url('testdata/index.php?op=load'), 'add');
52
            $adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'SAVE_SAMPLEDATA'), $helper->url('testdata/index.php?op=save'), 'add');
53
            $adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'CLEAR_SAMPLEDATA'), $helper->url('testdata/index.php?op=clear'), 'alert');
54
            //    $adminObject->addItemButton(constant('CO_' . $moduleDirNameUpper . '_' . 'EXPORT_SCHEMA'), $helper->url( 'testdata/index.php?op=exportschema'), 'add');
55
            $adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'HIDE_SAMPLEDATA_BUTTONS'), '?op=hide_buttons', 'delete');
56
        } else {
57
            $adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'SHOW_SAMPLEDATA_BUTTONS'), '?op=show_buttons', 'add');
58
            // $displaySampleButton = $config['displaySampleButton'];
59
        }
60
    }
61
62
    public static function hideButtons(): void
63
    {
64
        $yamlFile            = \dirname(__DIR__, 2) . '/config/admin.yml';
65
        $app                        = [];
66
        $app['displaySampleButton'] = 0;
67
        Yaml::save($app, $yamlFile);
68
        \redirect_header('index.php', 0, '');
69
    }
70
71
    public static function showButtons(): void
72
    {
73
        $yamlFile            = \dirname(__DIR__, 2) . '/config/admin.yml';
74
        $app                        = [];
75
        $app['displaySampleButton'] = 1;
76
        Yaml::save($app, $yamlFile);
77
        \redirect_header('index.php', 0, '');
78
    }
79
}
80
81