Completed
Push — master ( 4e5fd8...358131 )
by Gino
08:01 queued 03:42
created

TDMCreateFieldElements::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 8
rs 9.4285
cc 1
eloc 6
nc 1
nop 0
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 24.

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
 * tdmcreate module.
14
 *
15
 * @copyright       The XOOPS Project http://sourceforge.net/projects/xoops/
16
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
17
 *
18
 * @since           2.5.5
19
 *
20
 * @author          Txmod Xoops <[email protected]>
21
 *
22
 * @version         $Id: 1.91 fieldelements.php 11297 2014-03-24 09:11:10Z timgno $
23
 */
24
defined('XOOPS_ROOT_PATH') || die('Restricted access');
25
26
/*
27
*  @Class TDMCreateFieldElements
28
*  @extends XoopsObject
29
*/
30
31
/**
32
 * Class TDMCreateFieldElements.
33
 */
34
class TDMCreateFieldElements 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...
35
{
36
    /*
37
    *  @public function constructor class
38
    *  @param null
39
    */
40
    /**
41
     *
42
     */
43
    public function __construct()
44
    {
45
        $this->initVar('fieldelement_id', XOBJ_DTYPE_INT);
46
        $this->initVar('fieldelement_mid', XOBJ_DTYPE_INT);
47
        $this->initVar('fieldelement_tid', XOBJ_DTYPE_INT);
48
        $this->initVar('fieldelement_name', XOBJ_DTYPE_TXTBOX);
49
        $this->initVar('fieldelement_value', XOBJ_DTYPE_TXTBOX);
50
    }
51
52
    /**
53
     * @param string $method
54
     * @param array  $args
55
     *
56
     * @return mixed
57
     */
58
    public function __call($method, $args)
59
    {
60
        $arg = isset($args[0]) ? $args[0] : null;
61
62
        return $this->getVar($method, $arg);
63
    }
64
65
    /*
66
    *  @static function &getInstance
67
    *  @param null
68
    */
69
    /**
70
     * @return TDMCreateFieldElements
71
     */
72
    public static function &getInstance()
73
    {
74
        static $instance = false;
75
        if (!$instance) {
76
            $instance = new self();
77
        }
78
79
        return $instance;
80
    }
81
82
    /**
83
     * Get Values.
84
     */
85
    public function getValuesFieldElements($keys = null, $format = null, $maxDepth = null)
86
    {
87
        $ret = $this->getValues($keys, $format, $maxDepth);
88
        // Values
89
        $ret['id'] = $this->getVar('fieldelement_id');
90
        $ret['mid'] = $this->getVar('fieldelement_mid');
91
        $ret['tid'] = $this->getVar('fieldelement_tid');
92
        $ret['name'] = $this->getVar('fieldelement_name');
93
        $ret['value'] = $this->getVar('fieldelement_value');
94
95
        return $ret;
96
    }
97
}
98
99
/*
100
*  @Class TDMCreateFieldElementsHandler
101
*  @extends XoopsPersistableObjectHandler
102
*/
103
104
/**
105
 * Class TDMCreateFieldElementsHandler.
106
 */
107
class TDMCreateFieldElementsHandler 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...
108
{
109
    /*
110
    *  @public function constructor class
111
    *  @param mixed $db
112
    */
113
    /**
114
     * @param null|object $db
115
     */
116
    public function __construct(&$db)
117
    {
118
        parent::__construct($db, 'tdmcreate_fieldelements', 'tdmcreatefieldelements', 'fieldelement_id', 'fieldelement_name');
119
    }
120
121
    /**
122
     * Get Count Fields.
123
     */
124
    public function getCountFieldElements($start = 0, $limit = 0, $sort = 'fieldelement_id ASC, fieldelement_name', $order = 'ASC')
125
    {
126
        $criteriaCountFieldElements = new CriteriaCompo();
127
        $criteriaCountFieldElements = $this->getFieldElementsCriteria($criteriaCountFieldElements, $start, $limit, $sort, $order);
128
129
        return parent::getCount($criteriaCountFieldElements);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getCount() instead of getCountFieldElements()). Are you sure this is correct? If so, you might want to change this to $this->getCount().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
130
    }
131
132
    /**
133
     * Get Objects Fields.
134
     */
135
    public function getObjectsFieldElements($start = 0, $limit = 0, $sort = 'fieldelement_id ASC, fieldelement_name', $order = 'ASC')
136
    {
137
        $criteriaObjectsFieldElements = new CriteriaCompo();
138
        $criteriaObjectsFieldElements = $this->getFieldElementsCriteria($criteriaObjectsFieldElements, $start, $limit, $sort, $order);
139
140
        return $this->getObjects($criteriaObjectsFieldElements);
141
    }
142
143
    /**
144
     * Get All Fields.
145
     */
146
    public function getAllFieldElements($start = 0, $limit = 0, $sort = 'fieldelement_id ASC, fieldelement_name', $order = 'ASC')
147
    {
148
        $criteriaAllFieldElements = new CriteriaCompo();
149
        $criteriaAllFieldElements = $this->getFieldElementsCriteria($criteriaAllFieldElements, $start, $limit, $sort, $order);
150
151
        return $this->getAll($criteriaAllFieldElements);
152
    }
153
154
    /**
155
     * Get All Fields By Module & Table Id.
156
     */
157 View Code Duplication
    public function getAllFieldElementsByModuleAndTableId($modId, $tabId, $start = 0, $limit = 0, $sort = 'fieldelement_id ASC, fieldelement_name', $order = 'ASC')
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
158
    {
159
        $criteriaAllFieldElementsByModule = new CriteriaCompo();
160
        $criteriaAllFieldElementsByModule->add(new Criteria('fieldelement_mid', $modId));
161
        $criteriaAllFieldElementsByModule->add(new Criteria('fieldelement_tid', $tabId));
162
        $criteriaAllFieldElementsByModule = $this->getFieldElementsCriteria($criteriaAllFieldElementsByModule, $start, $limit, $sort, $order);
163
164
        return $this->getAll($criteriaAllFieldElementsByModule);
165
    }
166
167
    /**
168
     * Get FieldElements Criteria.
169
     */
170
    private function getFieldElementsCriteria($criteriaFieldElements, $start, $limit, $sort, $order)
171
    {
172
        $criteriaFieldElements->setStart($start);
173
        $criteriaFieldElements->setLimit($limit);
174
        $criteriaFieldElements->setSort($sort);
175
        $criteriaFieldElements->setOrder($order);
176
177
        return $criteriaFieldElements;
178
    }
179
}
180