Completed
Pull Request — master (#144)
by Michael
03:13
created

Tables::getValuesTables()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 16
nc 1
nop 3
dl 0
loc 20
rs 9.7333
c 0
b 0
f 0
1
<?php
2
3
namespace XoopsModules\Tdmcreate;
4
5
use XoopsModules\Tdmcreate;
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
 * tdmcreate module.
19
 *
20
 * @copyright       XOOPS Project (https://xoops.org)
21
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
22
 *
23
 * @since           2.5.7
24
 *
25
 * @author          Txmod Xoops <[email protected]> - <http://www.txmodxoops.org/>
26
 *
27
 * @version         $Id: 1.91 tables.php 11297 2013-03-24 10:58:10Z timgno $
28
 */
29
// include __DIR__ . '/autoload.php';
30
31
/**
32
 * Class Tables.
33
 */
34
class Tables extends \XoopsObject
35
{
36
    /**
37
     * Options.
38
     */
39
    public $options = [
40
        'install',
41
        'index',
42
        'blocks',
43
        'admin',
44
        'user',
45
        'submenu',
46
        'submit',
47
        'tag',
48
        'broken',
49
        'search',
50
        'comments',
51
        'notifications',
52
        'permissions',
53
        'rate',
54
        'print',
55
        'pdf',
56
        'rss',
57
        'single',
58
        'visit',
59
    ];
60
61
    /**
62
     * @public function constructor class
63
     * @param null
64
     */
65
    public function __construct()
66
    {
67
        $this->initVar('table_id', XOBJ_DTYPE_INT);
68
        $this->initVar('table_mid', XOBJ_DTYPE_INT);
69
        $this->initVar('table_category', XOBJ_DTYPE_INT);
70
        $this->initVar('table_name', XOBJ_DTYPE_TXTBOX);
71
        $this->initVar('table_solename', XOBJ_DTYPE_TXTBOX);
72
        $this->initVar('table_fieldname', XOBJ_DTYPE_TXTBOX);
73
        $this->initVar('table_nbfields', XOBJ_DTYPE_INT);
74
        $this->initVar('table_order', XOBJ_DTYPE_INT);
75
        $this->initVar('table_image', XOBJ_DTYPE_TXTBOX);
76
        $this->initVar('table_autoincrement', XOBJ_DTYPE_INT);
77
        $this->initVar('table_install', XOBJ_DTYPE_INT);
78
        $this->initVar('table_index', XOBJ_DTYPE_INT);
79
        $this->initVar('table_blocks', XOBJ_DTYPE_INT);
80
        $this->initVar('table_admin', XOBJ_DTYPE_INT);
81
        $this->initVar('table_user', XOBJ_DTYPE_INT);
82
        $this->initVar('table_submenu', XOBJ_DTYPE_INT);
83
        $this->initVar('table_submit', XOBJ_DTYPE_INT);
84
        $this->initVar('table_tag', XOBJ_DTYPE_INT);
85
        $this->initVar('table_broken', XOBJ_DTYPE_INT);
86
        $this->initVar('table_search', XOBJ_DTYPE_INT);
87
        $this->initVar('table_comments', XOBJ_DTYPE_INT);
88
        $this->initVar('table_notifications', XOBJ_DTYPE_INT);
89
        $this->initVar('table_permissions', XOBJ_DTYPE_INT);
90
        $this->initVar('table_rate', XOBJ_DTYPE_INT);
91
        $this->initVar('table_print', XOBJ_DTYPE_INT);
92
        $this->initVar('table_pdf', XOBJ_DTYPE_INT);
93
        $this->initVar('table_rss', XOBJ_DTYPE_INT);
94
        $this->initVar('table_single', XOBJ_DTYPE_INT);
95
        $this->initVar('table_visit', XOBJ_DTYPE_INT);
96
    }
97
98
    /**
99
     * @param string $method
100
     * @param array  $args
101
     *
102
     * @return mixed
103
     */
104
    public function __call($method, $args)
105
    {
106
        $arg = isset($args[0]) ? $args[0] : null;
107
108
        return $this->getVar($method, $arg);
109
    }
110
111
    /**
112
     * @static function getInstance
113
     * @param null
114
     * @return Tables
115
     */
116
    public static function getInstance()
117
    {
118
        static $instance = false;
119
        if (!$instance) {
120
            $instance = new self();
121
        }
122
123
        return $instance;
124
    }
125
126
    /**
127
     * @static function getFormTables
128
     * @param mixed $action
129
     *
130
     * @return \XoopsThemeForm
131
     */
132
    public function getFormTables($action = false)
133
    {
134
        if (false === $action) {
135
            $action = $_SERVER['REQUEST_URI'];
136
        }
137
        $helper    = Tdmcreate\Helper::getInstance();
138
        $isNew     = $this->isNew();
139
        $tableName = $this->getVar('table_name');
140
        $tableMid  = $this->getVar('table_mid');
141
        $title     = $isNew ? sprintf(_AM_TDMCREATE_TABLE_NEW) : sprintf(_AM_TDMCREATE_TABLE_EDIT);
142
143
        xoops_load('XoopsFormLoader');
144
        $form = new \XoopsThemeForm($title, 'tableform', $action, 'post', true);
145
        $form->setExtra('enctype="multipart/form-data"');
146
147
        $modules       = $helper->getHandler('Modules')->getObjects(null);
0 ignored issues
show
Bug introduced by
The method getObjects() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of said class. However, the method does not exist in XoopsRankHandler or XoUserHandler. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

147
        $modules       = $helper->getHandler('Modules')->/** @scrutinizer ignore-call */ getObjects(null);
Loading history...
148
        $modulesSelect = new \XoopsFormSelect(_AM_TDMCREATE_TABLE_MODULES, 'table_mid', $tableMid);
149
        $modulesSelect->addOption('', _AM_TDMCREATE_TABLE_MODSELOPT);
150
        foreach ($modules as $mod) {
151
            $modulesSelect->addOption($mod->getVar('mod_id'), $mod->getVar('mod_name'));
152
        }
153
        $form->addElement($modulesSelect, true);
154
155
        $tableNameText = new \XoopsFormText(_AM_TDMCREATE_TABLE_NAME, 'table_name', 40, 150, $tableName);
0 ignored issues
show
Bug introduced by
It seems like $tableName can also be of type array and array; however, parameter $value of XoopsFormText::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

155
        $tableNameText = new \XoopsFormText(_AM_TDMCREATE_TABLE_NAME, 'table_name', 40, 150, /** @scrutinizer ignore-type */ $tableName);
Loading history...
156
        $tableNameText->setDescription(_AM_TDMCREATE_TABLE_NAME_DESC);
157
        $form->addElement($tableNameText, true);
158
159
        $tableSoleNameText = new \XoopsFormText(_AM_TDMCREATE_TABLE_SOLENAME, 'table_solename', 40, 150, $this->getVar('table_solename'));
160
        $tableSoleNameText->setDescription(_AM_TDMCREATE_TABLE_SOLENAME_DESC);
161
        $form->addElement($tableSoleNameText, true);
162
163
        $radioCategory = $isNew ? 0 : $this->getVar('table_category');
164
        $category      = new \XoopsFormRadioYN(_AM_TDMCREATE_TABLE_CATEGORY, 'table_category', $radioCategory);
0 ignored issues
show
Bug introduced by
It seems like $radioCategory can also be of type array and array; however, parameter $value of XoopsFormRadioYN::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

164
        $category      = new \XoopsFormRadioYN(_AM_TDMCREATE_TABLE_CATEGORY, 'table_category', /** @scrutinizer ignore-type */ $radioCategory);
Loading history...
165
        $category->setDescription(_AM_TDMCREATE_TABLE_CATEGORY_DESC);
166
        $form->addElement($category);
167
168
        $tableFieldname = new \XoopsFormText(_AM_TDMCREATE_TABLE_FIELDNAME, 'table_fieldname', 30, 50, $this->getVar('table_fieldname'));
169
        $tableFieldname->setDescription(_AM_TDMCREATE_TABLE_FIELDNAME_DESC);
170
        $form->addElement($tableFieldname);
171
172
        $tableNumbFileds = new \XoopsFormText(_AM_TDMCREATE_TABLE_NBFIELDS, 'table_nbfields', 10, 25, $this->getVar('table_nbfields'));
173
        $tableNumbFileds->setDescription(_AM_TDMCREATE_TABLE_NBFIELDS_DESC);
174
        $form->addElement($tableNumbFileds, true);
175
176
        if (!$isNew) {
177
            $tableOrder = new \XoopsFormText(_AM_TDMCREATE_TABLE_ORDER, 'table_order', 5, 10, $this->getVar('table_order'));
178
            $tableOrder->setDescription(_AM_TDMCREATE_TABLE_ORDER_DESC);
179
            $form->addElement($tableOrder, true);
180
        }
181
182
        $getTableImage    = $this->getVar('table_image');
183
        $tableImage       = $getTableImage ?: 'blank.gif';
184
        $icons32Directory = '/Frameworks/moduleclasses/icons/32';
185
        $uploadsDirectory = '/uploads/tdmcreate/images/tables';
186
        $iconsDirectory   = is_dir(XOOPS_ROOT_PATH . $icons32Directory) ? $icons32Directory : $uploadsDirectory;
187
188
        $imgtray1     = new \XoopsFormElementTray(_AM_TDMCREATE_TABLE_IMAGE, '<br>');
189
        $imgpath1     = sprintf(_AM_TDMCREATE_FORMIMAGE_PATH, ".{$iconsDirectory}/");
190
        $imageSelect1 = new \XoopsFormSelect($imgpath1, 'table_image', $tableImage, 10);
191
        $imageArray1  = \XoopsLists::getImgListAsArray(XOOPS_ROOT_PATH . $iconsDirectory);
192
        foreach ($imageArray1 as $image1) {
193
            $imageSelect1->addOption($image1, $image1);
194
        }
195
        $imageSelect1->setExtra("onchange='showImgSelected(\"image1\", \"table_image\", \"" . $iconsDirectory . '", "", "' . XOOPS_URL . "\")'");
196
        $imgtray1->addElement($imageSelect1, false);
197
        $imgtray1->addElement(new \XoopsFormLabel('', "<br><img src='" . XOOPS_URL . '/' . $iconsDirectory . '/' . $tableImage . "' name='image1' id='image1' alt='' />"));
198
        $fileseltray1 = new \XoopsFormElementTray('', '<br>');
199
        $fileseltray1->addElement(new \XoopsFormFile(_AM_TDMCREATE_FORMUPLOAD, 'attachedfile', $helper->getConfig('maxsize')));
200
        $fileseltray1->addElement(new \XoopsFormLabel(''));
201
        $imgtray1->addElement($fileseltray1);
202
        $imgtray1->setDescription(_AM_TDMCREATE_TABLE_IMAGE_DESC);
203
        $form->addElement($imgtray1);
204
205
        $tableAutoincrement      = $this->isNew() ? 1 : $this->getVar('table_autoincrement');
206
        $checkTableAutoincrement = new \XoopsFormRadioYN(_AM_TDMCREATE_TABLE_AUTO_INCREMENT, 'table_autoincrement', $tableAutoincrement);
207
        $checkTableAutoincrement->setDescription(_AM_TDMCREATE_TABLE_AUTO_INCREMENT_DESC);
208
        $form->addElement($checkTableAutoincrement);
209
210
        $optionsTray = new \XoopsFormElementTray(_OPTIONS, '<br>');
211
212
        $tableCheckAll = new \XoopsFormCheckBox('', 'tablebox', 1);
213
        $tableCheckAll->addOption('allbox', _AM_TDMCREATE_TABLE_ALL);
214
        $tableCheckAll->setExtra(' onclick="xoopsCheckAll(\'tableform\', \'tablebox\');" ');
215
        $tableCheckAll->setClass('xo-checkall');
216
        $optionsTray->addElement($tableCheckAll);
217
        // Options
218
        $checkbox = new \XoopsFormCheckbox(' ', 'table_option', $this->getOptionsTables(), '<br>');
219
        $checkbox->setDescription(_AM_TDMCREATE_OPTIONS_DESC);
220
        foreach ($this->options as $option) {
221
            $checkbox->addOption($option, self::getDefinedLanguage('_AM_TDMCREATE_TABLE_' . mb_strtoupper($option)));
222
        }
223
        $optionsTray->addElement($checkbox);
224
225
        $optionsTray->setDescription(_AM_TDMCREATE_TABLE_OPTIONS_CHECKS_DESC);
226
227
        $form->addElement($optionsTray);
228
229
        $buttonTray = new \XoopsFormElementTray(_REQUIRED . ' <sup class="red bold">*</sup>', '');
230
        $buttonTray->addElement(new \XoopsFormHidden('op', 'save'));
231
        $buttonTray->addElement(new \XoopsFormHidden('table_id', ($isNew ? 0 : $this->getVar('table_id'))));
0 ignored issues
show
Bug introduced by
It seems like $isNew ? 0 : $this->getVar('table_id') can also be of type array and array; however, parameter $value of XoopsFormHidden::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

231
        $buttonTray->addElement(new \XoopsFormHidden('table_id', /** @scrutinizer ignore-type */ ($isNew ? 0 : $this->getVar('table_id'))));
Loading history...
232
        $buttonTray->addElement(new \XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
233
        $form->addElement($buttonTray);
234
235
        return $form;
236
    }
237
238
    /**
239
     * Get Values.
240
     *
241
     * @param null $keys
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $keys is correct as it would always require null to be passed?
Loading history...
242
     * @param null $format
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $format is correct as it would always require null to be passed?
Loading history...
243
     * @param null $maxDepth
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $maxDepth is correct as it would always require null to be passed?
Loading history...
244
     *
245
     * @return array
246
     */
247
    public function getValuesTables($keys = null, $format = null, $maxDepth = null)
248
    {
249
        $ret = $this->getValues($keys, $format, $maxDepth);
250
        // Values
251
        $ret['id']            = $this->getVar('table_id');
252
        $ret['mid']           = $this->getVar('table_mid');
253
        $ret['name']          = ucfirst($this->getVar('table_name'));
0 ignored issues
show
Bug introduced by
It seems like $this->getVar('table_name') can also be of type array and array; however, parameter $str of ucfirst() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

253
        $ret['name']          = ucfirst(/** @scrutinizer ignore-type */ $this->getVar('table_name'));
Loading history...
254
        $ret['image']         = $this->getVar('table_image');
255
        $ret['nbfields']      = $this->getVar('table_nbfields');
256
        $ret['order']         = $this->getVar('table_order');
257
        $ret['blocks']        = $this->getVar('table_blocks');
258
        $ret['admin']         = $this->getVar('table_admin');
259
        $ret['user']          = $this->getVar('table_user');
260
        $ret['submenu']       = $this->getVar('table_submenu');
261
        $ret['search']        = $this->getVar('table_search');
262
        $ret['comments']      = $this->getVar('table_comments');
263
        $ret['notifications'] = $this->getVar('table_notifications');
264
        $ret['permissions']   = $this->getVar('table_permissions');
265
266
        return $ret;
267
    }
268
269
    /**
270
     * Get Options.
271
     *
272
     * @return array
273
     */
274
    public function getOptionsTables()
275
    {
276
        $retTable = [];
277
        foreach ($this->options as $option) {
278
            if (1 == $this->getVar('table_' . $option)) {
279
                $retTable[] = $option;
280
            }
281
        }
282
283
        return $retTable;
284
    }
285
286
    /**
287
     * Get Defined Language.
288
     *
289
     * @param $lang
290
     *
291
     * @return string
292
     */
293
    private static function getDefinedLanguage($lang)
294
    {
295
        if (defined($lang)) {
296
            return constant($lang);
297
        }
298
299
        return $lang;
300
    }
301
}
302