Passed
Push — master ( 077fbd...836ec9 )
by Michael
04:09
created

hideButtons()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 3
dl 0
loc 5
rs 10
c 1
b 0
f 1
cc 1
nc 1
nop 1
1
<?php
2
/*
3
 * You may not change or alter any portion of this comment or credits
4
 * of supporting developers from this source code or any supporting source code
5
 * which is considered copyrighted (c) material of the original comment or credit authors.
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
 */
11
12
/**
13
 * @copyright    {@link https://xoops.org/ XOOPS Project}
14
 * @license      {@link https://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later}
15
 * @package      extcal
16
 * @since
17
 * @author       XOOPS Development Team,
18
 */
19
20
use XoopsModules\Extcal;
21
use XoopsModules\Extcal\Common;
22
23
require_once __DIR__ . '/admin_header.php';
24
// Display Admin header
25
xoops_cp_header();
26
/** @var Extcal\Utility $utility */
27
28
$configurator = new Common\Configurator();
29
30
//count "total categories"
31
/** @var \XoopsPersistableObjectHandler $categoryHandler */
32
$countCategory = $categoryHandler->getCount();
33
//count "total events"
34
/** @var \XoopsPersistableObjectHandler $eventHandler */
35
$countEvent = $eventHandler->getCount();
36
//count "total eventmembers"
37
/** @var \XoopsPersistableObjectHandler $eventMemberHandler */
38
$countEventmember = $eventMemberHandler->getCount();
39
//count "total eventnotmembers"
40
/** @var \XoopsPersistableObjectHandler $eventNotMemberHandler */
41
$countEventnotmember = $eventNotMemberHandler->getCount();
42
//count "total files"
43
/** @var \XoopsPersistableObjectHandler $fileHandler */
44
$countFile = $fileHandler->getCount();
45
//count "total location"
46
/** @var \XoopsPersistableObjectHandler $locationHandler */
47
$countLocation = $locationHandler->getCount();
48
// InfoBox Statistics
49
$adminObject->addInfoBox(AM_EXTCAL_STATISTICS);
50
51
// InfoBox extcal_cat
52
$adminObject->addInfoBoxLine(sprintf(AM_EXTCAL_THEREARE_EXTCAL_CAT, $countCategory));
53
54
// InfoBox extcal_event
55
$adminObject->addInfoBoxLine(sprintf(AM_EXTCAL_THEREARE_EXTCAL_EVENT, $countEvent));
56
57
// InfoBox extcal_eventmember
58
$adminObject->addInfoBoxLine(sprintf(AM_EXTCAL_THEREARE_EXTCAL_EVENTMEMBER, $countEventmember));
59
60
// InfoBox extcal_eventnotmember
61
$adminObject->addInfoBoxLine(sprintf(AM_EXTCAL_THEREARE_EXTCAL_EVENTNOTMEMBER, $countEventnotmember));
62
63
// InfoBox extcal_file
64
$adminObject->addInfoBoxLine(sprintf(AM_EXTCAL_THEREARE_EXTCAL_FILE, $countFile));
65
66
// InfoBox extcal_location
67
$adminObject->addInfoBoxLine(sprintf(AM_EXTCAL_THEREARE_EXTCAL_LOCATION, $countLocation));
68
// Render Index
69
$adminObject->displayNavigation(basename(__FILE__));
70
71
//check for latest release
72
//$newRelease = $utility::checkVerModule($helper);
73
//if (!empty($newRelease)) {
74
//    $adminObject->addItemButton($newRelease[0], $newRelease[1], 'download', 'style="color : Red"');
75
//}
76
77
//------------- Test Data ----------------------------
78
79
if ($helper->getConfig('displaySampleButton')) {
80
    $yamlFile            = dirname(__DIR__) . '/config/admin.yml';
81
    $config              = loadAdminConfig($yamlFile);
82
    $displaySampleButton = $config['displaySampleButton'];
83
84
    if (1 == $displaySampleButton) {
85
        xoops_loadLanguage('admin/modulesadmin', 'system');
86
    require_once dirname(__DIR__) . '/testdata/index.php';
87
88
        $adminObject->addItemButton(constant('CO_' . $moduleDirNameUpper . '_' . 'ADD_SAMPLEDATA'), '__DIR__ . /../../testdata/index.php?op=load', 'add');
89
        $adminObject->addItemButton(constant('CO_' . $moduleDirNameUpper . '_' . 'SAVE_SAMPLEDATA'), '__DIR__ . /../../testdata/index.php?op=save', 'add');
90
        //    $adminObject->addItemButton(constant('CO_' . $moduleDirNameUpper . '_' . 'EXPORT_SCHEMA'), '__DIR__ . /../../testdata/index.php?op=exportschema', 'add');
91
        $adminObject->addItemButton(constant('CO_' . $moduleDirNameUpper . '_' . 'HIDE_SAMPLEDATA_BUTTONS'), '?op=hide_buttons', 'delete');
92
    } else {
93
        $adminObject->addItemButton(constant('CO_' . $moduleDirNameUpper . '_' . 'SHOW_SAMPLEDATA_BUTTONS'), '?op=show_buttons', 'add');
94
        $displaySampleButton = $config['displaySampleButton'];
95
    }
96
    $adminObject->displayButton('left', '');
97
}
98
99
//------------- End Test Data ----------------------------
100
101
$adminObject->displayIndex();
102
103
/**
104
 * @param $yamlFile
105
 * @return array|bool
106
 */
107
function loadAdminConfig($yamlFile)
108
{
109
    $config = \Xmf\Yaml::readWrapped($yamlFile); // work with phpmyadmin YAML dumps
110
    return $config;
111
}
112
113
/**
114
 * @param $yamlFile
115
 */
116
function hideButtons($yamlFile)
117
{
118
    $app['displaySampleButton'] = 0;
0 ignored issues
show
Comprehensibility Best Practice introduced by
$app was never initialized. Although not strictly required by PHP, it is generally a good practice to add $app = array(); before regardless.
Loading history...
119
    \Xmf\Yaml::save($app, $yamlFile);
120
    redirect_header('index.php', 0, '');
121
}
122
123
/**
124
 * @param $yamlFile
125
 */
126
function showButtons($yamlFile)
127
{
128
    $app['displaySampleButton'] = 1;
0 ignored issues
show
Comprehensibility Best Practice introduced by
$app was never initialized. Although not strictly required by PHP, it is generally a good practice to add $app = array(); before regardless.
Loading history...
129
    \Xmf\Yaml::save($app, $yamlFile);
130
    redirect_header('index.php', 0, '');
131
}
132
133
$op = \Xmf\Request::getString('op', 0, 'GET');
134
135
switch ($op) {
136
    case 'hide_buttons':
137
        hideButtons($yamlFile);
138
        break;
139
    case 'show_buttons':
140
        showButtons($yamlFile);
141
        break;
142
}
143
144
echo $utility::getServerStats();
145
146
require __DIR__ . '/admin_footer.php';
147
148