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

Automatically remove badges based on criteria #24

@RyleaStark

Description

@RyleaStark

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    CRONRelated to CRON jobsUI:ACPRelated to UI (Admin)XF 2.2.xXenForo Version 2.2.xbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions