SettingsHandler::getInsertId()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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