'lu_CurrentRating', 'vote_title' => 'lu_VoteTitle', 'vote_count' => 'lu_VoteCount', 'invalid_rating' => 'lu_InvalidRating', 'already_voted' => 'lu_AlreadyVoted', 'thanks_for_voting' => 'lu_ThanksForVoting', ); /** * Draws rating bar for a given category item * * @param kDBItem $object * @param bool $show_div * @param string $additional_msg * @param string $additional_style * @return string * @access public */ public function ratingBar(&$object, $show_div = true, $additional_msg = '', $additional_style = '') { // 1. user is allowed to vote by permissions $perm_prefix = $object->getUnitConfig()->getPermItemPrefix(); $static = !$this->Application->CheckPermission($perm_prefix . '.RATE', 0, $object->GetDBField('CategoryId')); // 2. user isn't voting too frequently $spam_helper =& $this->_getSpamHelper($object); $user_voted = $spam_helper->InSpamControl(); if ( !$static && !$user_voted ) { // allow to set rating when not static and user not voted before $voting_js = $this->getVotingControl($object, $additional_style); } else { $voting_js = ''; } $msg_info = Array ('text' => $additional_msg, 'class' => Array ()); if ( $static ) { $msg_info['class'][] = 'static'; } if ( $user_voted ) { $msg_info['class'][] = 'voted'; } $rater = $this->ratingBarSimple($this->getAverageRating($object), $voting_js, $msg_info, $additional_style); if ( $show_div ) { // adds div around rating stars (when drawing rating first time) $rater = '
'; } return $rater; } /** * Returns average rating * * @param kDBItem $object * @return float|int */ function getAverageRating(&$object) { $total_votes = $object->GetDBField('CachedVotesQty'); $total_rating = $object->GetDBField('CachedRating') * $total_votes; return $total_votes ? $total_rating / $total_votes : 0; } /** * Draws rating bar for a given category item * * @param float $average_rating * @param string $voting_js * @param Array $msg_info * @param string $additional_style * @return string * @access public */ public function ratingBarSimple($average_rating, $voting_js = '', $msg_info = null, $additional_style = '') { if ( !isset($msg_info) || !is_array($msg_info) ) { $msg_info = Array ('text' => '', 'class' => Array ()); } $unit_selected_width = $additional_style ? $this->ratingSmallUnitWidth : $this->ratingUnitWidth; $rating_width = $average_rating ? @number_format($average_rating, 2) * $unit_selected_width : 0; $rating2 = $average_rating ? @number_format($average_rating, 2) : 0; $current_rating_text = $this->_replaceInPhrase('current_rating', Array ('' . $rating2 . '', $this->ratingMaximal)); $rater = ' '; // this part is disabled for now, will be addressed once properly review /*$rating1 = $average_rating ? @number_format($average_rating, 1) : 0; $rater .= '' . $this->_replaceInPhrase('vote_title', Array ('' . $rating1 . '', $this->ratingMaximal)) . ' (' . $this->_replaceInPhrase('vote_count', Array ($total_votes)) . ')
';*/ if ( $voting_js ) { $rater .= ' ' . $msg_info['text'] . ''; } else { // adds div around rating stars (when drawing rating first time) $rater = ' '; } return $rater; } /** * Returns control, used to vote on a given $object * * @param kDBItem $object * @param string $additional_style * @return string */ function getVotingControl(&$object, $additional_style = '') { $ret = ''; for ($i = 1; $i <= $this->ratingMaximal; $i++) { $ret .= '