Exemplo n.º 1
0
 /**
  * Returns rendered users list in the given channel.
  *
  * @param WiseChatChannel $channel
  *
  * @return string HTML source
  */
 public function getRenderedUsersList($channel)
 {
     $channelUsers = $this->channelUsersDAO->getAllActiveByChannelId($channel->getId());
     $isCurrentUserPresent = false;
     $userId = $this->authentication->getUserIdOrNull();
     $usersList = array();
     foreach ($channelUsers as $channelUser) {
         if ($channelUser->getUser() == null) {
             continue;
         }
         // text color feature:
         $styles = '';
         if ($this->options->isOptionEnabled('allow_change_text_color')) {
             $textColor = $channelUser->getUser()->getDataProperty('textColor');
             if (strlen($textColor) > 0) {
                 $styles = sprintf('style="color: %s"', $textColor);
             }
         }
         $currentUserClassName = '';
         if ($userId == $channelUser->getUserId()) {
             $isCurrentUserPresent = true;
             $currentUserClassName = 'wcCurrentUser';
         }
         $flag = '';
         if ($this->options->isOptionEnabled('collect_user_stats', true) && $this->options->isOptionEnabled('show_users_flags', false)) {
             $countryCode = $channelUser->getUser()->getDataProperty('countryCode');
             $country = $channelUser->getUser()->getDataProperty('country');
             if (strlen($countryCode) > 0) {
                 $flagURL = $this->options->getFlagURL(strtolower($countryCode));
                 $flag = " <img src='{$flagURL}' class='wcUsersListFlag wcIcon' alt='{$countryCode}' title='{$country}'/>";
             }
         }
         $cityAndCountry = '';
         if ($this->options->isOptionEnabled('collect_user_stats', true) && $this->options->isOptionEnabled('show_users_city_and_country', false)) {
             $cityAndCountryArray = array();
             $city = $channelUser->getUser()->getDataProperty('city');
             if (strlen($city) > 0) {
                 $cityAndCountryArray[] = $city;
             }
             $countryCode = $channelUser->getUser()->getDataProperty('countryCode');
             if (strlen($countryCode) > 0) {
                 $cityAndCountryArray[] = $countryCode;
             }
             if (count($cityAndCountryArray) > 0) {
                 $cityAndCountry = ' <span class="wcUsersListCity">' . implode(', ', $cityAndCountryArray) . '</span>';
             }
         }
         $encodedName = htmlspecialchars($channelUser->getUser()->getName(), ENT_QUOTES, 'UTF-8');
         $usersList[] = sprintf('<span class="wcUserInChannel %s" %s>%s</span>', $currentUserClassName, $styles, $encodedName) . $flag . $cityAndCountry;
     }
     if (!$isCurrentUserPresent && $userId !== null) {
         array_unshift($usersList, sprintf('<span class="wcCurrentUser">%s</span>', $this->authentication->getUserNameOrEmptyString()));
     }
     return implode('<br />', $usersList);
 }