Passed
Pull Request — master (#81)
by Michael
02:31
created

Relgroupuser::getAllRelgroupusers()   B

Complexity

Conditions 9
Paths 12

Size

Total Lines 37
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 23
c 0
b 0
f 0
dl 0
loc 37
rs 8.0555
cc 9
nc 12
nop 6
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
 * Module: Yogurt
18
 *
19
 * @category        Module
20
 * @package         yogurt
21
 * @author          Marcello Brandão aka  Suico, Mamba, LioMJ  <https://xoops.org>
22
 * @copyright       {@link https://xoops.org/ XOOPS Project}
23
 * @license         GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html)
24
 */
25
26
27
// Relgroupuser.php,v 1
28
//  ---------------------------------------------------------------- //
29
// Author: Bruno Barthez                                               //
30
// ----------------------------------------------------------------- //
31
32
use Xmf\Module\Helper\Permission;
33
use XoopsDatabaseFactory;
34
use XoopsObject;
35
36
require_once XOOPS_ROOT_PATH . '/kernel/object.php';
37
38
/**
39
 * Relgroupuser class.
40
 * $this class is responsible for providing data access mechanisms to the data source
41
 * of XOOPS user class objects.
42
 */
43
class Relgroupuser extends XoopsObject
44
{
45
    public $db;
46
    public $helper;
47
    public $permHelper;
48
49
    // constructor
50
51
    /**
52
     * Relgroupuser constructor.
53
     * @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...
54
     */
55
    public function __construct($id = null)
56
    {
57
        /** @var Helper $helper */
58
        $this->helper     = Helper::getInstance();
59
        $this->permHelper = new Permission();
60
        $this->db         = XoopsDatabaseFactory::getDatabaseConnection();
61
        $this->initVar('rel_id', \XOBJ_DTYPE_INT, null, false, 10);
62
        $this->initVar('rel_group_id', \XOBJ_DTYPE_INT, null, false, 10);
63
        $this->initVar('rel_user_uid', \XOBJ_DTYPE_INT, null, false, 10);
64
        if (!empty($id)) {
65
            if (\is_array($id)) {
66
                $this->assignVars($id);
67
            } else {
68
                $this->load((int)$id);
69
            }
70
        } else {
71
            $this->setNew();
72
        }
73
    }
74
75
    /**
76
     * @param $id
77
     */
78
    public function load($id)
79
    {
80
        $sql   = 'SELECT * FROM ' . $this->db->prefix('yogurt_relgroupuser') . ' WHERE rel_id=' . $id;
81
        $myrow = $this->db->fetchArray($this->db->query($sql));
82
        $this->assignVars($myrow);
83
        if (!$myrow) {
84
            $this->setNew();
85
        }
86
    }
87
88
    /**
89
     * @param array  $criteria
90
     * @param bool   $asobject
91
     * @param string $sort
92
     * @param string $order
93
     * @param int    $limit
94
     * @param int    $start
95
     * @return array
96
     */
97
    public function getAllRelgroupusers(
98
        $criteria = [],
99
        $asobject = false,
100
        $sort = 'rel_id',
101
        $order = 'ASC',
102
        $limit = 0,
103
        $start = 0
104
    ) {
105
        $db          = XoopsDatabaseFactory::getDatabaseConnection();
106
        $ret         = [];
107
        $whereQuery = '';
108
        if (\is_array($criteria) && \count($criteria) > 0) {
109
            $whereQuery = ' WHERE';
110
            foreach ($criteria as $c) {
111
                $whereQuery .= " ${c} AND";
112
            }
113
            $whereQuery = mb_substr($whereQuery, 0, -4);
114
        } elseif (!\is_array($criteria) && $criteria) {
115
            $whereQuery = ' WHERE ' . $criteria;
116
        }
117
        if (!$asobject) {
118
            $sql    = 'SELECT rel_id FROM ' . $db->prefix(
119
                'yogurt_relgroupuser'
120
            ) . "${whereQuery} ORDER BY ${sort} ${order}";
121
            $result = $db->query($sql, $limit, $start);
122
            while (false !== ($myrow = $db->fetchArray($result))) {
123
                $ret[] = $myrow['yogurt_relgroupuser_id'];
124
            }
125
        } else {
126
            $sql    = 'SELECT * FROM ' . $db->prefix('yogurt_relgroupuser') . "${whereQuery} ORDER BY ${sort} ${order}";
127
            $result = $db->query($sql, $limit, $start);
128
            while (false !== ($myrow = $db->fetchArray($result))) {
129
                $ret[] = new self($myrow);
130
            }
131
        }
132
133
        return $ret;
134
    }
135
136
    /**
137
     * Get form
138
     *
139
     * @return \XoopsModules\Yogurt\Form\RelgroupuserForm
140
     */
141
    public function getForm()
142
    {
143
        return new Form\RelgroupuserForm($this);
144
    }
145
146
    /**
147
     * @return array|null
148
     */
149
    public function getGroupsRead()
150
    {
151
        //$permHelper = new \Xmf\Module\Helper\Permission();
152
        return $this->permHelper->getGroupsForItem(
153
            'sbcolumns_read',
154
            $this->getVar('rel_id')
155
        );
156
    }
157
158
    /**
159
     * @return array|null
160
     */
161
    public function getGroupsSubmit()
162
    {
163
        //$permHelper = new \Xmf\Module\Helper\Permission();
164
        return $this->permHelper->getGroupsForItem(
165
            'sbcolumns_submit',
166
            $this->getVar('rel_id')
167
        );
168
    }
169
170
    /**
171
     * @return array|null
172
     */
173
    public function getGroupsModeration()
174
    {
175
        //$permHelper = new \Xmf\Module\Helper\Permission();
176
        return $this->permHelper->getGroupsForItem(
177
            'sbcolumns_moderation',
178
            $this->getVar('rel_id')
179
        );
180
    }
181
}
182