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