Passed
Push — master ( 69c050...5d34fd )
by Goffy
03:36
created

FieldsHandler::getCountFields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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