public static function badge(UserBadge $badge, $mediaPath, $tip = false, $placeholders = array())
 {
     $title = '';
     $class = '';
     $classes = array();
     if ($tip and $badge->getBadge()->getActivityText()) {
         JHtml::_('bootstrap.tooltip');
         $classes[] = 'hasTooltip';
         $description = strip_tags(trim($badge->getBadge()->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($badge->getBadge()->getTitle()));
     if ($alt !== null and $alt !== '') {
         $alt = ' alt="' . htmlspecialchars($alt, ENT_QUOTES, 'UTF-8') . '"';
     }
     $html = '<img src="' . $mediaPath . '/' . $badge->getBadge()->getImage() . '"' . $class . $alt . $title . ' />';
     return $html;
 }
예제 #2
0
 /**
  * Get badge by badge ID and group ID.
  *
  * <code>
  * $keys = array(
  *       'user_id'  => 1,
  *       'group_id' => 2
  * );
  *
  * $badgeId     = 1;
  *
  * $userBadges  = new Gamification\User\Badge\Badges(\JFactory::getDbo());
  * $userBadges->load($options);
  *
  * $badge       = $userBadges->getBadge($badgeId);
  * </code>
  *
  * @param int $badgeId
  * @param int $groupId
  *
  * @return null|Badge
  */
 public function getBadge($badgeId, $groupId = 0)
 {
     $badge = null;
     if ($groupId > 0) {
         // Get an item from a specific group
         foreach ($this->items as $item) {
             if ((int) $badgeId === (int) $item['id'] and (int) $groupId === (int) $item['group_id']) {
                 $badge = new Badge($this->db);
                 $badge->bind($item);
                 break;
             }
         }
     } else {
         // Look in all groups
         foreach ($this->items as $item) {
             if ((int) $item['id'] === (int) $badgeId) {
                 $badge = new Badge($this->db);
                 $badge->bind($item);
                 break;
             }
         }
     }
     return $badge;
 }