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(); }
/** * Set Badge object. * This method will reset badge ID, user ID the ID of the record. * * <code> * $userBadge = new Gamification\User\Badge\Badge(JFactory::getDbo()); * * $basicBadge = new Gamification\Points\Points(JFactory::getDbo()); * $userBadge->setBadge($basicBadge); * </code> * * @param BasicBadge $badge * * @throws \OutOfBoundsException * * @return self */ public function setBadge(BasicBadge $badge) { $this->badge = $badge; $this->id = null; $this->user_id = null; $this->badge_id = $badge->getId(); // Add the badge object in the container. $key = StringHelper::generateMd5Hash(BasicBadge::class, $this->badge_id); if ($this->container !== null and !$this->container->exists($key)) { $this->container->set($key, $this->badge); } return $this; }