FieldsHandler::getAllFieldsByModuleAndTableId()   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 6
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
 * tdmcreatereate 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 fields.php 12258 2014-01-02 09:33:29Z timgno $
26
 */
27
//include __DIR__.'/autoload.php';
28
29
30
/**
31
 * Class FieldsHandler.
32
 */
33
class FieldsHandler extends \XoopsPersistableObjectHandler
34
{
35
    /**
36
     * @public function constructor class
37
     *
38
     * @param mixed|\XoopsDatabase $db
39
     */
40
    public function __construct(\XoopsDatabase $db)
41
    {
42
        parent::__construct($db, 'tdmcreate_fields', Fields::class, 'field_id', 'field_name');
43
    }
44
45
    /**
46
     * @param bool $isNew
47
     *
48
     * @return \XoopsObject
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 Fields} object
75
     */
76
    public function getInsertId()
77
    {
78
        return $this->db->getInsertId();
79
    }
80
81
    /**
82
     * Get Count Fields.
83
     * @param int    $start
84
     * @param int    $limit
85
     * @param string $sort
86
     * @param string $order
87
     * @return int
88
     */
89
    public function getCountFields($start = 0, $limit = 0, $sort = 'field_id ASC, field_name', $order = 'ASC')
90
    {
91
        $crCountFields = new \CriteriaCompo();
92
        $crCountFields = $this->getFieldsCriteria($crCountFields, $start, $limit, $sort, $order);
93
94
        return $this->getCount($crCountFields);
95
    }
96
97
    /**
98
     * Get All Fields.
99
     * @param int    $start
100
     * @param int    $limit
101
     * @param string $sort
102
     * @param string $order
103
     * @return array
104
     */
105
    public function getAllFields($start = 0, $limit = 0, $sort = 'field_id ASC, field_name', $order = 'ASC')
106
    {
107
        $crAllFields = new \CriteriaCompo();
108
        $crAllFields = $this->getFieldsCriteria($crAllFields, $start, $limit, $sort, $order);
109
110
        return $this->getAll($crAllFields);
111
    }
112
113
    /**
114
     * Get All Fields By Module & Table Id.
115
     * @param        $modId
116
     * @param        $tabId
117
     * @param int    $start
118
     * @param int    $limit
119
     * @param string $sort
120
     * @param string $order
121
     * @return array
122
     */
123
    public function getAllFieldsByModuleAndTableId($modId, $tabId, $start = 0, $limit = 0, $sort = 'field_order ASC, field_id, field_name', $order = 'ASC')
124
    {
125
        $crAllFieldsByModule = new \CriteriaCompo();
126
        $crAllFieldsByModule->add(new \Criteria('field_mid', $modId));
127
        $crAllFieldsByModule->add(new \Criteria('field_tid', $tabId));
128
        $crAllFieldsByModule = $this->getFieldsCriteria($crAllFieldsByModule, $start, $limit, $sort, $order);
129
130
        return $this->getAll($crAllFieldsByModule);
131
    }
132
133
    /**
134
     * Get Fields Criteria.
135
     * @param $crFields
136
     * @param $start
137
     * @param $limit
138
     * @param $sort
139
     * @param $order
140
     * @return mixed
141
     */
142
    private function getFieldsCriteria($crFields, $start, $limit, $sort, $order)
143
    {
144
        $crFields->setStart($start);
145
        $crFields->setLimit($limit);
146
        $crFields->setSort($sort);
147
        $crFields->setOrder($order);
148
149
        return $crFields;
150
    }
151
}
152