From: <dj...@us...> - 2011-12-26 22:16:52
|
Revision: 8569 http://xoops.svn.sourceforge.net/xoops/?rev=8569&view=rev Author: djculex Date: 2011-12-26 22:16:45 +0000 (Mon, 26 Dec 2011) Log Message: ----------- Adjusted get avg rating for users and Added worst rated users Modified Paths: -------------- XoopsModules/smallworld/trunk/include/functions.php XoopsModules/smallworld/trunk/language/english/main.php XoopsModules/smallworld/trunk/stats.php XoopsModules/smallworld/trunk/templates/getStat.html Modified: XoopsModules/smallworld/trunk/include/functions.php =================================================================== --- XoopsModules/smallworld/trunk/include/functions.php 2011-12-26 21:52:48 UTC (rev 8568) +++ XoopsModules/smallworld/trunk/include/functions.php 2011-12-26 22:16:45 UTC (rev 8569) @@ -494,21 +494,27 @@ return $msg; } -function SmallworldGetAvgRating($uid) { - global $xoopsDB; - $sql = " SELECT - (SELECT count(up) FROM xoops_smallworld_vote WHERE owner = '".intval($uid)."' and up = '1' GROUP BY owner) - - - (SELECT count(down) FROM xoops_smallworld_vote WHERE owner = '".intval($uid)."' and down = '1' GROUP BY owner) - AS TOTAL"; +// Find worst rated users overall +function worstratedusers() { + global $xoopsUser, $xoopsDB; + $array = array(); + $counter = 1; + $sql = "SELECT owner, ("; + $sql .= "sum( up ) - sum( down )"; + $sql .= ") AS total"; + $sql .= " FROM ".$xoopsDB->prefix('smallworld_vote').""; + $sql .= " GROUP BY owner ORDER by total ASC LIMIT 5"; $result = $xoopsDB->queryF($sql); - while ($r = $xoopsDB->fetchArray($result)) { - $avg = $r['TOTAL']; + while ($row = $xoopsDB->fetchArray($result)) { + $array[$counter]['counter'] = $counter; + $array[$counter]['img'] = smallworld_getAvatarLink ($row["owner"], Gravatar($row["owner"])); + $array[$counter]['user'] = $xoopsUser->getUnameFromId($row["owner"]); + $array[$counter]['rating'] = $row["total"]; + $array[$counter]['user_link'] = "<a href = '".XOOPS_URL."/modules/smallworld/userprofile.php?username=".$array[$counter]['user']."'>"; + $array[$counter]['user_link'] .= $array[$counter]['user']." (".$array[$counter]['rating'].")</a>"; + $counter++; } - if ($avg < 0) { $avg = "-".$avg;} - if ($avg == 0) { $avg = 0;} - if ($avg > 0) { $avg = "+".$avg;} - return $avg; + return $array; } // Find best rated users overall @@ -516,14 +522,17 @@ global $xoopsUser, $xoopsDB; $array = array(); $counter = 1; - $sql = "SELECT owner, count(*) as cnt FROM ".$xoopsDB->prefix('smallworld_vote')." where up='1' GROUP by owner ORDER BY cnt DESC limit 5"; + $sql = "SELECT owner, ("; + $sql .= "sum( up ) - sum( down )"; + $sql .= ") AS total"; + $sql .= " FROM ".$xoopsDB->prefix('smallworld_vote').""; + $sql .= " GROUP BY owner ORDER by total DESC LIMIT 5"; $result = $xoopsDB->queryF($sql); while ($row = $xoopsDB->fetchArray($result)) { $array[$counter]['counter'] = $counter; $array[$counter]['img'] = smallworld_getAvatarLink ($row["owner"], Gravatar($row["owner"])); - $array[$counter]['cnt'] = $row['cnt']; $array[$counter]['user'] = $xoopsUser->getUnameFromId($row["owner"]); - $array[$counter]['rating'] = SmallworldGetAvgRating($row["owner"]); + $array[$counter]['rating'] = $row["total"]; $array[$counter]['user_link'] = "<a href = '".XOOPS_URL."/modules/smallworld/userprofile.php?username=".$array[$counter]['user']."'>"; $array[$counter]['user_link'] .= $array[$counter]['user']." (".$array[$counter]['rating'].")</a>"; $counter++; Modified: XoopsModules/smallworld/trunk/language/english/main.php =================================================================== --- XoopsModules/smallworld/trunk/language/english/main.php 2011-12-26 21:52:48 UTC (rev 8568) +++ XoopsModules/smallworld/trunk/language/english/main.php 2011-12-26 22:16:45 UTC (rev 8569) @@ -353,6 +353,7 @@ define("_SMALLWORLD_STATS_NEWESTUSERS","Newest users"); define("_SMALLWORLD_STATS_MOSTACTUSERS","Most active users"); define("_SMALLWORLD_STATS_BESTRATEDUSERS","Best Rated users"); +define("_SMALLWORLD_STATS_WORSTRATEDUSERS","Worst rated users"); define("_SMALLWORLD_STATS_NOBDAYSTODAY","No birthdays today................"); define("_SMALLWORLD_STATS_BDAYSTODAY","Todays Birthdays"); define("_SMALLWORLD_STATS_LIKETHISMODULE","Like this module ???"); Modified: XoopsModules/smallworld/trunk/stats.php =================================================================== --- XoopsModules/smallworld/trunk/stats.php 2011-12-26 21:52:48 UTC (rev 8568) +++ XoopsModules/smallworld/trunk/stats.php 2011-12-26 22:16:45 UTC (rev 8569) @@ -27,11 +27,13 @@ $newusers = smallworld_Stats_newest (); $m_a_users = mostactiveusers_allround(); $br_users = topratedusers(); +$wo_users = worstratedusers(); $birth = smallworld_nextBirthdays (); $sp = smallworld_sp (); $tpl->assign('newusers',$newusers); $tpl->assign('mostactiveU',$m_a_users); $tpl->assign('bestratedU',$br_users); +$tpl->assign('worstratedU',$wo_users); $tpl->assign('sp',$sp); if (!empty($birth)) { Modified: XoopsModules/smallworld/trunk/templates/getStat.html =================================================================== --- XoopsModules/smallworld/trunk/templates/getStat.html 2011-12-26 21:52:48 UTC (rev 8568) +++ XoopsModules/smallworld/trunk/templates/getStat.html 2011-12-26 22:16:45 UTC (rev 8569) @@ -24,6 +24,14 @@ <{/foreach}> </li> + <li> + <span id ="smallworld_Stats_title"><{$smarty.const._SMALLWORLD_STATS_WORSTRATEDUSERS}></span> + <{foreach item=wru from=$worstratedU}> + <span id = "smallworld_stats_img"><img src="<{$wru.img}>" height="30px" width="30px" /></span> + <span id = "smallworld_stats_text"><{$wru.user_link}> </span> + <{/foreach}> + </li> + <{foreach item=bu from=$birthdays}> <{if $birthdays != 0}> <li> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |