public static
renderRateFile
(mixed $id, mixed $displayRating, mixed $small = 1, mixed $refresh = false)
public static function renderRateFile($id, $displayRating, $small = 1, $refresh = false)
{
$user = Factory::getUser();
$neededAccessLevels = PhocaDownloadAccess::getNeededAccessLevels();
$access = PhocaDownloadAccess::isAccess($user->getAuthorisedViewLevels(), $neededAccessLevels);
if ($small == 1) {
$smallO = '-small';
$ratio = 18;
} else {
$smallO = '';
$ratio = 22;
}
$o = '';
//.$rating['urlvote'].$amp.'controller=detail&task=rate&rating=1
//$amp = PhocaDownloadAccess::setQuestionmarkOrAmp($rating['urlvote']);
$href = 'javascript:void(0);';
if ((int) $displayRating != 1) {
return '';
} else {
$rating['alreadyratedfile'] = self::checkUserVoteFile((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::getVotesStatisticsFile((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_PHOCADOWNLOAD_RATING_ALREADY_RATED_FILE');
//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_PHOCADOWNLOAD_RATING') . '</strong>: ' . $rating['votesaveragefile'] . ' / ' . $rating['votescountfile'] . ' ' . Text::_('COM_PHOCADOWNLOAD_' . $rating['votestextimg']) . ' </div>';
if ($rating['alreadyratedfile']) {
$o .= '<div style="float:left;"><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="pd-result" id="pdresult' . (int) $id . '" style="float:left;margin-left:5px">' . Text::_('COM_PHOCADOWNLOAD_RATING_ALREADY_RATED_FILE') . '</div>';
} else {
if ($rating['notregisteredfile']) {
$o .= '<div style="float:left;"><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="pd-result" id="pdresult' . (int) $id . '" style="float:left;margin-left:5px">' . Text::_('COM_PHOCADOWNLOAD_ONLY_REGISTERED_LOGGED_RATE_FILE') . '</div>';
} else {
$o .= '<div style="float:left;"><ul class="star-rating' . $smallO . '">' . '<li class="current-rating" style="width:' . $rating['voteswidthfile'] . 'px"></li>' . '<li><a href="' . $href . '" onclick="pdRating(' . (int) $id . ', 1)" title="1 ' . Text::_('COM_PHOCADOWNLOAD_STAR_OUT_OF') . ' 5" class="star1">1</a></li>';
for ($i = 2; $i < 6; $i++) {
$o .= '<li><a href="' . $href . '" onclick="pdRating(' . (int) $id . ', ' . $i . ')" title="' . $i . ' ' . Text::_('COM_PHOCADOWNLOAD_STARS_OUT_OF') . ' 5" class="stars' . $i . '">' . $i . '</a></li>';
}
$o .= '</ul></div>';
$or = '<div class="pd-result" id="pdresult' . (int) $id . '" style="float:left;margin-left:5px"></div>';
}
}
}
if ($refresh == true) {
return $o;
//we are in Ajax, return only content of pdvoting div
} else {
return '<div id="pdvoting' . (int) $id . '">' . $o . '</div>' . $or;
//not in ajax, return the contend in div
}
}