public static function rank(UserRank $rank, $mediaPath, $tip = false, $placeholders = array()) { $title = ''; $class = ''; $classes = array(); if ($tip and $rank->getRank()->getActivityText()) { JHtml::_('bootstrap.tooltip'); $classes[] = 'hasTooltip'; $description = strip_tags(trim($rank->getRank()->getActivityText($placeholders))); $title = ' title="' . htmlspecialchars($description, ENT_QUOTES, 'UTF-8') . '"'; } // Prepare class property if (count($classes) > 0) { $class = ' class="' . implode(' ', $classes) . '"'; } // Prepare alt property $alt = strip_tags(trim($rank->getRank()->getTitle())); if ($alt !== null and $alt !== '') { $alt = ' alt="' . htmlspecialchars($alt, ENT_QUOTES, 'UTF-8') . '"'; } $html = '<img src="' . $mediaPath . '/' . $rank->getRank()->getImage() . '"' . $class . $alt . $title . ' />'; return $html; }
/** * Prepare current and next ranks. * * @throws \RuntimeException */ public function prepareData() { $userPoints = (int) $this->points->getPointsNumber(); // Get current level. $keys = array('user_id' => $this->points->getUserId(), 'group_id' => $this->points->getPoints()->getGroupId()); $userRank = new UserRank($this->db); $userRank->load($keys); $this->currentUnit = $userRank->getRank(); // Get incoming level. $query = $this->db->getQuery(true); $query->select('a.id, a.title, a.description, a.image, a.activity_text, a.published, a.points_id, a.points_number, a.group_id')->from($this->db->quoteName('#__gfy_ranks', 'a'))->where('a.points_id = ' . (int) $this->points->getPointsId())->where('a.published = ' . (int) Constants::PUBLISHED)->where('a.points_number > ' . $userPoints)->order('a.points_number ASC'); $this->db->setQuery($query, 0, 1); $result = (array) $this->db->loadAssoc(); if (count($result) > 0) { $this->nextUnit = new BasicRank($this->db); $this->nextUnit->bind($result); $this->percentageCurrent = (int) MathHelper::calculatePercentage($userPoints, $this->nextUnit->getPointsNumber()); $this->percentageNext = 100 - $this->percentageCurrent; } else { $this->percentageCurrent = 100; $this->percentageNext = 100; } }