Notifications
Clear all

Linking up reviews received and reviews given.

18 Posts
3 Users
0 Reactions
4,659 Views
 Elle
(@jenny)
Posts: 594
Honorable Member
Topic starter
 

Thank you, Tammy!

Here is the new code in full:

# Create array
$reviewers = array();

# Pull list of received reviews
$revreceived = dbquery("SELECT count( reviewid ) AS rec, s.uid, a.penname FROM ".TABLEPREFIX."fanfiction_reviews AS r, ".TABLEPREFIX."fanfiction_stories AS s, ".TABLEPREFIX."fanfiction_authors as a, ".TABLEPREFIX."fanfiction_authorprefs as ap WHERE s.uid = a.uid AND ap.uid = a.uid AND ap.stories > 0 AND r.type = 'ST' AND r.review != 'No Review' AND r.item  = s.sid GROUP BY s.uid");

while($re = dbassoc($revreceived)) {
# print print_r($re);
# if (empty($reviewers[$re["uid"]]["penname"])) $reviewers[$re["uid"]]["penname"] = $re["penname"];
$reviewers[$re["uid"]]["penname"] = $re["penname"];
$reviewers[$re['uid']]["received"] = $re['rec'];
# $reviewers[$re['uid']]["uid"] = $re['uid'];
}

# Pull list of reviews
$reviews = dbquery("SELECT COUNT(reviewid) as reviews, a.uid, penname FROM ".TABLEPREFIX."fanfiction_reviews as r, ".TABLEPREFIX."fanfiction_authors as a, ".TABLEPREFIX."fanfiction_authorprefs as ap WHERE a.uid = r.uid AND ap.uid = a.uid AND ap.stories > 0 AND review != 'No Review' GROUP BY uid");

# Loop through written reviews
while($r = dbassoc($reviews)) {
# $reviewers[$r["uid"]]["uid"] = $r["uid"];
$reviewers[$r["uid"]]["penname"] = $r["penname"];
$reviewers[$r["uid"]]["given"] = $r["reviews"];
}

foreach ($reviewers as $k => $v) { # $k = uid $v = num?
if(empty($v["given"])) $reviewers[$k]["given"] = 0;
if(empty($v["received"])) $reviewers[$k]["received"] = 0;
$ranked[$k] = $reviewers[$k]['given'] - $reviewers[$k]['received'];
$reviewers[$k]["diff"] = $reviewers[$k]["given"]-$reviewers[$k]["received"];
}

$output .= "<h2>Review Balancing</h2>r";
$output .= "<table class="tblborder" width="80%">r";
$output .= "<tr><th>Penname</th><th>Given</th><th>Received</th><th>Difference</th></tr>r";
#ksort($reviewers);
arsort($ranked);
foreach ($ranked as $k => $v) {
$output .= "<tr".($reviewers[$k]["diff"] >= 0 ? " class="highlite"" : "").">r";
$output .= "<td><a href=""$url/viewuser.php?uid=".$k."">".$reviewers[$k"]["penname"]."</a></td>n
<td class="center">".$reviewers[$k]["given"]."</td>n
<td class="center">".$reviewers[$k]["received"]."</td>n
<td class="center">".$reviewers[$k]["diff"]."</td>r";
$output .= "</tr>r";
}
$output .= "</table>r";

There's an extra uid there... wasn't sure how to bypass that. :3 Works though: http://dramione.org/revpyramid.php πŸ˜€

(The list is of ALL authors who have received reviews. Our count is relatively small ATM. Probably won't be good for a big big archive.)

ORRRRRRRR:

<?php

$current = "revpyramidstats";

include ("header.php");

if(file_exists("$skindir/default.tpl")) $tpl = new TemplatePower( "$skindir/default.tpl" );
else $tpl = new TemplatePower(_BASEDIR."default_tpls/default.tpl");
$tpl->assignInclude( "header", "./$skindir/header.tpl" );
$tpl->assignInclude( "footer", "./$skindir/footer.tpl" );
//let TemplatePower do its thing, parsing etc.
$tpl->prepare();

include("includes/pagesetup.php");
# Create array
$reviewers = array();

# Pull list of received reviews
$revreceived = dbquery("SELECT count( reviewid ) AS rec, s.uid, a.penname FROM ".TABLEPREFIX."fanfiction_reviews AS r, ".TABLEPREFIX."fanfiction_stories AS s, ".TABLEPREFIX."fanfiction_authors as a, ".TABLEPREFIX."fanfiction_authorprefs as ap WHERE s.uid = a.uid AND ap.uid = a.uid AND ap.stories > 0 AND r.type = 'ST' AND r.review != 'No Review' AND r.item  = s.sid GROUP BY s.uid");

while($re = dbassoc($revreceived)) {
$reviewers[$re["uid"]]["penname"] = $re["penname"];
$reviewers[$re['uid']]["received"] = $re['rec'];
$reviewers[$re['uid']]["uid"] = $re['uid'];
}

# Pull list of reviews
$reviews = dbquery("SELECT COUNT(reviewid) as reviews, a.uid, penname FROM ".TABLEPREFIX."fanfiction_reviews as r, ".TABLEPREFIX."fanfiction_authors as a, ".TABLEPREFIX."fanfiction_authorprefs as ap WHERE a.uid = r.uid AND ap.uid = a.uid AND ap.stories > 0 AND review != 'No Review' GROUP BY uid");

# Loop through written reviews
while($r = dbassoc($reviews)) {
$reviewers[$r["uid"]]["uid"] = $r["uid"];
$reviewers[$r["uid"]]["penname"] = $r["penname"];
$reviewers[$r["uid"]]["given"] = $r["reviews"];
}

foreach ($reviewers as $k => $v) { # $k = uid $v = num?
if(empty($v["given"])) $reviewers[$k]["given"] = 0;
if(empty($v["received"])) $reviewers[$k]["received"] = 0;
$ranked[$k] = $reviewers[$k]['given'] - $reviewers[$k]['received'];
$reviewers[$k]["diff"] = $reviewers[$k]["given"]-$reviewers[$k]["received"];
}

$output .= "<h2>Review Balancing</h2>r";
$output .= "<p>This table shows the top thirty authors.</p>";
$output .= "<table class="tblborder" width="80%">r";
$output .= "<tr><th>Rank</th><th>Penname</th><th>Given</th><th>Received</th><th>Difference</th></tr>r";

arsort($ranked);

$x = 1;

function ordinal($num) {
$last=substr($num,-1);
if($last>3 or $last==0) $ext='th';
else if($last==3) $ext='rd';
else if($last==2) $ext='nd';
else $ext='st';
return $num.$ext;
}

$ranked = array_slice($ranked, 0, 30, true);

foreach ($ranked as $k => $v) {
$output .= "<tr".($reviewers[$k]["diff"] >= 0 ? " class="highlite"" : "").">r";
$output .= "<td>".ordinal($x)."</td><td><a href=""$url/viewuser.php?uid=".$k."">".$reviewers[$k"]["penname"]."</a></td>n
<td class="center">".$reviewers[$k]["given"]."</td>n
<td class="center">".$reviewers[$k]["received"]."</td>n
<td class="center">".$reviewers[$k]["diff"]."</td>r";
$output .= "</tr>r";
$x++;
}
$output .= "</table>r";
?>

... which "ranks" and only shows the top thirty.


archive: dramione.org
site: accio.nu

Available for skin/mod commission! πŸ™‚

 
Posted : 18/02/2010 10:48 am
(@tammy)
Posts: 2577
Member Moderator
 

You know what might be neat is if you put a graphic in the profile showing their "balance".  Something like:

Given    =====|            Received

if they've given more than received or...

Given                |====    Received

if they've received more than they've given.

You could use the same technique as the poll block.


 
Posted : 18/02/2010 6:10 pm
 Elle
(@jenny)
Posts: 594
Honorable Member
Topic starter
 

Good idea. I'm trying it out now. (You can see my failing progress, haha.)


archive: dramione.org
site: accio.nu

Available for skin/mod commission! πŸ™‚

 
Posted : 19/02/2010 1:43 pm
Page 2 / 2
Share: