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