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
|
|
|
// Friendrequest.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
|
|
|
* Friendrequest class. |
40
|
|
|
* $this class is responsible for providing data access mechanisms to the data source |
41
|
|
|
* of XOOPS user class objects. |
42
|
|
|
*/ |
43
|
|
|
class Friendrequest extends XoopsObject |
44
|
|
|
{ |
45
|
|
|
public $db; |
46
|
|
|
public $helper; |
47
|
|
|
public $permHelper; |
48
|
|
|
|
49
|
|
|
// constructor |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Friendrequest constructor. |
53
|
|
|
* @param null $id |
|
|
|
|
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('friendreq_id', \XOBJ_DTYPE_INT, null, false, 10); |
62
|
|
|
$this->initVar('friendrequester_uid', \XOBJ_DTYPE_INT, null, false, 10); |
63
|
|
|
$this->initVar('friendrequestto_uid', \XOBJ_DTYPE_INT, null, false, 10); |
64
|
|
|
$this->initVar('date_created', \XOBJ_DTYPE_INT, 0, false); |
65
|
|
|
if (!empty($id)) { |
66
|
|
|
if (\is_array($id)) { |
67
|
|
|
$this->assignVars($id); |
68
|
|
|
} else { |
69
|
|
|
$this->load((int)$id); |
70
|
|
|
} |
71
|
|
|
} else { |
72
|
|
|
$this->setNew(); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @param $id |
78
|
|
|
*/ |
79
|
|
|
public function load($id) |
80
|
|
|
{ |
81
|
|
|
$sql = 'SELECT * FROM ' . $this->db->prefix('yogurt_friendrequests') . ' WHERE friendreq_id=' . $id; |
82
|
|
|
$myrow = $this->db->fetchArray($this->db->query($sql)); |
83
|
|
|
$this->assignVars($myrow); |
84
|
|
|
if (!$myrow) { |
85
|
|
|
$this->setNew(); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @param array $criteria |
91
|
|
|
* @param bool $asobject |
92
|
|
|
* @param string $sort |
93
|
|
|
* @param string $order |
94
|
|
|
* @param int $limit |
95
|
|
|
* @param int $start |
96
|
|
|
* @return array |
97
|
|
|
*/ |
98
|
|
|
public function getAllFriendrequests( |
99
|
|
|
$criteria = [], |
100
|
|
|
$asobject = false, |
101
|
|
|
$sort = 'friendreq_id', |
102
|
|
|
$order = 'ASC', |
103
|
|
|
$limit = 0, |
104
|
|
|
$start = 0 |
105
|
|
|
) { |
106
|
|
|
$db = XoopsDatabaseFactory::getDatabaseConnection(); |
107
|
|
|
$ret = []; |
108
|
|
|
$whereQuery = ''; |
109
|
|
|
if (\is_array($criteria) && \count($criteria) > 0) { |
110
|
|
|
$whereQuery = ' WHERE'; |
111
|
|
|
foreach ($criteria as $c) { |
112
|
|
|
$whereQuery .= " ${c} AND"; |
113
|
|
|
} |
114
|
|
|
$whereQuery = mb_substr($whereQuery, 0, -4); |
115
|
|
|
} elseif (!\is_array($criteria) && $criteria) { |
116
|
|
|
$whereQuery = ' WHERE ' . $criteria; |
117
|
|
|
} |
118
|
|
|
if (!$asobject) { |
119
|
|
|
$sql = 'SELECT friendreq_id FROM ' . $db->prefix( |
120
|
|
|
'yogurt_friendrequests' |
121
|
|
|
) . "${whereQuery} ORDER BY ${sort} ${order}"; |
122
|
|
|
$result = $db->query($sql, $limit, $start); |
123
|
|
|
while (false !== ($myrow = $db->fetchArray($result))) { |
124
|
|
|
$ret[] = $myrow['yogurt_friendrequest_id']; |
125
|
|
|
} |
126
|
|
|
} else { |
127
|
|
|
$sql = 'SELECT * FROM ' . $db->prefix( |
128
|
|
|
'yogurt_friendrequests' |
129
|
|
|
) . "${whereQuery} ORDER BY ${sort} ${order}"; |
130
|
|
|
$result = $db->query($sql, $limit, $start); |
131
|
|
|
while (false !== ($myrow = $db->fetchArray($result))) { |
132
|
|
|
$ret[] = new self($myrow); |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
return $ret; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Get form |
141
|
|
|
* |
142
|
|
|
* @return \XoopsModules\Yogurt\Form\FriendrequestForm |
143
|
|
|
*/ |
144
|
|
|
public function getForm() |
145
|
|
|
{ |
146
|
|
|
return new Form\FriendrequestForm($this); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @return array|null |
151
|
|
|
*/ |
152
|
|
|
public function getGroupsRead() |
153
|
|
|
{ |
154
|
|
|
//$permHelper = new \Xmf\Module\Helper\Permission(); |
155
|
|
|
return $this->permHelper->getGroupsForItem( |
156
|
|
|
'sbcolumns_read', |
157
|
|
|
$this->getVar('friendreq_id') |
158
|
|
|
); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* @return array|null |
163
|
|
|
*/ |
164
|
|
|
public function getGroupsSubmit() |
165
|
|
|
{ |
166
|
|
|
//$permHelper = new \Xmf\Module\Helper\Permission(); |
167
|
|
|
return $this->permHelper->getGroupsForItem( |
168
|
|
|
'sbcolumns_submit', |
169
|
|
|
$this->getVar('friendreq_id') |
170
|
|
|
); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* @return array|null |
175
|
|
|
*/ |
176
|
|
|
public function getGroupsModeration() |
177
|
|
|
{ |
178
|
|
|
//$permHelper = new \Xmf\Module\Helper\Permission(); |
179
|
|
|
return $this->permHelper->getGroupsForItem( |
180
|
|
|
'sbcolumns_moderation', |
181
|
|
|
$this->getVar('friendreq_id') |
182
|
|
|
); |
183
|
|
|
} |
184
|
|
|
} |
185
|
|
|
|