public function hasBadge(Badge $badge, $userId = 0) { if (!$userId and $this->id > 0) { $userId = $this->id; } $query = $this->db->getQuery(true); $query->select('COUNT(*)')->from($this->db->quoteName('#__gfy_userbadges', 'a'))->where('a.badge_id = ' . (int) $badge->getId())->where('a.user_id = ' . (int) $userId)->where('a.group_id = ' . (int) $badge->getGroupId()); $this->db->setQuery($query, 0, 1); return (bool) $this->db->loadResult(); }