TablesHandler   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 123
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 123
rs 10
c 0
b 0
f 0
wmc 8

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getCountTables() 0 6 1
A __construct() 0 3 1
A create() 0 3 1
A get() 0 3 1
A getAllTables() 0 6 1
A getTablesCriteria() 0 8 1
A getAllTablesByModuleId() 0 7 1
A getInsertId() 0 3 1
1
<?php
2
3
namespace XoopsModules\Modulebuilder;
4
5
use XoopsModules\Modulebuilder;
6
7
/*
8
 You may not change or alter any portion of this comment or credits
9
 of supporting developers from this source code or any supporting source code
10
 which is considered copyrighted (c) material of the original comment or credit authors.
11
12
 This program is distributed in the hope that it will be useful,
13
 but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
 */
16
17
/**
18
 * modulebuilder module.
19
 *
20
 * @copyright       XOOPS Project (https://xoops.org)
21
 * @license         GNU GPL 2 (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
22
 *
23
 * @since           2.5.7
24
 *
25
 * @author          Txmod Xoops <[email protected]> - <https://xoops.org/>
26
 *
27
 */
28
29
/**
30
 * @Class TablesHandler
31
 * @extends \XoopsPersistableObjectHandler
32
 */
33
class TablesHandler extends \XoopsPersistableObjectHandler
34
{
35
    /**
36
     * @public function constructor class
37
     *
38
     * @param null|\XoopsDatabase|\XoopsMySQLDatabase $db
39
     */
40
    public function __construct(\XoopsDatabase $db)
41
    {
42
        parent::__construct($db, 'modulebuilder_tables', Tables::class, 'table_id', 'table_name');
43
    }
44
45
    /**
46
     * @param bool $isNew
47
     *
48
     * @return object
49
     */
50
    public function create($isNew = true)
51
    {
52
        return parent::create($isNew);
53
    }
54
55
    /**
56
     * retrieve a field.
57
     *
58
     * @param int  $i field id
59
     * @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...
60
     *
61
     * @return mixed reference to the <a href='psi_element://Fields'>Fields</a> object
62
     *               object
63
     */
64
    public function get($i = null, $fields = null)
65
    {
66
        return parent::get($i, $fields);
67
    }
68
69
    /**
70
     * get inserted id.
71
     *
72
     * @param null
73
     *
74
     * @return int reference to the {@link Tables} object
75
     */
76
    public function getInsertId()
77
    {
78
        return $this->db->getInsertId();
79
    }
80
81
    /**
82
     * Get Count Modules.
83
     *
84
     * @param int    $start
85
     * @param int    $limit
86
     * @param string $sort
87
     * @param string $order
88
     *
89
     * @return int
90
     */
91
    public function getCountTables($start = 0, $limit = 0, $sort = 'table_id ASC, table_name', $order = 'ASC')
92
    {
93
        $crCountTables = new \CriteriaCompo();
94
        $crCountTables = $this->getTablesCriteria($crCountTables, $start, $limit, $sort, $order);
95
96
        return $this->getCount($crCountTables);
97
    }
98
99
    /**
100
     * Get All Modules.
101
     *
102
     * @param int    $start
103
     * @param int    $limit
104
     * @param string $sort
105
     * @param string $order
106
     *
107
     * @return array
108
     */
109
    public function getAllTables($start = 0, $limit = 0, $sort = 'table_mid DESC, table_order ASC, table_id', $order = 'DESC')
110
    {
111
        $crAllTables = new \CriteriaCompo();
112
        $crAllTables = $this->getTablesCriteria($crAllTables, $start, $limit, $sort, $order);
113
114
        return $this->getAll($crAllTables);
115
    }
116
117
    /**
118
     * Get All Tables By Module Id.
119
     *
120
     * @param        $modId
121
     * @param int    $start
122
     * @param int    $limit
123
     * @param string $sort
124
     * @param string $order
125
     *
126
     * @return array
127
     */
128
    public function getAllTablesByModuleId($modId, $start = 0, $limit = 0, $sort = 'table_order ASC, table_id, table_name', $order = 'ASC')
129
    {
130
        $crAllTablesByModuleId = new \CriteriaCompo();
131
        $crAllTablesByModuleId->add(new \Criteria('table_mid', $modId));
132
        $crAllTablesByModuleId = $this->getTablesCriteria($crAllTablesByModuleId, $start, $limit, $sort, $order);
133
134
        return $this->getAll($crAllTablesByModuleId);
135
    }
136
137
    /**
138
     * Get Tables Criteria.
139
     *
140
     * @param $crTables
141
     * @param $start
142
     * @param $limit
143
     * @param $sort
144
     * @param $order
145
     *
146
     * @return mixed
147
     */
148
    private function getTablesCriteria($crTables, $start, $limit, $sort, $order)
149
    {
150
        $crTables->setStart($start);
151
        $crTables->setLimit($limit);
152
        $crTables->setSort($sort);
153
        $crTables->setOrder($order);
154
155
        return $crTables;
156
    }
157
}
158