From fd214fdcb78a8e5a23462b9206f35f707bb19ba7 Mon Sep 17 00:00:00 2001 From: Paul Arthur Date: Wed, 23 Jan 2013 11:32:24 -0500 Subject: Mess around with ratings Drop the public variables from the rating class; everyone should use the getters. Add the ability for themes and applications to distinguish between a user's actual rating and the global average rating; in the web interface the average shows up if a user hasn't rated something but at least one other user has. --- lib/class/rating.class.php | 9 --------- lib/class/xmldata.class.php | 20 ++++++++++++-------- templates/show_object_rating.inc.php | 23 +++++++++++++++-------- 3 files changed, 27 insertions(+), 25 deletions(-) diff --git a/lib/class/rating.class.php b/lib/class/rating.class.php index 5a85c220..3b89f9c1 100644 --- a/lib/class/rating.class.php +++ b/lib/class/rating.class.php @@ -41,8 +41,6 @@ class Rating extends database_object { // Public variables public $id; // The ID of the object rated public $type; // The type of object we want - public $rating; // Integer rating - public $preciserating; // Decimal rating /** * Constructor @@ -56,13 +54,6 @@ class Rating extends database_object { $this->id = $id; $this->type = $type; - if (! $rating = $this->get_user_rating()) { - $rating = $this->get_average_rating(); - } - - $this->rating = floor($rating); - $this->preciserating = $rating; - return true; } // Constructor diff --git a/lib/class/xmldata.class.php b/lib/class/xmldata.class.php index c736569a..9b467620 100644 --- a/lib/class/xmldata.class.php +++ b/lib/class/xmldata.class.php @@ -298,8 +298,9 @@ class xmlData { $tag_string . "\t$artist->albums\n" . "\t$artist->songs\n" . - "\t" . $rating->preciserating . "\n" . - "\t" . $rating->rating . "\n" . + "\t" . $rating->get_user_rating() . "\n" . + "\t" . $rating->get_user_rating() . "\n" . + "\t" . $rating->get_average_rating() . "\n" . "\n"; } // end foreach artists @@ -350,8 +351,9 @@ class xmlData { "\t$album->disk\n" . self::tags_string($album->tags) . "\t\n" . - "\t" . $rating->preciserating . "\n" . - "\t" . $rating->rating . "\n" . + "\t" . $rating->get_user_rating() . "\n" . + "\t" . $rating->get_user_rating() . "\n" . + "\t" . $rating->get_average_rating() . "\n" . "\n"; } // end foreach @@ -448,8 +450,9 @@ class xmlData { "\t$song->album_mbid\n". "\t$song->artist_mbid\n". "\t\n" . - "\t" . $rating->preciserating . "\n" . - "\t" . $rating->rating . "\n" . + "\t" . $rating->get_user_rating() . "\n" . + "\t" . $rating->get_user_rating() . "\n" . + "\t" . $rating->get_average_rating() . "\n" . "\n"; } // end foreach @@ -541,8 +544,9 @@ class xmlData { "\tid) . "]]>\n" . "\t$song->size\n" . "\t\n" . - "\t" . $rating->preciserating . "\n" . - "\t" . $rating->rating . "\n" . + "\t" . $rating->get_user_rating() . "\n" . + "\t" . $rating->get_user_rating() . "\n" . + "\t" . $rating->get_average_rating() . "\n" . "\t" . $democratic->get_vote($row_id) . "\n" . "\n"; diff --git a/templates/show_object_rating.inc.php b/templates/show_object_rating.inc.php index 8fa40fac..0feefd4d 100644 --- a/templates/show_object_rating.inc.php +++ b/templates/show_object_rating.inc.php @@ -29,31 +29,38 @@ /* Create some variables we are going to need */ $web_path = Config::get('web_path'); $base_url = '?action=set_rating&rating_type=' . $rating->type . '&object_id=' . $rating->id; +$othering = false; +$rate = $rating->get_user_rating(); +if (!$rate) { + $rate = $rating->get_average_rating(); + $othering = true; +} ?> -
+
    20% per star) - $width = $rating->preciserating*20; + $width = $rate * 20; if ($width < 0) $width = 0; //set the current rating background - echo "
  • " . T_('Current rating: '); - if ($rating->rating <= 0) { + echo '
  • '; + echo T_('Current rating: '); + if ($rate <= 0) { echo T_('not rated yet') . "
  • \n"; } - else printf(T_('%s of 5'), $rating->preciserating); echo "\n"; + else printf(T_('%s of 5'), $rate); echo "\n"; - for ($i=1; $i<6; $i++) + for ($i = 1; $i < 6; $i++) { ?>
  • - id,'','star'.$i); ?> + id, '', 'star' . $i); ?>
- id,'','star0'); ?> + id, '', 'star0'); ?>
-- cgit