AddFiles::getInstance()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 8
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       The XOOPS Project http:sourceforge.net/projects/xoops/
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
/**
30
 * Class MoreFiles.
31
 */
32
class AddFiles extends \XoopsObject
33
{
34
    /**
35
     * Tdmcreate.
36
     *
37
     * @var mixed
38
     */
39
    private $helper;
40
41
    /**
42
     * Settings.
43
     *
44
     * @var mixed
45
     */
46
    private $settings;
0 ignored issues
show
introduced by
The private property $settings is not used, and could be removed.
Loading history...
47
48
    /**
49
    *  @public function constructor class
50
    *  @param null
51
    */
52
53
    public function __construct()
54
    {
55
        $this->helper = Tdmcreate\Helper::getInstance();
56
57
        $this->initVar('file_id', XOBJ_DTYPE_INT);
58
        $this->initVar('file_mid', XOBJ_DTYPE_INT);
59
        $this->initVar('file_name', XOBJ_DTYPE_TXTBOX);
60
        $this->initVar('file_extension', XOBJ_DTYPE_TXTBOX);
61
        $this->initVar('file_infolder', XOBJ_DTYPE_TXTBOX);
62
    }
63
64
    /**
65
     * @param string $method
66
     * @param array  $args
67
     *
68
     * @return mixed
69
     */
70
    public function __call($method, $args)
71
    {
72
        $arg = isset($args[0]) ? $args[0] : null;
73
74
        return $this->getVar($method, $arg);
75
    }
76
77
    /**
78
    *  @static function getInstance
79
    *  @param null
80
     * @return AddFiles
81
     */
82
    public static function getInstance()
83
    {
84
        static $instance = false;
85
        if (!$instance) {
86
            $instance = new self();
87
        }
88
89
        return $instance;
90
    }
91
92
    /**
93
    *  @public function getFormMoreFiles
94
    *  @param mixed $action
95
     *
96
     * @return \XoopsThemeForm
97
     */
98
    public function getFormAddFiles($action = false)
99
    {
100
        if (false === $action) {
101
            $action = $_SERVER['REQUEST_URI'];
102
        }
103
104
        $isNew = $this->isNew();
105
        $title = $isNew ? sprintf(_AM_TDMCREATE_ADDFILES_NEW) : sprintf(_AM_TDMCREATE_ADDFILES_EDIT);
0 ignored issues
show
Bug introduced by
The constant XoopsModules\Tdmcreate\_AM_TDMCREATE_ADDFILES_EDIT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The constant XoopsModules\Tdmcreate\_AM_TDMCREATE_ADDFILES_NEW was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
106
107
        xoops_load('XoopsFormLoader');
108
109
        $form = new \XoopsThemeForm($title, 'addfilesform', $action, 'post', true);
110
        $form->setExtra('enctype="multipart/form-data"');
111
112
        $modules = $this->helper->getHandler('modules')->getObjects(null);
113
        $modulesSelect = new \XoopsFormSelect(_AM_TDMCREATE_ADDFILES_MODULES, 'file_mid', $this->getVar('file_mid'));
0 ignored issues
show
Bug introduced by
The constant XoopsModules\Tdmcreate\_...CREATE_ADDFILES_MODULES was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
114
        $modulesSelect->addOption('', _AM_TDMCREATE_ADDFILES_MODULE_SELECT);
0 ignored issues
show
Bug introduced by
The constant XoopsModules\Tdmcreate\_..._ADDFILES_MODULE_SELECT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
115
        foreach ($modules as $mod) {
116
            $modulesSelect->addOption($mod->getVar('mod_id'), $mod->getVar('mod_name'));
117
        }
118
        $form->addElement($modulesSelect, true);
119
120
        $modName = new \XoopsFormText(_AM_TDMCREATE_ADDFILES_NAME, 'file_name', 50, 255, $this->getVar('file_name'));
0 ignored issues
show
Bug introduced by
The constant XoopsModules\Tdmcreate\_AM_TDMCREATE_ADDFILES_NAME was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
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_ADDFILES_NAME, 'file_name', 50, 255, /** @scrutinizer ignore-type */ $this->getVar('file_name'));
Loading history...
121
        $modName->setDescription(_AM_TDMCREATE_ADDFILES_NAME_DESC);
0 ignored issues
show
Bug introduced by
The constant XoopsModules\Tdmcreate\_...EATE_ADDFILES_NAME_DESC was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
122
        $form->addElement($modName, true);
123
124
        $fileEstension = new \XoopsFormText(_AM_TDMCREATE_ADDFILES_EXTENSION, 'file_extension', 50, 255, $this->getVar('file_extension'));
0 ignored issues
show
Bug introduced by
The constant XoopsModules\Tdmcreate\_...EATE_ADDFILES_EXTENSION was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
125
        $fileEstension->setDescription(_AM_TDMCREATE_ADDFILES_EXTENSION_DESC);
0 ignored issues
show
Bug introduced by
The constant XoopsModules\Tdmcreate\_...ADDFILES_EXTENSION_DESC was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
126
        $form->addElement($fileEstension, true);
127
128
        $fileInfolder = new \XoopsFormText(_AM_TDMCREATE_ADDFILES_INFOLDER, 'file_infolder', 50, 255, $this->getVar('file_infolder'));
0 ignored issues
show
Bug introduced by
The constant XoopsModules\Tdmcreate\_...REATE_ADDFILES_INFOLDER was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
129
        $fileInfolder->setDescription(_AM_TDMCREATE_ADDFILES_INFOLDER_DESC);
0 ignored issues
show
Bug introduced by
The constant XoopsModules\Tdmcreate\_..._ADDFILES_INFOLDER_DESC was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
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 AddFiles Values.
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
     * @return array
144
     */
145
    public function getAddFilesValues($keys = null, $format = null, $maxDepth = null)
146
    {
147
        $ret = $this->getValues($keys, $format, $maxDepth);
148
        // Values
149
        $ret['id'] = $this->getVar('file_id');
150
        $ret['mid'] = $this->helper->getHandler('modules')->get($this->getVar('file_mid'))->getVar('mod_name');
151
        $ret['name'] = $this->getVar('file_name');
152
        $ret['extension'] = $this->getVar('file_extension');
153
        $ret['infolder'] = $this->getVar('file_infolder');
154
155
        return $ret;
156
    }
157
}
158
159