[Cpan-forum-commit] rev 127 - in trunk: . lib/CPAN templates www/img

svn at pti.co.il svn at pti.co.il
Tue Mar 22 14:10:36 IST 2005


Author: gabor
Date: 2005-03-22 14:10:36 +0200 (Tue, 22 Mar 2005)
New Revision: 127

Added:
   trunk/www/img/stars-0.0.png
   trunk/www/img/stars-0.5.png
   trunk/www/img/stars-1.0.png
   trunk/www/img/stars-1.5.png
   trunk/www/img/stars-2.0.png
   trunk/www/img/stars-2.5.png
   trunk/www/img/stars-3.0.png
   trunk/www/img/stars-3.5.png
   trunk/www/img/stars-4.0.png
   trunk/www/img/stars-4.5.png
   trunk/www/img/stars-5.0.png
Modified:
   trunk/Build.PL
   trunk/lib/CPAN/Forum.pm
   trunk/templates/links.tmpl
Log:
add the stars from cpanratings

Modified: trunk/Build.PL
===================================================================
--- trunk/Build.PL	2005-03-22 10:16:15 UTC (rev 126)
+++ trunk/Build.PL	2005-03-22 12:10:36 UTC (rev 127)
@@ -37,6 +37,7 @@
 		'Parse::RecDescent'                     => 0,
 		'Class::DBI::Plugin::AbstractCount'     => 0,
 		'Class::DBI::Plugin::Pager'             => 0,
+		'Text::CSV_XS'                          => 0,
 	},
 	build_requires => {
 		'Test::WWW::Mechanize'       => 0.02,

Modified: trunk/lib/CPAN/Forum.pm
===================================================================
--- trunk/lib/CPAN/Forum.pm	2005-03-22 10:16:15 UTC (rev 126)
+++ trunk/lib/CPAN/Forum.pm	2005-03-22 12:10:36 UTC (rev 127)
@@ -1300,6 +1300,7 @@
 	#$t->param(new_subject => _subject_escape($q->param("new_subject")));
 	$t->param(group       => $new_group) if $new_group;
 
+	$self->set_ratings($t, $new_group) if $new_group;
 	return $t->output;
 }
 
@@ -1500,9 +1501,42 @@
 #	$t->param(dashgroup => $dashgroup);
 	$t->param(title => _subject_escape($posts[0]->subject));
 
+	$self->set_ratings($t, $posts[0]->gid->name);
+
 	return $t->output;
 }
 
+sub get_rating {
+	my ($self, $dist) = @_;
+	require Text::CSV_XS;
+	my $csv    = Text::CSV_XS->new();
+	open my $fh, "../../db/cpan_ratings.csv" or return;
+	while (my $line = <$fh>) {
+		next if $line !~ /^"$dist"/;
+		last if not $csv->parse($line);
+		return $csv->fields();
+			
+	}
+	return;
+}
+
+sub set_ratings {
+	my ($self, $t, $group) = @_;
+
+	my ($distribution, $rating, $review_count) = $self->get_rating($group);
+	if (not $rating) {
+		$rating = "0.0";
+		$review_count = 0;
+	}
+	if ($rating) {
+		my $roundrating = sprintf "%1.1f", int($rating*2)/2;
+		$t->param(rating       => $rating);
+		$t->param(roundrating  => $roundrating);
+		$t->param(review_count => $review_count);
+		#warn "$rating $roundrating $review_count\n";
+	}
+}
+
 =head2 dist
 
 List last few posts belonging to this group, provides a link to post a new 
@@ -1554,6 +1588,7 @@
 			);
 	}
 
+	$self->set_ratings($t, $group);
 	my $page = $q->param('page') || 1;
 	$self->_search_results($t, {where => {gid => $gid}, page => $page});
 	$t->output;

Modified: trunk/templates/links.tmpl
===================================================================
--- trunk/templates/links.tmpl	2005-03-22 10:16:15 UTC (rev 126)
+++ trunk/templates/links.tmpl	2005-03-22 12:10:36 UTC (rev 127)
@@ -3,8 +3,11 @@
 	[<a href="http://search.cpan.org/dist/<TMPL_VAR group>">search.cpan.org</a>]
 	[<a href="http://cpan.uwinnipeg.ca/dist/<TMPL_VAR group>">Kobes search</a>]
     [<a href="http://rt.cpan.org/NoAuth/Bugs.html?Dist=<TMPL_VAR group>">View and report bugs</a>]
-	[<a href="http://cpanratings.perl.org/d/<TMPL_VAR group>">View and write ratings</a>]
+	[<a href="http://cpanratings.perl.org/d/<TMPL_VAR group>">Ratings</a>
+         <TMPL_IF rating>
+         <img src="/img/stars-<TMPL_VAR roundrating>.png" alt="<TMPL_VAR rating>"> (<TMPL_VAR review_count>)
+         </TMPL_IF>
+        ]
 	[<a href="http://testers.cpan.org/show/<TMPL_VAR group>.html">CPAN Tests results</a>]
 </div>
 
-

Added: trunk/www/img/stars-0.0.png
===================================================================
(Binary files differ)


Property changes on: trunk/www/img/stars-0.0.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: trunk/www/img/stars-0.5.png
===================================================================
(Binary files differ)


Property changes on: trunk/www/img/stars-0.5.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: trunk/www/img/stars-1.0.png
===================================================================
(Binary files differ)


Property changes on: trunk/www/img/stars-1.0.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: trunk/www/img/stars-1.5.png
===================================================================
(Binary files differ)


Property changes on: trunk/www/img/stars-1.5.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: trunk/www/img/stars-2.0.png
===================================================================
(Binary files differ)


Property changes on: trunk/www/img/stars-2.0.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: trunk/www/img/stars-2.5.png
===================================================================
(Binary files differ)


Property changes on: trunk/www/img/stars-2.5.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: trunk/www/img/stars-3.0.png
===================================================================
(Binary files differ)


Property changes on: trunk/www/img/stars-3.0.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: trunk/www/img/stars-3.5.png
===================================================================
(Binary files differ)


Property changes on: trunk/www/img/stars-3.5.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: trunk/www/img/stars-4.0.png
===================================================================
(Binary files differ)


Property changes on: trunk/www/img/stars-4.0.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: trunk/www/img/stars-4.5.png
===================================================================
(Binary files differ)


Property changes on: trunk/www/img/stars-4.5.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: trunk/www/img/stars-5.0.png
===================================================================
(Binary files differ)


Property changes on: trunk/www/img/stars-5.0.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream



More information about the Cpan-forum-commit mailing list