public static
renderRateImg
(mixed $id, mixed $displayRating, mixed $small = 1, mixed $refresh = false)
public static function renderRateImg($id, $displayRating, $small = 1, $refresh = false)
{
$user = Factory::getUser();
$neededAccessLevels = PhocaGalleryAccess::getNeededAccessLevels();
$access = PhocaGalleryAccess::isAccess($user->getAuthorisedViewLevels(), $neededAccessLevels);
if ($small == 1) {
$smallO = '-small';
$ratio = 16;
} else {
$smallO = '';
$ratio = 22;
}
$o = '';
$or = '';
$href = 'javascript:void(0);';
if ((int) $displayRating != 2) {
return '';
} else {
$rating['alreadyratedfile'] = self::checkUserVote((int) $id, (int) $user->id);
$rating['notregisteredfile'] = true;
//$rating['usernamefile'] = '';
if ($access > 0) {
$rating['notregisteredfile'] = false;
$rating['usernamefile'] = $user->name;
}
$rating['votescountfile'] = 0;
$rating['votesaveragefile'] = 0;
$rating['voteswidthfile'] = 0;
$votesStatistics = self::getVotesStatistics((int) $id);
if (!empty($votesStatistics->count)) {
$rating['votescountfile'] = $votesStatistics->count;
}
if (!empty($votesStatistics->average)) {
$rating['votesaveragefile'] = $votesStatistics->average;
if ($rating['votesaveragefile'] > 0) {
$rating['votesaveragefile'] = round((float) $rating['votesaveragefile'] / 0.5) * 0.5;
$rating['voteswidthfile'] = $ratio * $rating['votesaveragefile'];
} else {
$rating['votesaveragefile'] = (int) 0;
// not float displaying
}
}
// Leave message for already voted images
//$vote = JFactory::getApplication()->input->get('vote', 0, '', 'int');
$voteMsg = Text::_('COM_PHOCAGALLERY_ALREADY_RATE_IMG');
//if ($vote == 1) {
// $voteMsg = JText::_('COM_PHOCADOWNLOAD_ALREADY_RATED_FILE_THANKS');
//}
$rating['votestextimg'] = 'VOTE';
if ((int) $rating['votescountfile'] > 1) {
$rating['votestextimg'] = 'VOTES';
}
/*
$o .= '<div style="float:left;"><strong>'
. Text::_('COM_PHOCAGALLERY_RATING'). '</strong>: ' . $rating['votesaveragefile'] .' / '
.$rating['votescountfile'] . ' ' . Text::_('COM_PHOCAGALLERY_'.$rating['votestextimg']). ' </div>';
*/
if ($rating['alreadyratedfile']) {
$o .= '<div class="pg-rate-box" title="' . $voteMsg . '" ><ul class="star-rating' . $smallO . '">' . '<li class="current-rating" style="width:' . $rating['voteswidthfile'] . 'px"></li>' . '<li><span class="star1"></span></li>';
for ($i = 2; $i < 6; $i++) {
$o .= '<li><span class="stars' . $i . '"></span></li>';
}
$o .= '</ul></div>';
//$or ='<div class="pg-cv-vote-img-result" id="pg-cv-vote-img-result'.(int)$id.'" style="float:left;margin-left:5px">'.JText::_('COM_PHOCAGALLERY_ALREADY_RATE_IMG').'</div>';
} else {
if ($rating['notregisteredfile']) {
$o .= '<div class="pg-rate-box" title="' . Text::_('COM_PHOCAGALLERY_COMMENT_ONLY_REGISTERED_LOGGED_RATE_IMAGE') . '"><ul class="star-rating' . $smallO . '">' . '<li class="current-rating" style="width:' . $rating['voteswidthfile'] . 'px"></li>' . '<li><span class="star1"></span></li>';
for ($i = 2; $i < 6; $i++) {
$o .= '<li><span class="stars' . $i . '"></span></li>';
}
$o .= '</ul></div>';
//$or ='<div class="pg-cv-vote-img-result" id="pg-cv-vote-img-result'.(int)$id.'" style="float:left;margin-left:5px">'.JText::_('COM_PHOCAGALLERY_COMMENT_ONLY_REGISTERED_LOGGED_RATE_IMAGE').'</div>';
} else {
$o .= '<div class="pg-rate-box"><ul class="star-rating' . $smallO . '">' . '<li class="current-rating" style="width:' . $rating['voteswidthfile'] . 'px"></li>' . '<li><a href="' . $href . '" onclick="pgRating(' . (int) $id . ', 1, 1, \'pg-msnr-container\')" title="' . Text::sprintf('COM_PHOCAGALLERY_STAR_OUT_OF', 1, 5) . '" class="star1">1</a></li>';
for ($i = 2; $i < 6; $i++) {
$o .= '<li><a href="' . $href . '" onclick="pgRating(' . (int) $id . ', ' . $i . ', 1, \'pg-msnr-container\')" title="' . Text::sprintf('COM_PHOCAGALLERY_STARS_OUT_OF', $i, 5) . '" class="stars' . $i . '">' . $i . '</a></li>';
}
$o .= '</ul></div>';
$or = '<div class="pg-rate-img-result" id="pg-rate-img-result' . (int) $id . '"></div>';
}
}
}
if ($refresh == true) {
return $o . '<div style="clear:both;"></div>';
//we are in Ajax, return only content of pdvoting div
} else {
return '<div class="pg-rate-img" id="pg-rate-img' . (int) $id . '">' . $o . '</div>' . $or . '<div style="clear:both;"></div>';
//not in ajax, return the content in div
}
}