FieldsHandler::getAllFieldsByTableId()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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