Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F1069822
in-portal
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sun, Jul 20, 9:04 AM
Size
7 KB
Mime Type
text/x-diff
Expires
Tue, Jul 22, 9:04 AM (2 h, 18 m)
Engine
blob
Format
Raw Data
Handle
692713
Attached To
rINP In-Portal
in-portal
View Options
Index: branches/RC/core/units/general/helpers/rating_helper.php
===================================================================
--- branches/RC/core/units/general/helpers/rating_helper.php (revision 11089)
+++ branches/RC/core/units/general/helpers/rating_helper.php (revision 11090)
@@ -1,165 +1,169 @@
<?php
class RatingHelper extends kHelper {
/**
* One star width/height in pixels
*
* @var int
*/
- var $ratingUnitWidth = 30;
+ var $ratingUnitWidth = 25;
/**
* Maximal star count
*
* @var int
*/
var $ratingMaximal = 5;
var $_phrases = Array (
'current_rating' => '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
* @return string
*/
function ratingBar(&$object, $show_div = true, $additional_msg = '')
{
$perm_prefix = $this->Application->getUnitOption($object->Prefix, 'PermItemPrefix');
$static = !$this->Application->CheckPermission($perm_prefix . '.RATE', 0, $object->GetDBField('CategoryId'));
$total_votes = $object->GetDBField('CachedVotesQty');
$total_rating = $object->GetDBField('CachedRating') * $total_votes;
$spam_helper =& $this->Application->recallObject('SpamHelper');
/* @var $spam_helper SpamHelper */
$config_mapping = $this->Application->getUnitOption($object->Prefix, 'ConfigMapping');
$review_settings = $config_mapping['RatingDelayValue'].':'.$config_mapping['RatingDelayInterval'];
$spam_helper->InitHelper($object->GetDBField('ResourceId'), 'Rating', $review_settings);
$user_voted = $spam_helper->InSpamControl();
// now draw the rating bar
$rating_width = $total_votes ? @number_format($total_rating / $total_votes, 2) * $this->ratingUnitWidth : 0;
$rating1 = $total_votes ? @number_format($total_rating / $total_votes, 1) : 0;
$rating2 = $total_votes ? @number_format($total_rating / $total_votes, 2) : 0;
- $rater = ' <ul class="unit-rating" style="width: ' . $this->ratingUnitWidth * $this->ratingMaximal . 'px;">
- <li class="current-rating" style="width: ' . $rating_width . 'px;">' . $this->_replaceInPhrase('current_rating', Array ('<strong>' . $rating2 . '</strong>', $this->ratingMaximal)) . '</li>';
+
+ $rater = ' <ul class="star-rating" style="width: ' . $this->ratingUnitWidth * $this->ratingMaximal . 'px;">
+ <li class="current-rating" style="width: ' . $rating_width . 'px;">' . $this->_replaceInPhrase('current_rating', Array ('<strong>' . $rating2 . '</strong>', $this->ratingMaximal)) . '</li>'."\n";;
if (!$static && !$user_voted) {
// allow to set rating when not static and user not voted before
for ($ncount = 1; $ncount <= $this->ratingMaximal; $ncount++) {
- $rater .= '<li><a href="#vote-' . $ncount . '" onclick="aRatingManager.makeVote(' . $ncount . ', \'' . $object->Prefix . '\', ' . $object->GetID() . '); return false;" title="' . $this->_replaceInPhrase('vote_title', Array ($ncount, $this->ratingMaximal)) . '" class="r' . $ncount . '-unit rater" rel="nofollow">' . $ncount . '</a></li>';
+ $rater .= '<li><a href="#vote-' . $ncount . '" onclick="aRatingManager.makeVote(' . $ncount . ', \'' . $object->Prefix . '\', ' . $object->GetID() . '); return false;" title="' . $this->_replaceInPhrase('vote_title', Array ($ncount, $this->ratingMaximal)) . '" class="r' . $ncount . '-unit rater" rel="nofollow">' . $ncount . '</a></li>'."\n";
}
}
$msg_class = Array ();
if ($static) {
$msg_class[] = 'static';
}
if ($user_voted) {
$msg_class[] = 'voted';
}
- $rater .= ' </ul>
- <p class="' . implode(' ', $msg_class) . '">' .
- $this->_replaceInPhrase('vote_title', Array('<strong>'.$rating1.'</strong>', $this->ratingMaximal)) . ' ('. $this->_replaceInPhrase('vote_count', Array($total_votes)) . ') ' . $additional_msg . '
- </p>';
+ $rater .= ' </ul></span>';
+
+ // this part is disabled for now, will be addressed once properly review
+// $rater .= ' <p class="' . implode(' ', $msg_class) . '">' .
+ $this->_replaceInPhrase('vote_title', Array('<strong>'.$rating1.'</strong>', $this->ratingMaximal)) . ' ('. $this->_replaceInPhrase('vote_count', Array($total_votes)) . ') </p>';
+
+ $rater .= ' <span class="' . implode(' ', $msg_class) . '">'.$additional_msg.'<span>';
if ($show_div) {
// adds div around rating stars (when drawing rating first time)
- $rater = '<div class="ratingblock"><div id="page_rating_' . $object->GetID() . '">' . $rater . '</div></div>';
+ $rater = '<div class="inline-rating" id="page_rating_' . $object->GetID() . '">' . $rater . '</div>';
}
return $rater;
}
/**
* Saves user's vote, when allowed
*
* @param kDBItem $object
* @return string
*/
function makeVote(&$object)
{
$spam_helper =& $this->Application->recallObject('SpamHelper');
/* @var $spam_helper SpamHelper */
$config_mapping = $this->Application->getUnitOption($object->Prefix, 'ConfigMapping');
$review_settings = $config_mapping['RatingDelayValue'].':'.$config_mapping['RatingDelayInterval'];
$spam_helper->InitHelper($object->GetDBField('ResourceId'), 'Rating', $review_settings);
if (!$object->isLoaded() || $spam_helper->InSpamControl()) {
return '@err:' . $this->_replaceInPhrase('already_voted');
}
$perm_prefix = $this->Application->getUnitOption($object->Prefix, 'PermItemPrefix');
$can_rate = $this->Application->CheckPermission($perm_prefix . '.RATE', 0, $object->GetDBField('CategoryId'));
$rating = (int)$this->Application->GetVar('rating'); // not numeric rating is from GoogleBot :(
if (($rating <= 0) || ($rating > $this->ratingMaximal) || !$can_rate) {
return '@err:' . $this->_replaceInPhrase('invalid_rating');
}
// save current rating
$fields_hash = Array (
'ItemId' => $object->GetID(),
'RatingValue' => $rating,
'IPAddress' => $_SERVER['REMOTE_ADDR'],
'CreatedOn' => adodb_mktime(),
);
$this->Conn->doInsert($fields_hash, TABLE_PREFIX.'ItemRating');
// recalculate average rating
$votes_count = $object->GetDBField('CachedVotesQty');
$avg_rating = $object->GetDBField('CachedRating');
$avg_rating = round((($votes_count * $avg_rating) + $rating) / ($votes_count + 1), 2);
$object->SetDBField('CachedRating', "$avg_rating");
$object->Update();
$sql = 'UPDATE '.$object->TableName.'
SET CachedVotesQty = CachedVotesQty + 1
WHERE '.$object->IDField.' = '.$object->GetID();
$this->Conn->Query($sql);
$object->SetDBField('CachedVotesQty', $object->GetDBField('CachedVotesQty') + 1); // for using in template
// prevent user from voting too quickly
$spam_helper->AddToSpamControl();
return $this->ratingBar($object, false, '<span class="thanks">' . $this->_replaceInPhrase('thanks_for_voting') . '</span>');
}
/**
* Performs sprintf on phrase translation using given variables
*
* @param string $phrase
* @param Array $arguments
* @return string
*/
function _replaceInPhrase($phrase, $arguments = Array ())
{
$value = $this->Application->Phrase($this->_phrases[$phrase]);
if ($arguments) {
return vsprintf($value, $arguments);
}
return $value;
}
}
\ No newline at end of file
Property changes on: branches/RC/core/units/general/helpers/rating_helper.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.1.2.1
\ No newline at end of property
+1.1.2.2
\ No newline at end of property
Event Timeline
Log In to Comment