1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace XoopsModules\Pedigree\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
|
|
|
* @package \XoopsModules\Pedigreee |
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\{ |
26
|
|
|
Module\Admin, |
27
|
|
|
Request, |
28
|
|
|
Yaml |
29
|
|
|
}; |
30
|
|
|
use XoopsModules\Pedigree\{ |
31
|
|
|
Constants, |
32
|
|
|
Helper |
33
|
|
|
}; |
34
|
|
|
|
35
|
|
|
/** @var Helper $helper */ |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Class TestdataButtons |
39
|
|
|
* |
40
|
|
|
* Contains methods for to create the Test buttons and change their visibility |
41
|
|
|
*/ |
42
|
|
|
class TestdataButtons |
43
|
|
|
{ |
44
|
|
|
/** Button status constants */ |
45
|
|
|
private const SHOW_BUTTONS = 1; |
46
|
|
|
private const HIDE_BUTTONS = 0; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Load the test button configuration |
50
|
|
|
* |
51
|
|
|
* @param \Xmf\Module\Admin $adminObject |
52
|
|
|
* |
53
|
|
|
* @return void |
54
|
|
|
*/ |
55
|
|
|
public static function loadButtonConfig(Admin $adminObject): void |
56
|
|
|
{ |
57
|
|
|
$moduleDirName = \basename(\dirname(__DIR__, 2)); |
58
|
|
|
$moduleDirNameUpper = mb_strtoupper($moduleDirName); |
59
|
|
|
$helper = Helper::getInstance(); |
60
|
|
|
$yamlFile = $helper->path('/config/admin.yml'); |
61
|
|
|
$config = Yaml::readWrapped($yamlFile); // work with phpmyadmin YAML dumps |
62
|
|
|
$displaySampleButton = $config['displaySampleButton']; |
63
|
|
|
|
64
|
|
|
if (self::SHOW_BUTTONS == $displaySampleButton) { |
65
|
|
|
xoops_loadLanguage('admin/modulesadmin', 'system'); |
66
|
|
|
$adminObject->addItemButton(constant('CO_' . $moduleDirNameUpper . '_' . 'LOAD_SAMPLEDATA'), $helper->url('testdata/index.php?op=load'), 'add'); |
67
|
|
|
$adminObject->addItemButton(constant('CO_' . $moduleDirNameUpper . '_' . 'SAVE_SAMPLEDATA'), $helper->url('testdata/index.php?op=save'), 'add'); |
68
|
|
|
$adminObject->addItemButton(constant('CO_' . $moduleDirNameUpper . '_' . 'CLEAR_SAMPLEDATA'), $helper->url('testdata/index.php?op=clear'), 'alert'); |
69
|
|
|
// $adminObject->addItemButton(constant('CO_' . $moduleDirNameUpper . '_' . 'EXPORT_SCHEMA'), $helper->url( 'testdata/index.php?op=exportschema'), 'add'); |
|
|
|
|
70
|
|
|
$adminObject->addItemButton(constant('CO_' . $moduleDirNameUpper . '_' . 'HIDE_SAMPLEDATA_BUTTONS'), '?op=hide_buttons', 'delete'); |
71
|
|
|
} else { |
72
|
|
|
$adminObject->addItemButton(constant('CO_' . $moduleDirNameUpper . '_' . 'SHOW_SAMPLEDATA_BUTTONS'), '?op=show_buttons', 'add'); |
73
|
|
|
// $displaySampleButton = $config['displaySampleButton']; |
|
|
|
|
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Hide the test buttons |
79
|
|
|
* |
80
|
|
|
* @return void |
81
|
|
|
*/ |
82
|
|
|
public static function hideButtons(): void |
83
|
|
|
{ |
84
|
|
|
$helper = Helper::getInstance(); |
85
|
|
|
$yamlFile = $helper->path('config/admin.yml'); |
86
|
|
|
$app = []; |
87
|
|
|
$app['displaySampleButton'] = self::HIDE_BUTTONS; |
88
|
|
|
Yaml::save($app, $yamlFile); |
89
|
|
|
$helper->redirect('admin/index.php', Constants::REDIRECT_DELAY_NONE, ''); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Show the test buttons |
94
|
|
|
* |
95
|
|
|
* @return void |
96
|
|
|
*/ |
97
|
|
|
public static function showButtons(): void |
98
|
|
|
{ |
99
|
|
|
$helper = Helper::getInstance(); |
100
|
|
|
$yamlFile = $helper->path('config/admin.yml'); |
101
|
|
|
$app = []; |
102
|
|
|
$app['displaySampleButton'] = self::SHOW_BUTTONS; |
103
|
|
|
Yaml::save($app, $yamlFile); |
104
|
|
|
$helper->redirect('admin/index.php', Constants::REDIRECT_DELAY_NONE, ''); |
105
|
|
|
} |
106
|
|
|
} |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.