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
|
|
|
* @category Module |
18
|
|
|
* @package yogurt |
19
|
|
|
* @copyright {@link https://xoops.org/ XOOPS Project} |
20
|
|
|
* @license GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html) |
21
|
|
|
* @author Bruno Barthez, Marcello Brandão aka Suico, Mamba, LioMJ <https://xoops.org> |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
use Xmf\Module\Helper\Permission; |
25
|
|
|
use XoopsDatabaseFactory; |
26
|
|
|
use XoopsObject; |
27
|
|
|
|
28
|
|
|
require_once XOOPS_ROOT_PATH . '/kernel/object.php'; |
29
|
|
|
/** |
30
|
|
|
* Includes of form objects and uploader |
31
|
|
|
*/ |
32
|
|
|
require_once XOOPS_ROOT_PATH . '/class/uploader.php'; |
33
|
|
|
require_once XOOPS_ROOT_PATH . '/kernel/object.php'; |
34
|
|
|
require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
35
|
|
|
require_once XOOPS_ROOT_PATH . '/kernel/object.php'; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Friendship class. |
39
|
|
|
* $this class is responsible for providing data access mechanisms to the data source |
40
|
|
|
* of XOOPS user class objects. |
41
|
|
|
*/ |
42
|
|
|
class Friendship extends XoopsObject |
43
|
|
|
{ |
44
|
|
|
public $db; |
45
|
|
|
|
46
|
|
|
public $helper; |
47
|
|
|
|
48
|
|
|
public $permHelper; |
49
|
|
|
|
50
|
|
|
// constructor |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Friendship constructor. |
54
|
|
|
* @param null $id |
|
|
|
|
55
|
|
|
*/ |
56
|
|
|
|
57
|
|
|
public function __construct($id = null) |
58
|
|
|
{ |
59
|
|
|
parent::__construct(); |
60
|
|
|
|
61
|
|
|
/** @var Helper $helper */ |
62
|
|
|
|
63
|
|
|
$this->helper = Helper::getInstance(); |
64
|
|
|
|
65
|
|
|
$this->permHelper = new Permission(); |
66
|
|
|
|
67
|
|
|
$this->db = XoopsDatabaseFactory::getDatabaseConnection(); |
68
|
|
|
|
69
|
|
|
$this->initVar('friendship_id', \XOBJ_DTYPE_INT, null, false, 10); |
70
|
|
|
|
71
|
|
|
$this->initVar('friend1_uid', \XOBJ_DTYPE_INT, null, false, 10); |
72
|
|
|
|
73
|
|
|
$this->initVar('friend2_uid', \XOBJ_DTYPE_INT, null, false, 10); |
74
|
|
|
|
75
|
|
|
$this->initVar('level', \XOBJ_DTYPE_INT, null, false, 10); |
76
|
|
|
|
77
|
|
|
$this->initVar('hot', \XOBJ_DTYPE_INT, null, false, 10); |
78
|
|
|
|
79
|
|
|
$this->initVar('trust', \XOBJ_DTYPE_INT, null, false, 10); |
80
|
|
|
|
81
|
|
|
$this->initVar('cool', \XOBJ_DTYPE_INT, null, false, 10); |
82
|
|
|
|
83
|
|
|
$this->initVar('fan', \XOBJ_DTYPE_INT, null, false, 10); |
84
|
|
|
|
85
|
|
|
$this->initVar('date_created', \XOBJ_DTYPE_INT, 0, false); |
86
|
|
|
|
87
|
|
|
$this->initVar('date_updated', \XOBJ_DTYPE_INT, 0, false); |
88
|
|
|
|
89
|
|
|
if (!empty($id)) { |
90
|
|
|
if (\is_array($id)) { |
91
|
|
|
$this->assignVars($id); |
92
|
|
|
} else { |
93
|
|
|
$this->load((int)$id); |
94
|
|
|
} |
95
|
|
|
} else { |
96
|
|
|
$this->setNew(); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @param $id |
102
|
|
|
*/ |
103
|
|
|
|
104
|
|
|
public function load($id) |
105
|
|
|
{ |
106
|
|
|
$sql = 'SELECT * FROM ' . $this->db->prefix('yogurt_friendships') . ' WHERE friendship_id=' . $id; |
107
|
|
|
|
108
|
|
|
$myrow = $this->db->fetchArray($this->db->query($sql)); |
109
|
|
|
|
110
|
|
|
$this->assignVars($myrow); |
111
|
|
|
|
112
|
|
|
if (!$myrow) { |
113
|
|
|
$this->setNew(); |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @param array $criteria |
119
|
|
|
* @param bool $asobject |
120
|
|
|
* @param string $sort |
121
|
|
|
* @param string $order |
122
|
|
|
* @param int $limit |
123
|
|
|
* @param int $start |
124
|
|
|
* @return array |
125
|
|
|
*/ |
126
|
|
|
|
127
|
|
|
public function getAllFriendships( |
128
|
|
|
$criteria = [], |
129
|
|
|
$asobject = false, |
130
|
|
|
$sort = 'friendship_id', |
131
|
|
|
$order = 'ASC', |
132
|
|
|
$limit = 0, |
133
|
|
|
$start = 0 |
134
|
|
|
) { |
135
|
|
|
$db = XoopsDatabaseFactory::getDatabaseConnection(); |
136
|
|
|
|
137
|
|
|
$ret = []; |
138
|
|
|
|
139
|
|
|
$whereQuery = ''; |
140
|
|
|
|
141
|
|
|
if (\is_array($criteria) && \count($criteria) > 0) { |
142
|
|
|
$whereQuery = ' WHERE'; |
143
|
|
|
|
144
|
|
|
foreach ($criteria as $c) { |
145
|
|
|
$whereQuery .= " ${c} AND"; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
$whereQuery = mb_substr($whereQuery, 0, -4); |
149
|
|
|
} elseif (!\is_array($criteria) && $criteria) { |
150
|
|
|
$whereQuery = ' WHERE ' . $criteria; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
if (!$asobject) { |
154
|
|
|
$sql = 'SELECT friendship_id FROM ' . $db->prefix( |
155
|
|
|
'yogurt_friendships' |
156
|
|
|
) . "${whereQuery} ORDER BY ${sort} ${order}"; |
157
|
|
|
|
158
|
|
|
$result = $db->query($sql, $limit, $start); |
159
|
|
|
|
160
|
|
|
while (false !== ($myrow = $db->fetchArray($result))) { |
161
|
|
|
$ret[] = $myrow['yogurt_friendship_id']; |
162
|
|
|
} |
163
|
|
|
} else { |
164
|
|
|
$sql = 'SELECT * FROM ' . $db->prefix('yogurt_friendships') . "${whereQuery} ORDER BY ${sort} ${order}"; |
165
|
|
|
|
166
|
|
|
$result = $db->query($sql, $limit, $start); |
167
|
|
|
|
168
|
|
|
while (false !== ($myrow = $db->fetchArray($result))) { |
169
|
|
|
$ret[] = new self($myrow); |
170
|
|
|
} |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
return $ret; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* Get form |
178
|
|
|
* |
179
|
|
|
* @return \XoopsModules\Yogurt\Form\FriendshipForm |
180
|
|
|
*/ |
181
|
|
|
|
182
|
|
|
public function getForm() |
183
|
|
|
{ |
184
|
|
|
return new Form\FriendshipForm($this); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* @return array|null |
189
|
|
|
*/ |
190
|
|
|
|
191
|
|
|
public function getGroupsRead() |
192
|
|
|
{ |
193
|
|
|
//$permHelper = new \Xmf\Module\Helper\Permission(); |
194
|
|
|
|
195
|
|
|
return $this->permHelper->getGroupsForItem( |
196
|
|
|
'sbcolumns_read', |
197
|
|
|
$this->getVar('friendship_id') |
198
|
|
|
); |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* @return array|null |
203
|
|
|
*/ |
204
|
|
|
|
205
|
|
|
public function getGroupsSubmit() |
206
|
|
|
{ |
207
|
|
|
//$permHelper = new \Xmf\Module\Helper\Permission(); |
208
|
|
|
|
209
|
|
|
return $this->permHelper->getGroupsForItem( |
210
|
|
|
'sbcolumns_submit', |
211
|
|
|
$this->getVar('friendship_id') |
212
|
|
|
); |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* @return array|null |
217
|
|
|
*/ |
218
|
|
|
|
219
|
|
|
public function getGroupsModeration() |
220
|
|
|
{ |
221
|
|
|
//$permHelper = new \Xmf\Module\Helper\Permission(); |
222
|
|
|
|
223
|
|
|
return $this->permHelper->getGroupsForItem( |
224
|
|
|
'sbcolumns_moderation', |
225
|
|
|
$this->getVar('friendship_id') |
226
|
|
|
); |
227
|
|
|
} |
228
|
|
|
} |
229
|
|
|
|