ModulesHandler::getModulesCriteria()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
nc 1
nop 5
dl 0
loc 8
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace 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
 * modules 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
 */
26
// include __DIR__ . '/autoload.php';
27
28
/**
29
 * @Class ModulesHandler
30
 * @extends \XoopsPersistableObjectHandler
31
 */
32
class ModulesHandler extends \XoopsPersistableObjectHandler
33
{
34
    /**
35
     * @public function constructor class
36
     *
37
     * @param null|\XoopsDatabase|\XoopsMySQLDatabase $db
38
     */
39
    public function __construct(\XoopsDatabase $db)
40
    {
41
        parent::__construct($db, 'tdmcreate_modules', Modules::class, 'mod_id', 'mod_name');
42
    }
43
44
    /**
45
     * @param bool $isNew
46
     *
47
     * @return \XoopsObject
48
     */
49
    public function create($isNew = true)
50
    {
51
        return parent::create($isNew);
52
    }
53
54
    /**
55
     * retrieve a field.
56
     *
57
     * @param int  $i field id
58
     * @param null $fields
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $fields is correct as it would always require null to be passed?
Loading history...
59
     *
60
     * @return mixed reference to the <a href='psi_element://Fields'>Fields</a> object
61
     *               object
62
     */
63
    public function get($i = null, $fields = null)
64
    {
65
        return parent::get($i, $fields);
66
    }
67
68
    /**
69
     * get inserted id.
70
     *
71
     * @param null
72
     *
73
     * @return int reference to the {@link Tables} object
74
     */
75
    public function getInsertId()
76
    {
77
        return $this->db->getInsertId();
78
    }
79
80
    /**
81
     * Get Count Modules.
82
     *
83
     * @param int    $start
84
     * @param int    $limit
85
     * @param string $sort
86
     * @param string $order
87
     *
88
     * @return int
89
     */
90
    public function getCountModules($start = 0, $limit = 0, $sort = 'mod_id ASC, mod_name', $order = 'ASC')
91
    {
92
        $crCountModules = new \CriteriaCompo();
93
        $crCountModules = $this->getModulesCriteria($crCountModules, $start, $limit, $sort, $order);
94
95
        return $this->getCount($crCountModules);
96
    }
97
98
    /**
99
     * Get All Modules.
100
     *
101
     * @param int    $start
102
     * @param int    $limit
103
     * @param string $sort
104
     * @param string $order
105
     *
106
     * @return array
107
     */
108
    public function getAllModules($start = 0, $limit = 0, $sort = 'mod_id ASC, mod_name', $order = 'ASC')
109
    {
110
        $crAllModules = new \CriteriaCompo();
111
        $crAllModules = $this->getModulesCriteria($crAllModules, $start, $limit, $sort, $order);
112
113
        return $this->getAll($crAllModules);
114
    }
115
116
    /**
117
     * Get Modules Criteria.
118
     *
119
     * @param $crModules
120
     * @param $start
121
     * @param $limit
122
     * @param $sort
123
     * @param $order
124
     *
125
     * @return mixed
126
     */
127
    private function getModulesCriteria($crModules, $start, $limit, $sort, $order)
128
    {
129
        $crModules->setStart($start);
130
        $crModules->setLimit($limit);
131
        $crModules->setSort($sort);
132
        $crModules->setOrder($order);
133
134
        return $crModules;
135
    }
136
}
137