TablesHandler::getInsertId()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace XoopsModules\Tdmcreate;
4
5
use XoopsModules\Tdmcreate;
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
 * tdmcreate module.
19
 *
20
 * @copyright       XOOPS Project (https://xoops.org)
21
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
22
 *
23
 * @since           2.5.7
24
 *
25
 * @author          Txmod Xoops <[email protected]> - <http://www.txmodxoops.org/>
26
 *
27
 */
28
29
// include __DIR__ . '/autoload.php';
30
31
/**
32
 * @Class TablesHandler
33
 * @extends \XoopsPersistableObjectHandler
34
 */
35
class TablesHandler extends \XoopsPersistableObjectHandler
36
{
37
    /**
38
     * @public function constructor class
39
     *
40
     * @param null|\XoopsDatabase|\XoopsMySQLDatabase $db
41
     */
42
    public function __construct(\XoopsDatabase $db)
43
    {
44
        parent::__construct($db, 'tdmcreate_tables', Tables::class, 'table_id', 'table_name');
45
    }
46
47
    /**
48
     * @param bool $isNew
49
     *
50
     * @return object
51
     */
52
    public function create($isNew = true)
53
    {
54
        return parent::create($isNew);
55
    }
56
57
    /**
58
     * retrieve a field.
59
     *
60
     * @param int  $i field id
61
     * @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...
62
     *
63
     * @return mixed reference to the <a href='psi_element://Fields'>Fields</a> object
64
     *               object
65
     */
66
    public function get($i = null, $fields = null)
67
    {
68
        return parent::get($i, $fields);
69
    }
70
71
    /**
72
     * get inserted id.
73
     *
74
     * @param null
75
     *
76
     * @return int reference to the {@link Tables} object
77
     */
78
    public function getInsertId()
79
    {
80
        return $this->db->getInsertId();
81
    }
82
83
    /**
84
     * Get Count Modules.
85
     *
86
     * @param int    $start
87
     * @param int    $limit
88
     * @param string $sort
89
     * @param string $order
90
     *
91
     * @return int
92
     */
93
    public function getCountTables($start = 0, $limit = 0, $sort = 'table_id ASC, table_name', $order = 'ASC')
94
    {
95
        $crCountTables = new \CriteriaCompo();
96
        $crCountTables = $this->getTablesCriteria($crCountTables, $start, $limit, $sort, $order);
97
98
        return $this->getCount($crCountTables);
99
    }
100
101
    /**
102
     * Get All Modules.
103
     *
104
     * @param int    $start
105
     * @param int    $limit
106
     * @param string $sort
107
     * @param string $order
108
     *
109
     * @return array
110
     */
111
    public function getAllTables($start = 0, $limit = 0, $sort = 'table_id ASC, table_name', $order = 'ASC')
112
    {
113
        $crAllTables = new \CriteriaCompo();
114
        $crAllTables = $this->getTablesCriteria($crAllTables, $start, $limit, $sort, $order);
115
116
        return $this->getAll($crAllTables);
117
    }
118
119
    /**
120
     * Get All Tables By Module Id.
121
     *
122
     * @param        $modId
123
     * @param int    $start
124
     * @param int    $limit
125
     * @param string $sort
126
     * @param string $order
127
     *
128
     * @return array
129
     */
130
    public function getAllTablesByModuleId($modId, $start = 0, $limit = 0, $sort = 'table_order ASC, table_id, table_name', $order = 'ASC')
131
    {
132
        $crAllTablesByModuleId = new \CriteriaCompo();
133
        $crAllTablesByModuleId->add(new \Criteria('table_mid', $modId));
134
        $crAllTablesByModuleId = $this->getTablesCriteria($crAllTablesByModuleId, $start, $limit, $sort, $order);
135
136
        return $this->getAll($crAllTablesByModuleId);
137
    }
138
139
    /**
140
     * Get Tables Criteria.
141
     *
142
     * @param $crTables
143
     * @param $start
144
     * @param $limit
145
     * @param $sort
146
     * @param $order
147
     *
148
     * @return mixed
149
     */
150
    private function getTablesCriteria($crTables, $start, $limit, $sort, $order)
151
    {
152
        $crTables->setStart($start);
153
        $crTables->setLimit($limit);
154
        $crTables->setSort($sort);
155
        $crTables->setOrder($order);
156
157
        return $crTables;
158
    }
159
}
160