MoreFiles::__call()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
nc 2
nop 2
dl 0
loc 5
rs 10
c 1
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
 * morefiles class.
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
 */
28
//include __DIR__.'/autoload.php';
29
/*
30
*  @Class MoreFiles
31
*  @extends \XoopsObject
32
*/
33
34
/**
35
 * Class MoreFiles.
36
 */
37
class MoreFiles extends \XoopsObject
38
{
39
    /**
40
     * Settings.
41
     *
42
     * @var mixed
43
     */
44
    private $settings;
0 ignored issues
show
introduced by
The private property $settings is not used, and could be removed.
Loading history...
45
46
    /**
47
     * @public function constructor class
48
     *
49
     * @param null
50
     */
51
    public function __construct()
52
    {
53
        $this->initVar('file_id', XOBJ_DTYPE_INT);
54
        $this->initVar('file_mid', XOBJ_DTYPE_INT);
55
        $this->initVar('file_name', XOBJ_DTYPE_TXTBOX);
56
        $this->initVar('file_extension', XOBJ_DTYPE_TXTBOX);
57
        $this->initVar('file_infolder', XOBJ_DTYPE_TXTBOX);
58
    }
59
60
    /**
61
     * @param string $method
62
     * @param array  $args
63
     *
64
     * @return mixed
65
     */
66
    public function __call($method, $args)
67
    {
68
        $arg = isset($args[0]) ? $args[0] : null;
69
70
        return $this->getVar($method, $arg);
71
    }
72
73
    /**
74
     * @static function getInstance
75
     *
76
     * @param null
77
     *
78
     * @return MoreFiles
79
     */
80
    public static function getInstance()
81
    {
82
        static $instance = false;
83
        if (!$instance) {
84
            $instance = new self();
85
        }
86
87
        return $instance;
88
    }
89
90
    /**
91
     * @public function getFormMoreFiles
92
     *
93
     * @param bool|mixed $action
94
     * @return \XoopsThemeForm
95
     */
96
    public function getFormMoreFiles($action = false)
97
    {
98
        $helper = Tdmcreate\Helper::getInstance();
99
        if (false === $action) {
100
            $action = \Xmf\Request::getString('REQUEST_URI', '', 'SERVER');
101
        }
102
103
        $isNew = $this->isNew();
104
        $title = $isNew ? sprintf(_AM_TDMCREATE_MORE_FILES_NEW) : sprintf(_AM_TDMCREATE_MORE_FILES_EDIT);
105
106
        xoops_load('XoopsFormLoader');
107
108
        $form = new \XoopsThemeForm($title, 'morefilesform', $action, 'post', true);
109
        $form->setExtra('enctype="multipart/form-data"');
110
111
        $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

111
        $modules       = $helper->getHandler('Modules')->/** @scrutinizer ignore-call */ getObjects(null);
Loading history...
112
        $modulesSelect = new \XoopsFormSelect(_AM_TDMCREATE_MORE_FILES_MODULES, 'file_mid', $this->getVar('file_mid'));
113
        $modulesSelect->addOption('', _AM_TDMCREATE_MORE_FILES_MODULE_SELECT);
114
        foreach ($modules as $mod) {
115
            //$modulesSelect->addOptionArray();
116
            $modulesSelect->addOption($mod->getVar('mod_id'), $mod->getVar('mod_name'));
117
        }
118
        $form->addElement($modulesSelect, true);
119
120
        $modName = new \XoopsFormText(_AM_TDMCREATE_MORE_FILES_NAME, 'file_name', 50, 255, $this->getVar('file_name'));
0 ignored issues
show
Bug introduced by
It seems like $this->getVar('file_name') 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

120
        $modName = new \XoopsFormText(_AM_TDMCREATE_MORE_FILES_NAME, 'file_name', 50, 255, /** @scrutinizer ignore-type */ $this->getVar('file_name'));
Loading history...
121
        $modName->setDescription(_AM_TDMCREATE_MORE_FILES_NAME_DESC);
122
        $form->addElement($modName, true);
123
124
        $fileEstension = new \XoopsFormText(_AM_TDMCREATE_MORE_FILES_EXTENSION, 'file_extension', 50, 255, $this->getVar('file_extension'));
125
        $fileEstension->setDescription(_AM_TDMCREATE_MORE_FILES_EXTENSION_DESC);
126
        $form->addElement($fileEstension, true);
127
128
        $fileInfolder = new \XoopsFormText(_AM_TDMCREATE_MORE_FILES_INFOLDER, 'file_infolder', 50, 255, $this->getVar('file_infolder'));
129
        $fileInfolder->setDescription(_AM_TDMCREATE_MORE_FILES_INFOLDER_DESC);
130
        $form->addElement($fileInfolder, true);
131
132
        $form->addElement(new \XoopsFormHidden('op', 'save'));
133
        $form->addElement(new \XoopsFormButton(_REQUIRED . ' <sup class="red bold">*</sup>', 'submit', _SUBMIT, 'submit'));
134
135
        return $form;
136
    }
137
138
    /**
139
     * Get Values.
140
     *
141
     * @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...
142
     * @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...
143
     * @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...
144
     *
145
     * @return array
146
     */
147
    public function getValuesMoreFiles($keys = null, $format = null, $maxDepth = null)
148
    {
149
        $helper = Tdmcreate\Helper::getInstance();
150
        $ret    = $this->getValues($keys, $format, $maxDepth);
151
        // Values
152
        $ret['id']        = $this->getVar('file_id');
153
        $ret['mid']       = $helper->getHandler('Modules')->get($this->getVar('file_mid'))->getVar('mod_name');
154
        $ret['name']      = $this->getVar('file_name');
155
        $ret['extension'] = $this->getVar('file_extension');
156
        $ret['infolder']  = $this->getVar('file_infolder');
157
158
        return $ret;
159
    }
160
}
161