Passed
Pull Request — master (#81)
by Michael
03:24
created

Relgroupuser   A

Complexity

Total Complexity 18

Size/Duplication

Total Lines 168
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 18
eloc 55
dl 0
loc 168
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getGroupsModeration() 0 7 1
A getForm() 0 3 1
A getGroupsSubmit() 0 7 1
A __construct() 0 24 3
A getGroupsRead() 0 7 1
B getAllRelgroupusers() 0 47 9
A load() 0 10 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace XoopsModules\Yogurt;
6
7
/*
8
 You may not change or alter any portion of this comment or credits
9
 of supporting developers from this source code or any supporting source code
10
 which is considered copyrighted (c) material of the original comment or credit authors.
11
 
12
 This program is distributed in the hope that it will be useful,
13
 but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
*/
16
17
/**
18
 * @category        Module
19
 * @package         yogurt
20
 * @copyright       {@link https://xoops.org/ XOOPS Project}
21
 * @license         GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html)
22
 * @author          Bruno Barthez, Marcello Brandão aka  Suico, Mamba, LioMJ  <https://xoops.org>
23
 */
24
25
use Xmf\Module\Helper\Permission;
26
use XoopsDatabaseFactory;
27
use XoopsObject;
28
29
require_once XOOPS_ROOT_PATH . '/kernel/object.php';
30
31
/**
32
 * Relgroupuser class.
33
 * $this class is responsible for providing data access mechanisms to the data source
34
 * of XOOPS user class objects.
35
 */
36
class Relgroupuser extends \XoopsObject
37
{
38
    public $db;
39
40
    public $helper;
41
42
    public $permHelper;
43
44
    // constructor
45
46
    /**
47
     * Relgroupuser constructor.
48
     * @param null $id
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $id is correct as it would always require null to be passed?
Loading history...
49
     */
50
51
    public function __construct($id = null)
52
    {
53
        /** @var Helper $helper */
54
55
        $this->helper = Helper::getInstance();
56
57
        $this->permHelper = new Permission();
58
59
        $this->db = XoopsDatabaseFactory::getDatabaseConnection();
60
61
        $this->initVar('rel_id', \XOBJ_DTYPE_INT, null, false, 10);
62
63
        $this->initVar('rel_group_id', \XOBJ_DTYPE_INT, null, false, 10);
64
65
        $this->initVar('rel_user_uid', \XOBJ_DTYPE_INT, null, false, 10);
66
67
        if (!empty($id)) {
68
            if (\is_array($id)) {
69
                $this->assignVars($id);
70
            } else {
71
                $this->load((int)$id);
72
            }
73
        } else {
74
            $this->setNew();
75
        }
76
    }
77
78
    /**
79
     * @param $id
80
     */
81
82
    public function load($id)
83
    {
84
        $sql = 'SELECT * FROM ' . $this->db->prefix('yogurt_relgroupuser') . ' WHERE rel_id=' . $id;
85
86
        $myrow = $this->db->fetchArray($this->db->query($sql));
87
88
        $this->assignVars($myrow);
89
90
        if (!$myrow) {
91
            $this->setNew();
92
        }
93
    }
94
95
    /**
96
     * @param array  $criteria
97
     * @param bool   $asobject
98
     * @param string $sort
99
     * @param string $order
100
     * @param int    $limit
101
     * @param int    $start
102
     * @return array
103
     */
104
105
    public function getAllRelgroupusers(
106
        $criteria = [],
107
        $asobject = false,
108
        $sort = 'rel_id',
109
        $order = 'ASC',
110
        $limit = 0,
111
        $start = 0
112
    ) {
113
        $db = XoopsDatabaseFactory::getDatabaseConnection();
114
115
        $ret = [];
116
117
        $whereQuery = '';
118
119
        if (\is_array($criteria) && \count($criteria) > 0) {
120
            $whereQuery = ' WHERE';
121
122
            foreach ($criteria as $c) {
123
                $whereQuery .= " ${c} AND";
124
            }
125
126
            $whereQuery = mb_substr($whereQuery, 0, -4);
127
        } elseif (!\is_array($criteria) && $criteria) {
128
            $whereQuery = ' WHERE ' . $criteria;
129
        }
130
131
        if (!$asobject) {
132
            $sql = 'SELECT rel_id FROM ' . $db->prefix(
133
                    'yogurt_relgroupuser'
134
                ) . "${whereQuery} ORDER BY ${sort} ${order}";
135
136
            $result = $db->query($sql, $limit, $start);
137
138
            while (false !== ($myrow = $db->fetchArray($result))) {
139
                $ret[] = $myrow['yogurt_relgroupuser_id'];
140
            }
141
        } else {
142
            $sql = 'SELECT * FROM ' . $db->prefix('yogurt_relgroupuser') . "${whereQuery} ORDER BY ${sort} ${order}";
143
144
            $result = $db->query($sql, $limit, $start);
145
146
            while (false !== ($myrow = $db->fetchArray($result))) {
147
                $ret[] = new self($myrow);
148
            }
149
        }
150
151
        return $ret;
152
    }
153
154
    /**
155
     * Get form
156
     *
157
     * @return \XoopsModules\Yogurt\Form\RelgroupuserForm
158
     */
159
160
    public function getForm()
161
    {
162
        return new Form\RelgroupuserForm($this);
163
    }
164
165
    /**
166
     * @return array|null
167
     */
168
169
    public function getGroupsRead()
170
    {
171
        //$permHelper = new \Xmf\Module\Helper\Permission();
172
173
        return $this->permHelper->getGroupsForItem(
174
            'sbcolumns_read',
175
            $this->getVar('rel_id')
176
        );
177
    }
178
179
    /**
180
     * @return array|null
181
     */
182
183
    public function getGroupsSubmit()
184
    {
185
        //$permHelper = new \Xmf\Module\Helper\Permission();
186
187
        return $this->permHelper->getGroupsForItem(
188
            'sbcolumns_submit',
189
            $this->getVar('rel_id')
190
        );
191
    }
192
193
    /**
194
     * @return array|null
195
     */
196
197
    public function getGroupsModeration()
198
    {
199
        //$permHelper = new \Xmf\Module\Helper\Permission();
200
201
        return $this->permHelper->getGroupsForItem(
202
            'sbcolumns_moderation',
203
            $this->getVar('rel_id')
204
        );
205
    }
206
}
207