TablesHandler::getTablesCriteria()   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 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
 * tdmcreate module.
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
 * @version         $Id: 1.91 tables.php 11297 2013-03-24 10:58:10Z timgno $
26
 */
27
28
// include __DIR__ . '/autoload.php';
29
30
/**
31
 *  @Class TablesHandler
32
 *  @extends \XoopsPersistableObjectHandler
33
 */
34
class TablesHandler extends \XoopsPersistableObjectHandler
35
{
36
    /**
37
     *  @public function constructor class
38
     *
39
     * @param null|\XoopsDatabase|\XoopsMySQLDatabase $db
40
     */
41
    public function __construct(\XoopsDatabase $db)
42
    {
43
        parent::__construct($db, 'tdmcreate_tables', Tables::class, 'table_id', 'table_name');
44
    }
45
46
    /**
47
     * @param bool $isNew
48
     *
49
     * @return object
50
     */
51
    public function create($isNew = true)
52
    {
53
        return parent::create($isNew);
54
    }
55
56
    /**
57
     * retrieve a field.
58
     *
59
     * @param int  $i      field id
60
     * @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...
61
     *
62
     * @return mixed reference to the <a href='psi_element://Fields'>Fields</a> object
63
     *               object
64
     */
65
    public function get($i = null, $fields = null)
66
    {
67
        return parent::get($i, $fields);
68
    }
69
70
    /**
71
     * get inserted id.
72
     *
73
     * @param null
74
     *
75
     * @return int reference to the {@link Tables} object
76
     */
77
    public function getInsertId()
78
    {
79
        return $this->db->getInsertId();
80
    }
81
82
    /**
83
     * Get Count Modules.
84
     *
85
     * @param int    $start
86
     * @param int    $limit
87
     * @param string $sort
88
     * @param string $order
89
     *
90
     * @return int
91
     */
92
    public function getCountTables($start = 0, $limit = 0, $sort = 'table_id ASC, table_name', $order = 'ASC')
93
    {
94
        $crCountTables = new \CriteriaCompo();
95
        $crCountTables = $this->getTablesCriteria($crCountTables, $start, $limit, $sort, $order);
96
97
        return $this->getCount($crCountTables);
98
    }
99
100
    /**
101
     * Get All Modules.
102
     *
103
     * @param int    $start
104
     * @param int    $limit
105
     * @param string $sort
106
     * @param string $order
107
     *
108
     * @return array
109
     */
110
    public function getAllTables($start = 0, $limit = 0, $sort = 'table_id ASC, table_name', $order = 'ASC')
111
    {
112
        $crAllTables = new \CriteriaCompo();
113
        $crAllTables = $this->getTablesCriteria($crAllTables, $start, $limit, $sort, $order);
114
115
        return $this->getAll($crAllTables);
116
    }
117
118
    /**
119
     * Get All Tables By Module Id.
120
     *
121
     * @param        $modId
122
     * @param int    $start
123
     * @param int    $limit
124
     * @param string $sort
125
     * @param string $order
126
     *
127
     * @return array
128
     */
129
    public function getAllTablesByModuleId($modId, $start = 0, $limit = 0, $sort = 'table_order ASC, table_id, table_name', $order = 'ASC')
130
    {
131
        $crAllTablesByModuleId = new \CriteriaCompo();
132
        $crAllTablesByModuleId->add(new \Criteria('table_mid', $modId));
133
        $crAllTablesByModuleId = $this->getTablesCriteria($crAllTablesByModuleId, $start, $limit, $sort, $order);
134
135
        return $this->getAll($crAllTablesByModuleId);
136
    }
137
138
    /**
139
     * Get Tables Criteria.
140
     *
141
     * @param $crTables
142
     * @param $start
143
     * @param $limit
144
     * @param $sort
145
     * @param $order
146
     *
147
     * @return mixed
148
     */
149
    private function getTablesCriteria($crTables, $start, $limit, $sort, $order)
150
    {
151
        $crTables->setStart($start);
152
        $crTables->setLimit($limit);
153
        $crTables->setSort($sort);
154
        $crTables->setOrder($order);
155
156
        return $crTables;
157
    }
158
}
159