| @@ 204-218 (lines=15) @@ | ||
| 201 | * @copyright (c) Hervé Thouzard |
|
| 202 | * @param $storyid |
|
| 203 | */ |
|
| 204 | public static function updateRating($storyid) |
|
| 205 | { |
|
| 206 | global $xoopsDB; |
|
| 207 | $query = 'SELECT rating FROM ' . $xoopsDB->prefix('news_stories_votedata') . ' WHERE storyid = ' . $storyid; |
|
| 208 | $voteresult = $xoopsDB->query($query); |
|
| 209 | $votesDB = $xoopsDB->getRowsNum($voteresult); |
|
| 210 | $totalrating = 0; |
|
| 211 | while (list($rating) = $xoopsDB->fetchRow($voteresult)) { |
|
| 212 | $totalrating += $rating; |
|
| 213 | } |
|
| 214 | $finalrating = $totalrating / $votesDB; |
|
| 215 | $finalrating = number_format($finalrating, 4); |
|
| 216 | $sql = sprintf('UPDATE %s SET rating = %u, votes = %u WHERE storyid = %u', $xoopsDB->prefix('news_stories'), $finalrating, $votesDB, $storyid); |
|
| 217 | $xoopsDB->queryF($sql); |
|
| 218 | } |
|
| 219 | ||
| 220 | /** |
|
| 221 | * Internal function for permissions |
|
| @@ 82-96 (lines=15) @@ | ||
| 79 | * @copyright (c) Hervé Thouzard |
|
| 80 | * @param $storyid |
|
| 81 | */ |
|
| 82 | function news_updaterating($storyid) |
|
| 83 | { |
|
| 84 | global $xoopsDB; |
|
| 85 | $query = 'SELECT rating FROM ' . $xoopsDB->prefix('news_stories_votedata') . ' WHERE storyid = ' . $storyid; |
|
| 86 | $voteresult = $xoopsDB->query($query); |
|
| 87 | $votesDB = $xoopsDB->getRowsNum($voteresult); |
|
| 88 | $totalrating = 0; |
|
| 89 | while (list($rating) = $xoopsDB->fetchRow($voteresult)) { |
|
| 90 | $totalrating += $rating; |
|
| 91 | } |
|
| 92 | $finalrating = $totalrating / $votesDB; |
|
| 93 | $finalrating = number_format($finalrating, 4); |
|
| 94 | $sql = sprintf('UPDATE %s SET rating = %u, votes = %u WHERE storyid = %u', $xoopsDB->prefix('news_stories'), $finalrating, $votesDB, $storyid); |
|
| 95 | $xoopsDB->queryF($sql); |
|
| 96 | } |
|
| 97 | ||
| 98 | /** |
|
| 99 | * Internal function for permissions |
|