public static function cohort_criteria_review(\core\event\cohort_member_added $event) {
        global $DB, $CFG;

        if (!empty($CFG->enablebadges)) {
            require_once($CFG->dirroot.'/lib/badgeslib.php');
            $cohortid = $event->objectid;
            $userid = $event->relateduserid;

            // Get relevant badges.
            $badgesql = "SELECT badgeid
                FROM {badge_criteria_param} cp
                JOIN {badge_criteria} c ON cp.critid = c.id
                WHERE c.criteriatype = ?
                AND cp.name = ?";
            $badges = $DB->get_records_sql($badgesql, array(BADGE_CRITERIA_TYPE_COHORT, "cohort_{$cohortid}"));
            if (empty($badges)) {
                return;
            }

            foreach ($badges as $b) {
                $badge = new badge($b->badgeid);
                if (!$badge->is_active()) {
                    continue;
                }
                if ($badge->is_issued($userid)) {
                    continue;
                }

                if ($badge->criteria[BADGE_CRITERIA_TYPE_COHORT]->review($userid)) {
                    $badge->criteria[BADGE_CRITERIA_TYPE_COHORT]->mark_complete($userid);

                    if ($badge->criteria[BADGE_CRITERIA_TYPE_OVERALL]->review($userid)) {
                        $badge->criteria[BADGE_CRITERIA_TYPE_OVERALL]->mark_complete($userid);
                        $badge->issue($userid);
                    }
                }
            }
        }
    }