ElkArte Community

General => Showcase => Topic started by: Ant59 on April 02, 2015, 06:17:43 am

Title: Post Group Progress Bar on Profile
Post by: Ant59 on April 02, 2015, 06:17:43 am
This is part of a WIP overhaul for the Elkarte profile page on the Xydre theme, but I wanted to share my code in case anyone else wants to implement a progress bar like this:

(http://i.imgur.com/ZSp8xEb.png)

Here's the snippet, database code and HTML (The HTML isn't pretty - it's quite fragmented at this point in the function):

Code: [Select]
/* TODO: Move this to addon */
$db = database();

$request = $db->query('', '
SELECT mg.group_name, mg.min_posts
FROM {db_prefix}membergroups AS mg
WHERE mg.min_posts = (
SELECT MAX(mg.min_posts)
                FROM {db_prefix}membergroups AS mg
WHERE mg.min_posts < {raw:min_posts})
OR mg.min_posts = (
SELECT MIN(mg.min_posts)
                FROM {db_prefix}membergroups AS mg
WHERE mg.min_posts > {raw:min_posts})
ORDER BY mg.min_posts ASC',
array(
'min_posts' => $context['member']['posts'],
)
);

$min_row = $db->fetch_assoc($request);
$max_row = $db->fetch_assoc($request);

/*print_r($min_row);
print_r($max_row);*/

$percentage_progress = $context['member']['posts'] / ($max_row['min_posts'] - $min_row['min_posts']) * 100;

echo '
</div>
</div>
<div class="row">
<div class="large-12 columns">
<div class="panel">
<div class="clearfix">
<div class="left text-left">', $min_row['group_name'], '<br />', $min_row['min_posts'], '</div>
<div class="right text-right">', $max_row['group_name'], '<br />', $max_row['min_posts'], '</div>
</div>
<div class="progress">
<div class="meter" style="width: ', $percentage_progress, '%"></div>
</div>
</div>
</div>';
Title: Re: Post Group Progress Bar on Profile
Post by: emanuele on April 02, 2015, 07:59:38 am
Very, very nice! :D
Title: Re: Post Group Progress Bar on Profile
Post by: Mstcool on April 12, 2015, 06:58:06 pm
idk if this is added but when you hover over the progress bar, it should say the amount of post you currently have. :D
Title: Re: Post Group Progress Bar on Profile
Post by: Jorin on April 21, 2015, 06:48:13 am
Plus show the needed posts for the next level.  ;)