1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace XoopsModules\Publisher; |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
You may not change or alter any portion of this comment or credits |
7
|
|
|
of supporting developers from this source code or any supporting source code |
8
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
9
|
|
|
|
10
|
|
|
This program is distributed in the hope that it will be useful, |
11
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
12
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Publisher module for xoops |
17
|
|
|
* |
18
|
|
|
* @copyright module for xoops |
19
|
|
|
* @license GPL 3.0 or later |
20
|
|
|
* @since 1.0 |
21
|
|
|
* @min_xoops 2.5.10 |
22
|
|
|
* @author XOOPS Development Team |
23
|
|
|
*/ |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Class Object VoteHandler |
27
|
|
|
*/ |
28
|
|
|
class VoteHandler extends \XoopsPersistableObjectHandler |
29
|
|
|
{ |
30
|
|
|
private const TABLE = 'publisher_rating'; |
31
|
|
|
private const ENTITY = Vote::class; |
32
|
|
|
private const ENTITYNAME = 'Vote'; |
33
|
|
|
private const KEYNAME = 'ratingid'; |
34
|
|
|
private const IDENTIFIER = 'itemid'; |
35
|
|
|
private const SOURCE = 'source'; |
36
|
|
|
/** |
37
|
|
|
* @var Helper |
38
|
|
|
*/ |
39
|
|
|
public $helper; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Constructor |
43
|
|
|
* @param \XoopsModules\Publisher\Helper|null $helper |
44
|
|
|
*/ |
45
|
|
|
public function __construct(\XoopsDatabase $db = null, Helper $helper = null) |
46
|
|
|
{ |
47
|
|
|
$this->db = $db; |
48
|
|
|
/** @var Helper $this- >helper */ |
49
|
|
|
$this->helper = $helper ?? Helper::getInstance(); |
50
|
|
|
|
51
|
|
|
parent::__construct($db, static::TABLE, static::ENTITY, static::KEYNAME, static::IDENTIFIER); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* get inserted id |
56
|
|
|
* |
57
|
|
|
* @param null |
58
|
|
|
* @return int reference to the {@link Get} object |
59
|
|
|
*/ |
60
|
|
|
public function getInsertId(): int |
61
|
|
|
{ |
62
|
|
|
return $this->db->getInsertId(); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Get Rating per item in the database |
67
|
|
|
* @param int|null $itemId |
68
|
|
|
* @param int|null $source |
69
|
|
|
*/ |
70
|
|
|
public function getItemRating($itemId = null, $source = null): array |
71
|
|
|
{ |
72
|
|
|
$itemId = $itemId ?? 0; |
73
|
|
|
$source = $source ?? 0; |
74
|
|
|
$xoopsUser = $GLOBALS['xoopsUser']; |
75
|
|
|
|
76
|
|
|
$itemRating = []; |
77
|
|
|
$itemRating['nb_vote'] = 0; |
78
|
|
|
$uid = \is_object($xoopsUser) ? $xoopsUser->getVar('uid') : 0; |
79
|
|
|
$voted = false; |
80
|
|
|
$ip = \getenv('REMOTE_ADDR'); |
81
|
|
|
$currentRating = 0; |
82
|
|
|
$count = 0; |
83
|
|
|
|
84
|
|
|
$max_units = 10; |
85
|
|
|
$ratingbarsValue = (int)$this->helper->getConfig('ratingbars'); |
86
|
|
|
$ratingArray = [Constants::RATING_5STARS, Constants::RATING_10STARS, Constants::RATING_10NUM]; |
87
|
|
|
|
88
|
|
|
if (\in_array($ratingbarsValue, $ratingArray, true)) { |
89
|
|
|
$rating_unitwidth = 25; |
90
|
|
|
if (Constants::RATING_5STARS === (int)$this->helper->getConfig('ratingbars')) { |
91
|
|
|
$max_units = 5; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
$criteria = new \CriteriaCompo(); |
95
|
|
|
$criteria->add(new \Criteria(static::IDENTIFIER, $itemId)); |
96
|
|
|
$criteria->add(new \Criteria(static::SOURCE, $source)); |
97
|
|
|
|
98
|
|
|
$voteObjs = $this->helper->getHandler(static::ENTITYNAME) |
99
|
|
|
->getObjects($criteria); |
|
|
|
|
100
|
|
|
$count = \count($voteObjs); |
101
|
|
|
$itemRating['nb_vote'] = $count; |
102
|
|
|
|
103
|
|
|
foreach ($voteObjs as $voteObj) { |
104
|
|
|
$currentRating += $voteObj->getVar('rate'); |
105
|
|
|
if (($voteObj->getVar('ip') == $ip && 0 == $uid) || ($uid > 0 && $uid == $voteObj->getVar('uid'))) { |
106
|
|
|
$voted = true; |
107
|
|
|
$itemRating['id'] = $voteObj->getVar('ratingid'); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
unset($criteria); |
111
|
|
|
|
112
|
|
|
$itemRating['avg_rate_value'] = 0; |
113
|
|
|
if ($count > 0) { |
114
|
|
|
$itemRating['avg_rate_value'] = \number_format($currentRating / $count, 2); |
115
|
|
|
} |
116
|
|
|
if (1 == $count) { |
117
|
|
|
$text = \str_replace('%c', $itemRating['avg_rate_value'], \_MA_PUBLISHER_RATING_CURRENT_1); |
118
|
|
|
$shorttext = \str_replace('%c', $itemRating['avg_rate_value'], \_MA_PUBLISHER_RATING_CURRENT_SHORT_1); |
119
|
|
|
} else { |
120
|
|
|
$text = \str_replace('%c', $itemRating['avg_rate_value'], \_MA_PUBLISHER_RATING_CURRENT_X); |
121
|
|
|
$shorttext = \str_replace('%c', $itemRating['avg_rate_value'], \_MA_PUBLISHER_RATING_CURRENT_SHORT_X); |
122
|
|
|
} |
123
|
|
|
$text = \str_replace('%m', (string)$max_units, $text); |
124
|
|
|
$text = \str_replace('%t', (string)$itemRating['nb_vote'], $text); |
125
|
|
|
$shorttext = \str_replace('%t', (string)$itemRating['nb_vote'], $shorttext); |
126
|
|
|
$itemRating['text'] = $text; |
127
|
|
|
$itemRating['shorttext'] = $shorttext; |
128
|
|
|
$itemRating['size'] = ($itemRating['avg_rate_value'] * $rating_unitwidth) . 'px'; |
129
|
|
|
$itemRating['maxsize'] = ($max_units * $rating_unitwidth) . 'px'; |
130
|
|
|
|
131
|
|
|
$itemRating['ip'] = $ip; |
132
|
|
|
$itemRating['uid'] = $uid; |
133
|
|
|
$itemRating['voted'] = $voted; |
134
|
|
|
// YouTube Liking ========================================== |
135
|
|
|
} elseif (Constants::RATING_LIKES === (int)$this->helper->getConfig('ratingbars')) { |
136
|
|
|
// get count of "dislikes" |
137
|
|
|
$criteria = new \CriteriaCompo(); |
138
|
|
|
$criteria->add(new \Criteria(static::IDENTIFIER, $itemId)); |
139
|
|
|
$criteria->add(new \Criteria(static::SOURCE, $source)); |
140
|
|
|
$criteria->add(new \Criteria('rate', 0, '<')); |
141
|
|
|
|
142
|
|
|
$voteObjs = $this->helper->getHandler(static::ENTITYNAME) |
143
|
|
|
->getObjects($criteria); |
144
|
|
|
$count = \count($voteObjs); |
145
|
|
|
|
146
|
|
|
foreach ($voteObjs as $voteObj) { |
147
|
|
|
$currentRating += $voteObj->getVar('rate'); |
148
|
|
|
if (($voteObj->getVar('ip') == $ip && 0 == $uid) || ($uid > 0 && $uid == $voteObj->getVar('uid'))) { |
149
|
|
|
$voted = true; |
150
|
|
|
$itemRating['id'] = $voteObj->getVar('ratingid'); |
151
|
|
|
} |
152
|
|
|
} |
153
|
|
|
unset($criteria); |
154
|
|
|
$itemRating['dislikes'] = $count; |
155
|
|
|
|
156
|
|
|
// get count of "likes" |
157
|
|
|
$criteria = new \CriteriaCompo(); |
158
|
|
|
$criteria->add(new \Criteria(static::IDENTIFIER, $itemId)); |
159
|
|
|
$criteria->add(new \Criteria(static::SOURCE, $source)); |
160
|
|
|
$criteria->add(new \Criteria('rate', 0, '>')); |
161
|
|
|
|
162
|
|
|
$voteObjs = $this->helper->getHandler(static::ENTITYNAME) |
163
|
|
|
->getObjects($criteria); |
164
|
|
|
$count = \count($voteObjs); |
165
|
|
|
$currentRating = 0; |
166
|
|
|
foreach ($voteObjs as $voteObj) { |
167
|
|
|
$currentRating += $voteObj->getVar('rate'); |
168
|
|
|
if (($voteObj->getVar('ip') == $ip && 0 == $uid) || ($uid > 0 && $uid == $voteObj->getVar('uid'))) { |
169
|
|
|
$voted = true; |
170
|
|
|
$itemRating['id'] = $voteObj->getVar('ratingid'); |
171
|
|
|
} |
172
|
|
|
} |
173
|
|
|
unset($criteria); |
174
|
|
|
$itemRating['likes'] = $count; |
175
|
|
|
|
176
|
|
|
$itemRating['nb_vote'] = $itemRating['likes'] + $itemRating['dislikes']; |
177
|
|
|
$itemRating['ip'] = $ip; |
178
|
|
|
$itemRating['uid'] = $uid; |
179
|
|
|
$itemRating['voted'] = $voted; |
180
|
|
|
// Facebook Reactions ========================================== |
181
|
|
|
} elseif (Constants::RATING_REACTION === (int)$this->helper->getConfig('ratingbars')) { |
182
|
|
|
$criteria = new \CriteriaCompo(); |
183
|
|
|
$criteria->add(new \Criteria(static::IDENTIFIER, $itemId)); |
184
|
|
|
$criteria->add(new \Criteria(static::SOURCE, $source)); |
185
|
|
|
$criteria->add(new \Criteria('rate', 0, '<')); |
186
|
|
|
|
187
|
|
|
$voteObjs = $this->helper->getHandler(static::ENTITYNAME) |
188
|
|
|
->getObjects($criteria); |
189
|
|
|
$count = \count($voteObjs); |
190
|
|
|
$itemRating['nb_vote'] = $count; |
191
|
|
|
|
192
|
|
|
foreach ($voteObjs as $voteObj) { |
193
|
|
|
$currentRating += $voteObj->getVar('rate'); |
194
|
|
|
if (($voteObj->getVar('ip') == $ip && 0 == $uid) || ($uid > 0 && $uid == $voteObj->getVar('uid'))) { |
195
|
|
|
$voted = true; |
196
|
|
|
$itemRating['id'] = $voteObj->getVar('ratingid'); |
197
|
|
|
} |
198
|
|
|
} |
199
|
|
|
unset($criteria); |
200
|
|
|
$itemRating['dislikes'] = $count; |
201
|
|
|
|
202
|
|
|
$criteria = new \CriteriaCompo(); |
203
|
|
|
$criteria->add(new \Criteria(static::IDENTIFIER, $itemId)); |
204
|
|
|
$criteria->add(new \Criteria(static::SOURCE, $source)); |
205
|
|
|
$criteria->add(new \Criteria('rate', 0, '>')); |
206
|
|
|
|
207
|
|
|
$voteObjs = $this->helper->getHandler(static::ENTITYNAME) |
208
|
|
|
->getObjects($criteria); |
209
|
|
|
$count = \count($voteObjs); |
210
|
|
|
$currentRating = 0; |
211
|
|
|
foreach ($voteObjs as $voteObj) { |
212
|
|
|
$currentRating += $voteObj->getVar('rate'); |
213
|
|
|
if (($voteObj->getVar('ip') == $ip && 0 == $uid) || ($uid > 0 && $uid == $voteObj->getVar('uid'))) { |
214
|
|
|
$voted = true; |
215
|
|
|
$itemRating['id'] = $voteObj->getVar('ratingid'); |
216
|
|
|
} |
217
|
|
|
} |
218
|
|
|
unset($criteria); |
219
|
|
|
$itemRating['likes'] = $count; |
220
|
|
|
|
221
|
|
|
$itemRating['nb_vote'] = $itemRating['likes'] + $itemRating['dislikes']; |
222
|
|
|
$itemRating['ip'] = $ip; |
223
|
|
|
$itemRating['uid'] = $uid; |
224
|
|
|
$itemRating['voted'] = $voted; |
225
|
|
|
} else { |
226
|
|
|
$itemRating['uid'] = $uid; |
227
|
|
|
$itemRating['nb_vote'] = $count; |
228
|
|
|
$itemRating['voted'] = $voted; |
229
|
|
|
$itemRating['ip'] = $ip; |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
return $itemRating; |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
/** |
236
|
|
|
* Get Rating per item in the database |
237
|
|
|
* @param Item|null $itemObj |
238
|
|
|
* @param int|null $source |
239
|
|
|
*/ |
240
|
|
|
public function getItemRating5($itemObj = null, $source = null): array |
241
|
|
|
{ |
242
|
|
|
$itemId = $itemObj->itemid(); |
|
|
|
|
243
|
|
|
$source = $source ?? 0; |
244
|
|
|
$xoopsUser = $GLOBALS['xoopsUser']; |
245
|
|
|
|
246
|
|
|
$itemRating = []; |
247
|
|
|
$itemRating['nb_vote'] = 0; |
248
|
|
|
$uid = \is_object($xoopsUser) ? $xoopsUser->getVar('uid') : 0; |
249
|
|
|
$voted = false; |
250
|
|
|
$ip = \getenv('REMOTE_ADDR'); |
251
|
|
|
$currentRating = 0; |
252
|
|
|
$count = 0; |
253
|
|
|
|
254
|
|
|
$max_units = 10; |
255
|
|
|
$ratingbarsValue = $itemObj->votetype(); |
|
|
|
|
256
|
|
|
$ratingArray = [Constants::RATING_5STARS, Constants::RATING_10STARS, Constants::RATING_10NUM]; |
257
|
|
|
|
258
|
|
|
if (\in_array($ratingbarsValue, $ratingArray, true)) { |
259
|
|
|
$rating_unitwidth = 25; |
260
|
|
|
if (Constants::RATING_5STARS === $ratingbarsValue) { |
261
|
|
|
$max_units = 5; |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
$criteria = new \CriteriaCompo(); |
265
|
|
|
$criteria->add(new \Criteria(static::IDENTIFIER, $itemId)); |
|
|
|
|
266
|
|
|
$criteria->add(new \Criteria(static::SOURCE, $source)); |
267
|
|
|
|
268
|
|
|
$voteObjs = $this->helper->getHandler(static::ENTITYNAME) |
269
|
|
|
->getObjects($criteria); |
270
|
|
|
$count = \count($voteObjs); |
271
|
|
|
$itemRating['nb_vote'] = $count; |
272
|
|
|
|
273
|
|
|
foreach ($voteObjs as $voteObj) { |
274
|
|
|
$currentRating += $voteObj->getVar('rate'); |
275
|
|
|
if (($voteObj->getVar('ip') == $ip && 0 == $uid) || ($uid > 0 && $uid == $voteObj->getVar('uid'))) { |
276
|
|
|
$voted = true; |
277
|
|
|
$itemRating['id'] = $voteObj->getVar('ratingid'); |
278
|
|
|
} |
279
|
|
|
} |
280
|
|
|
unset($criteria); |
281
|
|
|
|
282
|
|
|
$itemRating['avg_rate_value'] = 0; |
283
|
|
|
if ($count > 0) { |
284
|
|
|
$itemRating['avg_rate_value'] = \number_format($currentRating / $count, 2); |
285
|
|
|
} |
286
|
|
|
if (1 == $count) { |
287
|
|
|
$text = \str_replace('%c', $itemRating['avg_rate_value'], \_MA_PUBLISHER_RATING_CURRENT_1); |
288
|
|
|
$shorttext = \str_replace('%c', $itemRating['avg_rate_value'], \_MA_PUBLISHER_RATING_CURRENT_SHORT_1); |
289
|
|
|
} else { |
290
|
|
|
$text = \str_replace('%c', $itemRating['avg_rate_value'], \_MA_PUBLISHER_RATING_CURRENT_X); |
291
|
|
|
$shorttext = \str_replace('%c', $itemRating['avg_rate_value'], \_MA_PUBLISHER_RATING_CURRENT_SHORT_X); |
292
|
|
|
} |
293
|
|
|
$text = \str_replace('%m', (string)$max_units, $text); |
294
|
|
|
$text = \str_replace('%t', (string)$itemRating['nb_vote'], $text); |
295
|
|
|
$shorttext = \str_replace('%t', (string)$itemRating['nb_vote'], $shorttext); |
296
|
|
|
$itemRating['text'] = $text; |
297
|
|
|
$itemRating['shorttext'] = $shorttext; |
298
|
|
|
$itemRating['size'] = ($itemRating['avg_rate_value'] * $rating_unitwidth) . 'px'; |
299
|
|
|
$itemRating['maxsize'] = ($max_units * $rating_unitwidth) . 'px'; |
300
|
|
|
|
301
|
|
|
$itemRating['ip'] = $ip; |
302
|
|
|
$itemRating['uid'] = $uid; |
303
|
|
|
$itemRating['voted'] = $voted; |
304
|
|
|
// YouTube Liking ========================================== |
305
|
|
|
} elseif (Constants::RATING_LIKES === $ratingbarsValue) { |
306
|
|
|
// get count of "dislikes" |
307
|
|
|
$criteria = new \CriteriaCompo(); |
308
|
|
|
$criteria->add(new \Criteria(static::IDENTIFIER, $itemId)); |
309
|
|
|
$criteria->add(new \Criteria(static::SOURCE, $source)); |
310
|
|
|
$criteria->add(new \Criteria('rate', 0, '<')); |
311
|
|
|
|
312
|
|
|
$voteObjs = $this->helper->getHandler(static::ENTITYNAME) |
313
|
|
|
->getObjects($criteria); |
314
|
|
|
$count = \count($voteObjs); |
315
|
|
|
|
316
|
|
|
foreach ($voteObjs as $voteObj) { |
317
|
|
|
$currentRating += $voteObj->getVar('rate'); |
318
|
|
|
if (($voteObj->getVar('ip') == $ip && 0 == $uid) || ($uid > 0 && $uid == $voteObj->getVar('uid'))) { |
319
|
|
|
$voted = true; |
320
|
|
|
$itemRating['id'] = $voteObj->getVar('ratingid'); |
321
|
|
|
} |
322
|
|
|
} |
323
|
|
|
unset($criteria); |
324
|
|
|
$itemRating['dislikes'] = $count; |
325
|
|
|
|
326
|
|
|
// get count of "likes" |
327
|
|
|
$criteria = new \CriteriaCompo(); |
328
|
|
|
$criteria->add(new \Criteria(static::IDENTIFIER, $itemId)); |
329
|
|
|
$criteria->add(new \Criteria(static::SOURCE, $source)); |
330
|
|
|
$criteria->add(new \Criteria('rate', 0, '>')); |
331
|
|
|
|
332
|
|
|
$voteObjs = $this->helper->getHandler(static::ENTITYNAME) |
333
|
|
|
->getObjects($criteria); |
334
|
|
|
$count = \count($voteObjs); |
335
|
|
|
$currentRating = 0; |
336
|
|
|
foreach ($voteObjs as $voteObj) { |
337
|
|
|
$currentRating += $voteObj->getVar('rate'); |
338
|
|
|
if (($voteObj->getVar('ip') == $ip && 0 == $uid) || ($uid > 0 && $uid == $voteObj->getVar('uid'))) { |
339
|
|
|
$voted = true; |
340
|
|
|
$itemRating['id'] = $voteObj->getVar('ratingid'); |
341
|
|
|
} |
342
|
|
|
} |
343
|
|
|
unset($criteria); |
344
|
|
|
$itemRating['likes'] = $count; |
345
|
|
|
|
346
|
|
|
$itemRating['nb_vote'] = $itemRating['likes'] + $itemRating['dislikes']; |
347
|
|
|
$itemRating['ip'] = $ip; |
348
|
|
|
$itemRating['uid'] = $uid; |
349
|
|
|
$itemRating['voted'] = $voted; |
350
|
|
|
// Facebook Reactions ========================================== |
351
|
|
|
} elseif (Constants::RATING_REACTION === $ratingbarsValue) { |
352
|
|
|
$criteria = new \CriteriaCompo(); |
353
|
|
|
$criteria->add(new \Criteria(static::IDENTIFIER, $itemId)); |
354
|
|
|
$criteria->add(new \Criteria(static::SOURCE, $source)); |
355
|
|
|
$criteria->add(new \Criteria('rate', 1)); |
356
|
|
|
$voteObjs = $this->helper->getHandler(static::ENTITYNAME) |
357
|
|
|
->getObjects($criteria); |
358
|
|
|
$count = \count($voteObjs); |
359
|
|
|
$itemRating['likes'] = $count; |
360
|
|
|
|
361
|
|
|
$criteria = new \CriteriaCompo(); |
362
|
|
|
$criteria->add(new \Criteria(static::IDENTIFIER, $itemId)); |
363
|
|
|
$criteria->add(new \Criteria(static::SOURCE, $source)); |
364
|
|
|
$criteria->add(new \Criteria('rate', 2)); |
365
|
|
|
$voteObjs = $this->helper->getHandler(static::ENTITYNAME) |
366
|
|
|
->getObjects($criteria); |
367
|
|
|
$count = \count($voteObjs); |
368
|
|
|
$itemRating['love'] = $count; |
369
|
|
|
|
370
|
|
|
$criteria = new \CriteriaCompo(); |
371
|
|
|
$criteria->add(new \Criteria(static::IDENTIFIER, $itemId)); |
372
|
|
|
$criteria->add(new \Criteria(static::SOURCE, $source)); |
373
|
|
|
$criteria->add(new \Criteria('rate', 3)); |
374
|
|
|
$voteObjs = $this->helper->getHandler(static::ENTITYNAME) |
375
|
|
|
->getObjects($criteria); |
376
|
|
|
$count = \count($voteObjs); |
377
|
|
|
$itemRating['smile'] = $count; |
378
|
|
|
|
379
|
|
|
$criteria = new \CriteriaCompo(); |
380
|
|
|
$criteria->add(new \Criteria(static::IDENTIFIER, $itemId)); |
381
|
|
|
$criteria->add(new \Criteria(static::SOURCE, $source)); |
382
|
|
|
$criteria->add(new \Criteria('rate', 4)); |
383
|
|
|
$voteObjs = $this->helper->getHandler(static::ENTITYNAME) |
384
|
|
|
->getObjects($criteria); |
385
|
|
|
$count = \count($voteObjs); |
386
|
|
|
$itemRating['wow'] = $count; |
387
|
|
|
|
388
|
|
|
$criteria = new \CriteriaCompo(); |
389
|
|
|
$criteria->add(new \Criteria(static::IDENTIFIER, $itemId)); |
390
|
|
|
$criteria->add(new \Criteria(static::SOURCE, $source)); |
391
|
|
|
$criteria->add(new \Criteria('rate', 5)); |
392
|
|
|
$voteObjs = $this->helper->getHandler(static::ENTITYNAME) |
393
|
|
|
->getObjects($criteria); |
394
|
|
|
$count = \count($voteObjs); |
395
|
|
|
$itemRating['sad'] = $count; |
396
|
|
|
|
397
|
|
|
$criteria = new \CriteriaCompo(); |
398
|
|
|
$criteria->add(new \Criteria(static::IDENTIFIER, $itemId)); |
399
|
|
|
$criteria->add(new \Criteria(static::SOURCE, $source)); |
400
|
|
|
$criteria->add(new \Criteria('rate', 6)); |
401
|
|
|
$voteObjs = $this->helper->getHandler(static::ENTITYNAME) |
402
|
|
|
->getObjects($criteria); |
403
|
|
|
$count = \count($voteObjs); |
404
|
|
|
$itemRating['angry'] = $count; |
405
|
|
|
|
406
|
|
|
$itemRating['nb_vote'] = $itemRating['likes'] + $itemRating['love'] + $itemRating['smile'] + $itemRating['wow'] + $itemRating['sad'] + $itemRating['angry']; |
407
|
|
|
$itemRating['ip'] = $ip; |
408
|
|
|
$itemRating['uid'] = $uid; |
409
|
|
|
$itemRating['voted'] = $voted; |
410
|
|
|
} else { |
411
|
|
|
$itemRating['uid'] = $uid; |
412
|
|
|
$itemRating['nb_vote'] = $count; |
413
|
|
|
$itemRating['voted'] = $voted; |
414
|
|
|
$itemRating['ip'] = $ip; |
415
|
|
|
} |
416
|
|
|
|
417
|
|
|
return $itemRating; |
418
|
|
|
} |
419
|
|
|
|
420
|
|
|
/** |
421
|
|
|
* delete vote of given item |
422
|
|
|
* @param mixed $itemId |
423
|
|
|
* @param mixed $source |
424
|
|
|
*/ |
425
|
|
|
public function deleteAllVote($itemId, $source): bool |
426
|
|
|
{ |
427
|
|
|
$criteria = new \CriteriaCompo(); |
428
|
|
|
$criteria->add(new \Criteria(static::IDENTIFIER, $itemId)); |
429
|
|
|
$criteria->add(new \Criteria(static::SOURCE, $source)); |
430
|
|
|
|
431
|
|
|
return $this->deleteAll($criteria); |
432
|
|
|
} |
433
|
|
|
|
434
|
|
|
//TODO |
435
|
|
|
// delete all votes for an item |
436
|
|
|
// delete all votes |
437
|
|
|
// updates Vote counts for an item after new vote |
438
|
|
|
// convert vote type to another |
439
|
|
|
// TopRated |
440
|
|
|
// getAggregate |
441
|
|
|
|
442
|
|
|
// Average, Sum, Count |
443
|
|
|
// getVotingElement (FiveStarts, Reaction) |
444
|
|
|
// buildForm, getStyle |
445
|
|
|
// |
446
|
|
|
//tableName |
447
|
|
|
//behaviors |
448
|
|
|
//rules |
449
|
|
|
//attributeLabels |
450
|
|
|
//afterSave |
451
|
|
|
//getModelIdByName |
452
|
|
|
//getModelNameById |
453
|
|
|
//getIsAllowGuests |
454
|
|
|
//getIsAllowChangeVote |
455
|
|
|
//updateRating |
456
|
|
|
|
457
|
|
|
//getId |
458
|
|
|
//getVoterId |
459
|
|
|
//getVoterName |
460
|
|
|
//getVoteableId |
461
|
|
|
//getVotableName |
462
|
|
|
//getValue |
463
|
|
|
//getRange |
464
|
|
|
//getMinValue |
465
|
|
|
//getMaxValue |
466
|
|
|
//getTime |
467
|
|
|
|
468
|
|
|
//VoteRepositoryInterface: |
469
|
|
|
//find |
470
|
|
|
//findByVoter |
471
|
|
|
//findByVotable |
472
|
|
|
//getCountByVotable |
473
|
|
|
//getAvgByVotable |
474
|
|
|
//create |
475
|
|
|
//delete |
476
|
|
|
|
477
|
|
|
//VotesRepositoryTest |
478
|
|
|
//repo |
479
|
|
|
//vote |
480
|
|
|
//__construct |
481
|
|
|
//testRepo |
482
|
|
|
//_testCreate |
483
|
|
|
//_testFindByVoter |
484
|
|
|
//_testFindByVotable |
485
|
|
|
//_testAvg |
486
|
|
|
//_testCount |
487
|
|
|
//_testDelete |
488
|
|
|
//_votable |
489
|
|
|
//_voter |
490
|
|
|
|
491
|
|
|
//FieldVoteResultBase: |
492
|
|
|
//calculateResult |
493
|
|
|
//getVotesForField |
494
|
|
|
// |
495
|
|
|
// |
496
|
|
|
//VotingApiField: |
497
|
|
|
//defaultFieldSettings |
498
|
|
|
//defaultStorageSettings |
499
|
|
|
//fieldSettingsForm |
500
|
|
|
//generateSampleValue |
501
|
|
|
//isEmpty |
502
|
|
|
//mainPropertyName |
503
|
|
|
//postSave |
504
|
|
|
//propertyDefinitions |
505
|
|
|
//schema |
506
|
|
|
//storageSettingsForm |
507
|
|
|
// |
508
|
|
|
// |
509
|
|
|
//VotingApiWidgetBase: |
510
|
|
|
//canVote |
511
|
|
|
//getEntityForVoting |
512
|
|
|
//getForm |
513
|
|
|
//getInitialVotingElement |
514
|
|
|
//getLabel |
515
|
|
|
//getResults |
516
|
|
|
//getValues |
517
|
|
|
//getVoteSummary |
518
|
|
|
//getWindow |
519
|
|
|
|
520
|
|
|
//Rating |
521
|
|
|
//afterSave |
522
|
|
|
//attributeLabels |
523
|
|
|
//behaviors |
524
|
|
|
//compressIp |
525
|
|
|
//expandIp |
526
|
|
|
//getIsAllowChangeVote |
527
|
|
|
//getIsAllowGuests |
528
|
|
|
//getModelIdByName |
529
|
|
|
//getModelNameById |
530
|
|
|
//rules |
531
|
|
|
//tableName |
532
|
|
|
//updateRating |
533
|
|
|
} |
534
|
|
|
|