Completed
Push — master ( e9acbc...ae1831 )
by Gino
06:34 queued 02:43
created

TDMCreateMoreFilesHandler::insert()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
cc 2
eloc 4
c 3
b 1
f 0
nc 2
nop 2
dl 0
loc 8
rs 9.4285
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 34 and the first side effect is on line 25.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
/*
4
 You may not change or alter any portion of this comment or credits
5
 of supporting developers from this source code or any supporting source code
6
 which is considered copyrighted (c) material of the original comment or credit authors.
7
8
 This program is distributed in the hope that it will be useful,
9
 but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 */
12
13
/**
14
 * morefiles class.
15
 *
16
 * @copyright       The XOOPS Project http://sourceforge.net/projects/xoops/
17
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
18
 *
19
 * @since           2.5.7
20
 *
21
 * @author          Txmod Xoops <[email protected]> - <http://www.txmodxoops.org/>
22
 *
23
 * @version         $Id: morefiles.php 13080 2015-06-12 10:12:32Z timgno $
24
 */
25
include __DIR__.'/autoload.php';
26
/*
27
*  @Class TDMCreateMoreFiles
28
*  @extends XoopsObject
29
*/
30
31
/**
32
 * Class TDMCreateMoreFiles.
33
 */
34
class TDMCreateMoreFiles extends XoopsObject
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
Comprehensibility Best Practice introduced by
The type TDMCreateMoreFiles has been defined more than once; this definition is ignored, only the first definition in class/files/TDMCreateMoreFiles.php (L28-249) is considered.

This check looks for classes that have been defined more than once.

If you can, we would recommend to use standard object-oriented programming techniques. For example, to avoid multiple types, it might make sense to create a common interface, and then multiple, different implementations for that interface.

This also has the side-effect of providing you with better IDE auto-completion, static analysis and also better OPCode caching from PHP.

Loading history...
35
{
36
    /**
37
     * Settings.
38
     *
39
     * @var mixed
40
     */
41
    private $settings;
42
43
    /**
44
     *  @public function constructor class
45
     *
46
     *  @param null
47
     */
48
    public function __construct()
49
    {
50
        $this->initVar('file_id', XOBJ_DTYPE_INT);
0 ignored issues
show
Bug introduced by
The method initVar() does not seem to exist on object<TDMCreateMoreFiles>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
51
        $this->initVar('file_mid', XOBJ_DTYPE_INT);
0 ignored issues
show
Bug introduced by
The method initVar() does not seem to exist on object<TDMCreateMoreFiles>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
52
        $this->initVar('file_name', XOBJ_DTYPE_TXTBOX);
0 ignored issues
show
Bug introduced by
The method initVar() does not seem to exist on object<TDMCreateMoreFiles>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
53
        $this->initVar('file_extension', XOBJ_DTYPE_TXTBOX);
0 ignored issues
show
Bug introduced by
The method initVar() does not seem to exist on object<TDMCreateMoreFiles>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
54
        $this->initVar('file_infolder', XOBJ_DTYPE_TXTBOX);
0 ignored issues
show
Bug introduced by
The method initVar() does not seem to exist on object<TDMCreateMoreFiles>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
55
    }
56
57
    /**
58
     * @param string $method
59
     * @param array  $args
60
     *
61
     * @return mixed
62
     */
63
    public function __call($method, $args)
64
    {
65
        $arg = isset($args[0]) ? $args[0] : null;
66
67
        return $this->getVar($method, $arg);
0 ignored issues
show
Bug introduced by
The method getVar() does not seem to exist on object<TDMCreateMoreFiles>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
68
    }
69
70
    /**
71
     *  @static function getInstance
72
     *
73
     *  @param null
74
     *
75
     * @return TDMCreateMoreFiles
76
     */
77
    public static function getInstance()
78
    {
79
        static $instance = false;
80
        if (!$instance) {
81
            $instance = new self();
82
        }
83
84
        return $instance;
85
    }
86
87
    /**
88
     *  @public function getFormMoreFiles
89
     *
90
     *  @param mixed $action
91
     * @param bool $action
92
     *
93
     * @return XoopsThemeForm
94
     */
95
    public function getFormMoreFiles($action = false)
96
    {
97
        $tdmcreate = TDMCreateHelper::getInstance();
98
        if ($action === false) {
99
            $action = $_SERVER['REQUEST_URI'];
100
        }
101
        //
102
        $isNew = $this->isNew();
0 ignored issues
show
Bug introduced by
The method isNew() does not seem to exist on object<TDMCreateMoreFiles>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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 = $tdmcreate->getHandler('modules')->getObjects(null);
0 ignored issues
show
Bug introduced by
The method getObjects cannot be called on $tdmcreate->getHandler('modules') (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
111
        $modulesSelect = new XoopsFormSelect(_AM_TDMCREATE_MORE_FILES_MODULES, 'file_mid', $this->getVar('file_mid'));
0 ignored issues
show
Bug introduced by
The method getVar() does not seem to exist on object<TDMCreateMoreFiles>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
112
        $modulesSelect->addOption('', _AM_TDMCREATE_MORE_FILES_MODULE_SELECT);
113
        foreach ($modules as $mod) {
114
            //$modulesSelect->addOptionArray();
0 ignored issues
show
Unused Code Comprehensibility introduced by
84% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
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
The method getVar() does not seem to exist on object<TDMCreateMoreFiles>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

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'));
0 ignored issues
show
Bug introduced by
The method getVar() does not seem to exist on object<TDMCreateMoreFiles>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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'));
0 ignored issues
show
Bug introduced by
The method getVar() does not seem to exist on object<TDMCreateMoreFiles>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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
141
     * @param null $format
142
     * @param null $maxDepth
143
     *
144
     * @return array
145
     */
146
    public function getValuesMoreFiles($keys = null, $format = null, $maxDepth = null)
147
    {
148
        $tdmcreate = TDMCreateHelper::getInstance();
149
        $ret = $this->getValues($keys, $format, $maxDepth);
0 ignored issues
show
Bug introduced by
The method getValues() does not seem to exist on object<TDMCreateMoreFiles>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
150
        // Values
151
        $ret['id'] = $this->getVar('file_id');
0 ignored issues
show
Bug introduced by
The method getVar() does not seem to exist on object<TDMCreateMoreFiles>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
152
        $ret['mid'] = $tdmcreate->getHandler('modules')->get($this->getVar('file_mid'))->getVar('mod_name');
0 ignored issues
show
Bug introduced by
The method getVar() does not seem to exist on object<TDMCreateMoreFiles>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method get cannot be called on $tdmcreate->getHandler('modules') (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
153
        $ret['name'] = $this->getVar('file_name');
0 ignored issues
show
Bug introduced by
The method getVar() does not seem to exist on object<TDMCreateMoreFiles>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
154
        $ret['extension'] = $this->getVar('file_extension');
0 ignored issues
show
Bug introduced by
The method getVar() does not seem to exist on object<TDMCreateMoreFiles>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
155
        $ret['infolder'] = $this->getVar('file_infolder');
0 ignored issues
show
Bug introduced by
The method getVar() does not seem to exist on object<TDMCreateMoreFiles>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
156
157
        return $ret;
158
    }
159
}
160
161
/**
162
 *  @Class TDMCreateMoreFilesHandler
163
 *  @extends XoopsPersistableObjectHandler
164
 */
165
class TDMCreateMoreFilesHandler extends XoopsPersistableObjectHandler
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
166
{
167
    /**
168
     *  @public function constructor class
169
     *
170
     * @param null|object $db
171
     */
172
    public function __construct(&$db)
173
    {
174
        parent::__construct($db, 'tdmcreate_morefiles', 'tdmcreatemorefiles', 'file_id', 'file_name');
175
    }
176
177
    /**
178
     * @param bool $isNew
179
     *
180
     * @return object
181
     */
182
    public function create($isNew = true)
183
    {
184
        return parent::create($isNew);
185
    }
186
187
    /**
188
     * retrieve a field.
189
     *
190
     * @param int  $i      field id
191
     * @param null $fields
192
     *
193
     * @return mixed reference to the <a href='psi_element://TDMCreateFields'>TDMCreateFields</a> object
194
     *               object
195
     */
196
    public function get($i = null, $fields = null)
197
    {
198
        return parent::get($i, $fields);
199
    }
200
201
    /**
202
     * get inserted id.
203
     *
204
     * @param null
205
     *
206
     * @return int reference to the {@link TDMCreateTables} object
207
     */
208
    public function getInsertId()
209
    {
210
        return $this->db->getInsertId();
211
    }
212
213
    /**
214
     * Get Count MoreFiles.
215
     *
216
     * @param int    $start
217
     * @param int    $limit
218
     * @param string $sort
219
     * @param string $order
220
     *
221
     * @return int
222
     */
223
    public function getCountMoreFiles($start = 0, $limit = 0, $sort = 'file_id ASC, file_name', $order = 'ASC')
224
    {
225
        $crMoreFilesCount = new CriteriaCompo();
226
        $crMoreFilesCount = $this->getMoreFilesCriteria($crMoreFilesCount, $start, $limit, $sort, $order);
227
228
        return $this->getCount($crMoreFilesCount);
229
    }
230
231
    /**
232
     * Get All MoreFiles.
233
     *
234
     * @param int    $start
235
     * @param int    $limit
236
     * @param string $sort
237
     * @param string $order
238
     *
239
     * @return array
240
     */
241
    public function getAllMoreFiles($start = 0, $limit = 0, $sort = 'file_id ASC, file_name', $order = 'ASC')
242
    {
243
        $crMoreFilesAdd = new CriteriaCompo();
244
        $crMoreFilesAdd = $this->getMoreFilesCriteria($crMoreFilesAdd, $start, $limit, $sort, $order);
245
246
        return $this->getAll($crMoreFilesAdd);
247
    }
248
249
    /**
250
     * Get All MoreFiles By Module Id.
251
     *
252
     * @param        $modId
253
     * @param int    $start
254
     * @param int    $limit
255
     * @param string $sort
256
     * @param string $order
257
     *
258
     * @return array
259
     */
260
    public function getAllMoreFilesByModuleId($modId, $start = 0, $limit = 0, $sort = 'file_id ASC, file_name', $order = 'ASC')
261
    {
262
        $crMoreFilesByModuleId = new CriteriaCompo();
263
        $crMoreFilesByModuleId->add(new Criteria('file_mid', $modId));
264
        $crMoreFilesByModuleId = $this->getMoreFilesCriteria($crMoreFilesByModuleId, $start, $limit, $sort, $order);
265
266
        return $this->getAll($crMoreFilesByModuleId);
267
    }
268
269
    /**
270
     * Get MoreFiles Criteria.
271
     *
272
     * @param $crMoreFiles
273
     * @param $start
274
     * @param $limit
275
     * @param $sort
276
     * @param $order
277
     *
278
     * @return
279
     */
280
    private function getMoreFilesCriteria($crMoreFiles, $start, $limit, $sort, $order)
281
    {
282
        $crMoreFiles->setStart($start);
283
        $crMoreFiles->setLimit($limit);
284
        $crMoreFiles->setSort($sort);
285
        $crMoreFiles->setOrder($order);
286
287
        return $crMoreFiles;
288
    }
289
}
290