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