Test Setup Failed
Push — master ( c69ce6...5664e3 )
by Goffy
20:10
created

SettingsHandler::getAllSettings()   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
 * settings class.
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          TDM TEAM DEV MODULE
24
 *
25
 */
26
// include __DIR__ . '/autoload.php';
27
28
/**
29
 * Class SettingsHandler.
30
 */
31
class SettingsHandler extends \XoopsPersistableObjectHandler
32
{
33
    /**
34
     * @param null|\XoopsDatabase|\XoopsMySQLDatabase $db
35
     */
36
    public function __construct(\XoopsDatabase $db)
37
    {
38
        parent::__construct($db, 'modulebuilder_settings', Settings::class, 'set_id', 'set_name');
39
    }
40
41
    /**
42
     * @param bool $isNew
43
     *
44
     * @return \XoopsObject
45
     */
46
    public function create($isNew = true)
47
    {
48
        return parent::create($isNew);
49
    }
50
51
    /**
52
     * retrieve a field.
53
     *
54
     * @param int  $i field id
55
     * @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...
56
     *
57
     * @return mixed reference to the <a href='psi_element://Settings'>Settings</a> object
58
     *               object
59
     */
60
    public function get($i = null, $fields = null)
61
    {
62
        return parent::get($i, $fields);
63
    }
64
65
    /**
66
     * get inserted id.
67
     *
68
     * @param null
69
     *
70
     * @return int reference to the {@link Tables} object
71
     */
72
    public function getInsertId()
73
    {
74
        return $this->db->getInsertId();
75
    }
76
77
    /**
78
     * Get Count Settings.
79
     *
80
     * @param int    $start
81
     * @param int    $limit
82
     * @param string $sort
83
     * @param string $order
84
     *
85
     * @return int
86
     */
87
    public function getCountSettings($start = 0, $limit = 0, $sort = 'set_id ASC, set_name', $order = 'ASC')
88
    {
89
        $crCountSettings = new \CriteriaCompo();
90
        $crCountSettings = $this->getSettingsCriteria($crCountSettings, $start, $limit, $sort, $order);
91
92
        return $this->getCount($crCountSettings);
93
    }
94
95
    /**
96
     * Get All Settings.
97
     *
98
     * @param int    $start
99
     * @param int    $limit
100
     * @param string $sort
101
     * @param string $order
102
     *
103
     * @return array
104
     */
105
    public function getAllSettings($start = 0, $limit = 0, $sort = 'set_id ASC, set_name', $order = 'ASC')
106
    {
107
        $crAllSettings = new \CriteriaCompo();
108
        $crAllSettings = $this->getSettingsCriteria($crAllSettings, $start, $limit, $sort, $order);
109
110
        return $this->getAll($crAllSettings);
111
    }
112
113
    /**
114
     * Get All Settings.
115
     *
116
     * @param int    $start
117
     * @param int    $limit
118
     * @param string $sort
119
     * @param string $order
120
     *
121
     * @return array
122
     */
123
    public function getActiveSetting()
124
    {
125
        $crActiveSetting = new \CriteriaCompo();
126
        $crActiveSetting->add(new \Criteria('set_type', '1'));
127
128
        return $this->getAll($crActiveSetting);
129
    }
130
131
132
    /**
133
     * Get Settings Criteria.
134
     *
135
     * @param $crSettings
136
     * @param $start
137
     * @param $limit
138
     * @param $sort
139
     * @param $order
140
     *
141
     * @return mixed
142
     */
143
    private function getSettingsCriteria($crSettings, $start, $limit, $sort, $order)
144
    {
145
        $crSettings->setStart($start);
146
        $crSettings->setLimit($limit);
147
        $crSettings->setSort($sort);
148
        $crSettings->setOrder($order);
149
150
        return $crSettings;
151
    }
152
}
153