[1.0.2] Views goal percentage messed up when goal reached

Download and support for PhpBB3 Forum Goal MOD
User avatar
doktornotor
BBCoder IV
BBCoder IV
Posts: 167
Joined: 14 Sep 2011, 23:20
BBCodes: 30
Favourite MOD: Thanks for Posts
Contact:

[1.0.2] Views goal percentage messed up when goal reached

Post by doktornotor »

Views goal 1000 | Total views 34869 | Remaining -33869 | 3,487% (red bar)

;)
Support requests via PM go straight to /dev/null!
User avatar
Stoker
Site Admin
Site Admin
Posts: 3521
Joined: 12 May 2008, 23:26
BBCodes: 239
Favourite BBCode: Anipro
Favourite MOD: PrettyPhoto
Location: Denmark
Contact:

[1.0.2] Views goal percentage messed up when goal reached

Post by Stoker »

Hmm, you should have the same files I have: http://easycaptures.com/6824988521
Board rules! No PM support
User avatar
doktornotor
BBCoder IV
BBCoder IV
Posts: 167
Joined: 14 Sep 2011, 23:20
BBCodes: 30
Favourite MOD: Thanks for Posts
Contact:

[1.0.2] Views goal percentage messed up when goal reached

Post by doktornotor »

Well, I have whatever comes with latest version. :D

Code: Select all

if (!empty($config['forum_goals_views_enable']) &&  $config['forum_goals_views'] > 0)
{
		$sql = 'SELECT SUM(topic_views) AS count
			FROM ' . TOPICS_TABLE . '
			WHERE topic_approved = 1';
		$result = $db->sql_query($sql);
		$total_views = (int) $db->sql_fetchfield('count');

$forum_goals_views_percent = ($total_views * 100) / $config['forum_goals_views'];
$forum_goals_views_rest = $config['forum_goals_views'] - $total_views; 
Note that this will go to negative figures per the last line.
Support requests via PM go straight to /dev/null!
User avatar
doktornotor
BBCoder IV
BBCoder IV
Posts: 167
Joined: 14 Sep 2011, 23:20
BBCodes: 30
Favourite MOD: Thanks for Posts
Contact:

[1.0.2] Views goal percentage messed up when goal reached

Post by doktornotor »

Important note - this bug only appears if the goal has been exceeded by huge margin of %. E.g., - Views goal 20000 | Total views 34870 | Goal reached! | 174% (green) - the bug does not appear. Remove two zeros or so from your goal and you should see it.
Support requests via PM go straight to /dev/null!
User avatar
Stoker
Site Admin
Site Admin
Posts: 3521
Joined: 12 May 2008, 23:26
BBCodes: 239
Favourite BBCode: Anipro
Favourite MOD: PrettyPhoto
Location: Denmark
Contact:

[1.0.2] Views goal percentage messed up when goal reached

Post by Stoker »

Oh, have you refreshed the templates?
We have this in the template which should prevent it:

Code: Select all

<!-- IF FORUM_VIEW_PERCENT < 100 -->{L_GOAL_REMAINING} <strong>{FORUM_VIEW_REST}</strong><!-- ELSE --><em>{L_GOAL_REMAINING_ZERO}</em> <img src="{ROOT_PATH}images/forum_goal_ok.png" width="12" height="12" alt="" /><!-- ENDIF -->
and this in the php files: 'FORUM_VIEW_PERCENT' => number_format($forum_goals_views_percent), which should prevent the "precise" number.

EDIT: your are right. I will have a look.
Board rules! No PM support
User avatar
doktornotor
BBCoder IV
BBCoder IV
Posts: 167
Joined: 14 Sep 2011, 23:20
BBCodes: 30
Favourite MOD: Thanks for Posts
Contact:

[1.0.2] Views goal percentage messed up when goal reached

Post by doktornotor »

Heh, yeah, weird one... Only discovered it by chance, since I have mistaken the views goal count for the users goal count. :)
Support requests via PM go straight to /dev/null!
User avatar
Stoker
Site Admin
Site Admin
Posts: 3521
Joined: 12 May 2008, 23:26
BBCodes: 239
Favourite BBCode: Anipro
Favourite MOD: PrettyPhoto
Location: Denmark
Contact:

[1.0.2] Views goal percentage messed up when goal reached

Post by Stoker »

The problem is number format percent: 'FORUM_VIEW_PERCENT' => $forum_goals_views_percent,
Board rules! No PM support
User avatar
Stoker
Site Admin
Site Admin
Posts: 3521
Joined: 12 May 2008, 23:26
BBCodes: 239
Favourite BBCode: Anipro
Favourite MOD: PrettyPhoto
Location: Denmark
Contact:

[1.0.2] Views goal percentage messed up when goal reached

Post by Stoker »

Please test round: 'FORUM_VIEW_PERCENT' => round($forum_goals_views_percent),
Board rules! No PM support
User avatar
doktornotor
BBCoder IV
BBCoder IV
Posts: 167
Joined: 14 Sep 2011, 23:20
BBCodes: 30
Favourite MOD: Thanks for Posts
Contact:

[1.0.2] Views goal percentage messed up when goal reached

Post by doktornotor »

OK, tried with both "normal" and extremely low/high goal numbers and seems the percentage bug is gone! 8-) :thumb:

But the negative numbers remain: Post goal 1 | Total posts 617 | Remaining -616 | 61,700% :D
Last edited by doktornotor on 03 Dec 2011, 15:56, edited 1 time in total.
Support requests via PM go straight to /dev/null!
User avatar
Stoker
Site Admin
Site Admin
Posts: 3521
Joined: 12 May 2008, 23:26
BBCodes: 239
Favourite BBCode: Anipro
Favourite MOD: PrettyPhoto
Location: Denmark
Contact:

[1.0.2] Views goal percentage messed up when goal reached

Post by Stoker »

You also have to repplace the other instances of number_format with round.
Board rules! No PM support
Locked