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 namespace XoopsModules\Tdmcreate;
2
3
use XoopsModules\Tdmcreate;
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
 * morefiles class.
17
 *
18
 * @copyright       XOOPS Project (https://xoops.org)
19
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
20
 *
21
 * @since           2.5.7
22
 *
23
 * @author          Txmod Xoops <[email protected]> - <http://www.txmodxoops.org/>
24
 *
25
 * @version         $Id: morefiles.php 13080 2015-06-12 10:12:32Z timgno $
26
 */
27
//include __DIR__.'/autoload.php';
28
/*
29
*  @Class MoreFiles
30
*  @extends \XoopsObject
31
*/
32
33
/**
34
 * Class MoreFiles.
35
 */
36
class MoreFiles extends \XoopsObject
37
{
38
    /**
39
     * Settings.
40
     *
41
     * @var mixed
42
     */
43
    private $settings;
0 ignored issues
show
introduced by
The private property $settings is not used, and could be removed.
Loading history...
44
45
    /**
46
     *  @public function constructor class
47
     *
48
     *  @param null
49
     */
50
    public function __construct()
51
    {
52
        $this->initVar('file_id', XOBJ_DTYPE_INT);
53
        $this->initVar('file_mid', XOBJ_DTYPE_INT);
54
        $this->initVar('file_name', XOBJ_DTYPE_TXTBOX);
55
        $this->initVar('file_extension', XOBJ_DTYPE_TXTBOX);
56
        $this->initVar('file_infolder', XOBJ_DTYPE_TXTBOX);
57
    }
58
59
    /**
60
     * @param string $method
61
     * @param array  $args
62
     *
63
     * @return mixed
64
     */
65
    public function __call($method, $args)
66
    {
67
        $arg = isset($args[0]) ? $args[0] : null;
68
69
        return $this->getVar($method, $arg);
70
    }
71
72
    /**
73
     *  @static function getInstance
74
     *
75
     *  @param null
76
     *
77
     * @return MoreFiles
78
     */
79
    public static function getInstance()
80
    {
81
        static $instance = false;
82
        if (!$instance) {
83
            $instance = new self();
84
        }
85
86
        return $instance;
87
    }
88
89
    /**
90
     * @public function getFormMoreFiles
91
     *
92
     * @param bool|mixed $action
93
     * @return \XoopsThemeForm
94
     */
95
    public function getFormMoreFiles($action = false)
96
    {
97
        $helper = Tdmcreate\Helper::getInstance();
98
        if (false === $action) {
99
            $action = $_SERVER['REQUEST_URI'];
100
        }
101
102
        $isNew = $this->isNew();
103
        $title = $isNew ? sprintf(_AM_TDMCREATE_MORE_FILES_NEW) : sprintf(_AM_TDMCREATE_MORE_FILES_EDIT);
104
105
        xoops_load('XoopsFormLoader');
106
107
        $form = new \XoopsThemeForm($title, 'morefilesform', $action, 'post', true);
108
        $form->setExtra('enctype="multipart/form-data"');
109
110
        $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

110
        $modules = $helper->getHandler('Modules')->/** @scrutinizer ignore-call */ getObjects(null);
Loading history...
111
        $modulesSelect = new \XoopsFormSelect(_AM_TDMCREATE_MORE_FILES_MODULES, 'file_mid', $this->getVar('file_mid'));
112
        $modulesSelect->addOption('', _AM_TDMCREATE_MORE_FILES_MODULE_SELECT);
113
        foreach ($modules as $mod) {
114
            //$modulesSelect->addOptionArray();
115
            $modulesSelect->addOption($mod->getVar('mod_id'), $mod->getVar('mod_name'));
116
        }
117
        $form->addElement($modulesSelect, true);
118
119
        $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

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