Skip to content
This repository has been archived by the owner on Oct 13, 2021. It is now read-only.

Automatically remove badges based on criteria #24

Open
RyleaStark opened this issue Nov 28, 2020 · 1 comment
Open

Automatically remove badges based on criteria #24

RyleaStark opened this issue Nov 28, 2020 · 1 comment
Labels
bug Something isn't working CRON Related to CRON jobs UI:ACP Related to UI (Admin) XF 2.2.x XenForo Version 2.2.x

Comments

@RyleaStark
Copy link
Member

Badges currently only award badges, it is up to the administrator/moderators to remove any badges that have been assigned.

Suggested Solution: Add a "automatic removal" option to badges which will trigger a cron process that will validate the criteria (and either remove or assign). Option should ONLY be toggleable on a per-badge basis.

Related Code:

XF-Badges/Cron/Badge.php

Lines 40 to 60 in 1e9605e

foreach ($users as $user) {
/** @var UserBadge $userBadgeRepo */
$userBadgeRepo = XF::repository(C::__('UserBadge'));
$awardedIds = $userBadgeRepo->getAwardedBadgeIds($user->user_id);
/** @var \CMTV\Badges\Entity\Badge $badge */
foreach ($badges as $badge) {
if (in_array($badge->badge_id, $awardedIds)) {
continue;
}
$userCriteria = XF::app()->criteria('XF:User', $badge->user_criteria);
$userCriteria->setMatchOnEmpty(false);
if ($userCriteria->isMatched($user)) {
$userBadgeRepo->awardWithBadge($user, $badge->badge_id);
}
}
}
}

Additional Requirements: ACP:UI option to allow toggle.

Reported by Bulbagarden on XenForo Community Post 42

@RyleaStark RyleaStark added bug Something isn't working XF 2.2.x XenForo Version 2.2.x UI:ACP Related to UI (Admin) CRON Related to CRON jobs labels Nov 28, 2020
@shr3k
Copy link

shr3k commented Dec 13, 2020

That will be very convenient for moderators ... Thanks.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working CRON Related to CRON jobs UI:ACP Related to UI (Admin) XF 2.2.x XenForo Version 2.2.x
Projects
None yet
Development

No branches or pull requests

2 participants