SettingsHandler::getSettingsCriteria()   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 5
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
 * 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
 * @version         $Id: settings.php 13070 2015-05-19 12:24:20Z timgno $
26
 */
27
// include __DIR__ . '/autoload.php';
28
29
/**
30
 * Class SettingsHandler.
31
 */
32
class SettingsHandler extends \XoopsPersistableObjectHandler
33
{
34
    /**
35
     * @param null|\XoopsDatabase|\XoopsMySQLDatabase $db
36
     */
37
    public function __construct(\XoopsDatabase $db)
38
    {
39
        parent::__construct($db, 'tdmcreate_settings', Settings::class, 'set_id', 'set_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://Settings'>Settings</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 Tables} object
72
     */
73
    public function getInsertId()
74
    {
75
        return $this->db->getInsertId();
76
    }
77
78
    /**
79
     * Get Count Settings.
80
     *
81
     * @param int    $start
82
     * @param int    $limit
83
     * @param string $sort
84
     * @param string $order
85
     *
86
     * @return int
87
     */
88
    public function getCountSettings($start = 0, $limit = 0, $sort = 'set_id ASC, set_name', $order = 'ASC')
89
    {
90
        $crCountSettings = new \CriteriaCompo();
91
        $crCountSettings = $this->getSettingsCriteria($crCountSettings, $start, $limit, $sort, $order);
92
93
        return $this->getCount($crCountSettings);
94
    }
95
96
    /**
97
     * Get All Settings.
98
     *
99
     * @param int    $start
100
     * @param int    $limit
101
     * @param string $sort
102
     * @param string $order
103
     *
104
     * @return array
105
     */
106
    public function getAllSettings($start = 0, $limit = 0, $sort = 'set_id ASC, set_name', $order = 'ASC')
107
    {
108
        $crAllSettings = new \CriteriaCompo();
109
        $crAllSettings = $this->getSettingsCriteria($crAllSettings, $start, $limit, $sort, $order);
110
111
        return $this->getAll($crAllSettings);
112
    }
113
114
    /**
115
     * Get Settings Criteria.
116
     *
117
     * @param $crSettings
118
     * @param $start
119
     * @param $limit
120
     * @param $sort
121
     * @param $order
122
     *
123
     * @return mixed
124
     */
125
    private function getSettingsCriteria($crSettings, $start, $limit, $sort, $order)
126
    {
127
        $crSettings->setStart($start);
128
        $crSettings->setLimit($limit);
129
        $crSettings->setSort($sort);
130
        $crSettings->setOrder($order);
131
132
        return $crSettings;
133
    }
134
}
135