SimplePortal

Customization => Custom Coding => Topic started by: KahneFan on February 05, 2009, 11:49:07 PM

Title: Next Level (countdown)
Post by: KahneFan on February 05, 2009, 11:49:07 PM
Would it be possible to add to the User Info block...

Posts: ###
Next Level: ###
Total Messages: ##
New Messages: ##

with the "Next Level" acting as a countdown until the next user level? This might inspire users to posts more just to hit that next level.
Title: Re: Next Level (countdown)
Post by: [SiNaN] on February 06, 2009, 03:01:02 AM
SPortal2.php

Find:

Code: [Select]
//If you install the Membercolor Link the colors will be autmaticly set.
Replace:

Code: [Select]
global $smcFunc;
$request = $smcFunc['db_query']('', '
SELECT min_posts
FROM {db_prefix}membergroups
WHERE min_posts > {int:current}
ORDER BY min_posts
LIMIT 1',
array(
'current' => $memberContext[$member_id]['posts'],
)
);
list ($next_post) = $smcFunc['db_fetch_row']($request);
$smcFunc['db_free_result']($request);

$next_post_left = $next_post - $memberContext[$member_id]['posts'];

//If you install the Membercolor Link the colors will be autmaticly set.

Then you can use $next_post_left where you want it to appear.
Title: Re: Next Level (countdown)
Post by: KahneFan on February 06, 2009, 03:05:56 AM
I apologize, I'm still learning the ins/outs of SP. In order to insert it into the User Info box as above, which file(s) would I add $next_post_left to?
Title: Re: Next Level (countdown)
Post by: [SiNaN] on February 06, 2009, 03:16:02 AM
No problems. You should use that in the same function. Like this:

SPortal2.php

Find:

Code: [Select]
<img src="' . $settings['images_url'] . '/dot.gif" alt="', $txt['sp-dot'], '" /> ', $txt['posts'], ': ',$memberContext[$member_id]['posts'],'<br />';
Replace:

Code: [Select]
<img src="' . $settings['images_url'] . '/dot.gif" alt="', $txt['sp-dot'], '" /> ', $txt['posts'], ': ',$memberContext[$member_id]['posts'],'<br />';

echo '
<img src="' . $settings['images_url'] . '/dot.gif" alt="', $txt['sp-dot'], '" /> Next Post Level: ', $next_post_left, '<br />';
Title: Re: Next Level (countdown)
Post by: KahneFan on February 06, 2009, 03:18:59 AM
Outstanding, thanks!  ;D
Title: Re: Next Level (countdown)
Post by: Smoky Blue on February 12, 2009, 04:24:23 AM
Mr. Blue is slick with the coding  :mouse:

lol nice and thanks.. might get around to trying it out  :nervous-happy:
Title: Re: Next Level (countdown)
Post by: Killer on February 17, 2009, 03:07:19 PM
Wow, this works perfectly :D

Why not just add this as an option for that block in the next update?
Title: Re: Next Level (countdown)
Post by: Sentinel [AF] on April 02, 2009, 07:11:02 AM
I had to remove the WHERE part to stop it giving me a db error.

Thing is that for members that aren't part of a post based group it shows the db default which is '-1'

Then again I've not tried it on the portal itself I'm trying the code for within posts in display.php but still same code applies pretty much.

Could you show me how I could do an if/else statement so if $post_next_level = -1 then it should use the members secondary group which by default should be post based group.

Thank you.
Title: Re: Next Level (countdown)
Post by: KahneFan on April 02, 2009, 01:16:24 PM
SiNaN, should this work with 2.2?
Title: Re: Next Level (countdown)
Post by: Sentinel [AF] on April 02, 2009, 07:41:56 PM
Try it ?

Should do no ?

The code worked on my display.template for smf2

Except it should be based on your id_post_group and not on your primary id_group which far as I can tell you need to tell the query that your id_group = id_post_group which is found in 'members' and not membergroups.

I think.

I'm not very clued up on mysql.
Giving me an headache. :P
Title: Re: Next Level (countdown)
Post by: [SiNaN] on April 03, 2009, 02:11:06 AM
For 2.2 (SMF 2.0 RC1):

SPortal2.php

Find:

Code: [Select]
$member_info['karma']['total'] = $member_info['karma']['good'] - $member_info['karma']['bad'];
Replace:

Code: [Select]
$member_info['karma']['total'] = $member_info['karma']['good'] - $member_info['karma']['bad'];

global $smcFunc;
$request = $smcFunc['db_query']('', '
SELECT min_posts
FROM {db_prefix}membergroups
WHERE min_posts > {int:current}
ORDER BY min_posts
LIMIT 1',
array(
'current' => $member_info['posts'],
)
);
list ($next_post) = $smcFunc['db_fetch_row']($request);
$smcFunc['db_free_result']($request);
$next_post_left = $next_post - $member_info['posts'];

Find:

Code: [Select]
<li>', sp_embed_image('dot'), ' <strong>', $txt['posts'], ':</strong> ', $member_info['posts'], '</li>';
Replace:

Code: [Select]
<li>', sp_embed_image('dot'), ' <strong>', $txt['posts'], ':</strong> ', $member_info['posts'], '</li>
<li>', sp_embed_image('dot'), ' <strong>Next Post Left:</strong> ', $next_post_left, '</li>';

Moving this to the Custom Coding (http://simpleportal.net/index.php?board=39.0) board as this will not be a default feature.
Title: Re: Next Level (countdown)
Post by: mrtrc266 on April 03, 2009, 02:32:45 AM
That gave me a 500 error?
Title: Re: Next Level (countdown)
Post by: [SiNaN] on April 03, 2009, 02:36:22 AM
Take the change back. That error is quite normal when you have a database error in built-in block codes. Are you using SMF 2.0 RC1?
Title: Re: Next Level (countdown)
Post by: mrtrc266 on April 03, 2009, 02:41:35 AM
I undid the change, yes I have RC1
Title: Re: Next Level (countdown)
Post by: [SiNaN] on April 03, 2009, 02:50:42 AM
Now I have SimplePortal 2.2 installed on a SMF 2.0 RC1 forum and the edit I gave above works perfectly. Would you attach your SPortal2.php file here so that I can check it?
Title: Re: Next Level (countdown)
Post by: mrtrc266 on April 03, 2009, 02:53:52 AM
Here ya go...thanks for the help
Title: Re: Next Level (countdown)
Post by: [SiNaN] on April 03, 2009, 02:56:51 AM
Here you are. Tested on my forum too.

As a note, either your editor or your FTP Client replace the line brakes in your files for some reason. I see them double in my editor.
Title: Re: Next Level (countdown)
Post by: mrtrc266 on April 03, 2009, 03:00:43 AM
Perfect! Thank you very much!

LOL Only thing is that is says..." Next Post Left: -1152" cuz I already reached the max posts. Easy enough though, just increase the next post level :D

Thanks again
Title: Re: Next Level (countdown)
Post by: [SiNaN] on April 03, 2009, 03:04:14 AM
Lol. Use this then. :D
Title: Re: Next Level (countdown)
Post by: mrtrc266 on April 03, 2009, 03:08:06 AM
There we go! Thanks a lot!
Title: Re: Next Level (countdown)
Post by: [SiNaN] on April 03, 2009, 03:08:29 AM
You're welcome!
Title: Re: Next Level (countdown)
Post by: mrtrc266 on April 03, 2009, 03:11:35 AM
Ok I lied, it's almost perfect how about saying what the next post level is? :D

I know you're busy supporting the new release but when you get a moments that would be cool.
Title: Re: Next Level (countdown)
Post by: [SiNaN] on April 03, 2009, 03:14:50 AM
Okay, I'm in a good mood today. :P
Title: Re: Next Level (countdown)
Post by: mrtrc266 on April 03, 2009, 03:17:58 AM
You are da Bomb! Thanks again!

Title: Re: Next Level (countdown)
Post by: Sentinel [AF] on April 03, 2009, 08:29:26 AM
can you tell me how I could get the info based from the users post group rather than their primary group as none post based groups are by default set at "-1".

id_post_group is found in "members" and not "membergroups"

Thank you.
Title: Re: Next Level (countdown)
Post by: [SiNaN] on April 03, 2009, 08:33:42 AM
Sorry but I couldn't get the relation between primary group, -1 and this. Could you elaborate your question?
Title: Re: Next Level (countdown)
Post by: Sentinel [AF] on April 03, 2009, 09:00:10 AM
Hmmm Ok.

In my mySQL database all members that are assigned to none post based groups like admin, global moderators, vip members and producers have "-1" as default in in membergroups min_posts but in the db in members each member also has id_post_group which is the users true post group rather then being based on membergroups id_group which is based on users primary group which in my case most members are in a none post based group called producers.

I was wondering how to make it so that it works from members id_post_group rather than their primary group id.

Thank you & sorry for the epic reply I'm not very good at explaining things.
Title: Re: Next Level (countdown)
Post by: [SiNaN] on April 03, 2009, 09:10:45 AM
So you don't want the Next Level to be calculated/displayed when user has a primary group set?
Title: Re: Next Level (countdown)
Post by: Sentinel [AF] on April 03, 2009, 09:18:37 AM
There's nothing to calculate.

I'd like it to get the users id_group based on member id_post_group

Then even if user has a none post based primary group it will still display the levels until next post based count.

I think. :P

I'm not very good with this mysql query stuff.

Taaa  :thumbsup:
Title: Re: Next Level (countdown)
Post by: [SiNaN] on April 03, 2009, 09:24:30 AM
Codes I gave gives you the count of posts needed for next level of post count based group regardless of the users' primary group status. Even if user has a non-post count based primary group, it will give the correct next level post count value.
Title: Re: Next Level (countdown)
Post by: Sentinel [AF] on April 03, 2009, 09:29:48 AM
Oh right, sorry mate.

I guess it must be my end as I was trying to apply it to display.template within threads so I guess it must be applying the same thing to each person.
Title: Re: Next Level (countdown)
Post by: [SiNaN] on April 03, 2009, 09:36:12 AM
What codes are you using there? The same won't work.
Title: Re: Next Level (countdown)
Post by: Sentinel [AF] on April 03, 2009, 09:49:40 AM
I noticed.

The other coder on my site said he would look into it tomorrow.

I was trying to make %bars using bar.gif and sums depending on what users post group is.

It works fine with the first if statement but for all the rest of the users with more than the first if statement it just displays bar at 100% and isn't going to the next elseif.

Like I said I'm not very efficient with mySQL, sorry to bother you.
Title: Re: Next Level (countdown)
Post by: Sentinel [AF] on April 03, 2009, 10:03:11 AM
I got your code to work on display.template.php
for user info on threads. :D

Now to get the graph code working.

I think I should be able to get that working now taaa.

Code: (Code I used for display.template SMF 2.04b) [Select]
      // setup next level
  global $smcFunc, $memberContext;
      $request = $smcFunc['db_query']('', '
         SELECT min_posts
         FROM {db_prefix}membergroups
         WHERE min_posts > "'.$message['member']['posts'].'"
         ORDER BY min_posts
         LIMIT 1',
         array(
         )
      );
      list ($next_post) = $smcFunc['db_fetch_row']($request);
      $smcFunc['db_free_result']($request);
      $next_post_left = $next_post - $message['member']['posts'];
 
  // show next level
  echo 'Nxt Lvl In: ', $next_post_left, ' Posts<br/>';
Title: Re: Next Level (countdown)
Post by: [SiNaN] on April 03, 2009, 10:29:45 AM
Code: [Select]
echo '<img src="', $settings['images_url'], '/bar.gif" width="', (int) (($next_post_left/$next_post) * 100), '" height="15" alt="" />';
Title: Re: Next Level (countdown)
Post by: KahneFan on April 03, 2009, 03:30:58 PM
Perfect, thanks!!
Title: Re: Next Level (countdown)
Post by: Sentinel [AF] on April 03, 2009, 08:07:12 PM
Thanks :thumbsup:

I'll try that now.
Not been having much luck at my end :P

Ok that makes go down backwards like how I started off earlier on.
I made a calculation to make it go upwards instead but the problem is that it doesn't take into account that with each level it needs to reset to 100% full or 0% depending on whether you are decreasing or increasing the bar.

So I made a few $variables to try and make it remove the previous $next_post from both the $message['member']['post's] & the $next_post total but for some reason it isn't taking them into account.

I'll figure it out though- eventually.
HaHa this php & sql stuff is complicated.
SimplePortal 2.3.8 © 2008-2024, SimplePortal