forked from VersoBit/XF-Badges
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EventListener.php
48 lines (38 loc) · 1.23 KB
/
EventListener.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
/**
* Badges xF2 addon by CMTV
* Enjoy!
*/
namespace CMTV\Badges;
use CMTV\Badges\Constants as C;
use XF;
use XF\Entity\User;
class EventListener
{
public static function criteriaUser($rule, array $data, User $user, &$returnValue)
{
/** @var XF\Entity\User $user */
$user = $user;
switch ($rule) {
case C::_('badge_count'):
$returnValue = $user->cmtv_badges_badge_count && $user->cmtv_badges_badge_count >= $data['badges'];
break;
case C::_('badge_count_max'):
$returnValue = $user->cmtv_badges_badge_count && $user->cmtv_badges_badge_count <= $data['badges'];
break;
case C::_('has_badge'):
$ids = explode(',', $data['badge_ids']);
foreach ($ids as &$id) {
$id = intval($id);
}
$awardedIds = XF::repository(C::__('UserBadge'))->getAwardedBadgeIds($user->user_id);
$returnValue = true;
foreach ($ids as $id) {
if (!in_array($id, $awardedIds)) {
$returnValue = false;
}
}
break;
}
}
}