vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Posts Per Week Statistic (https://vborg.vbsupport.ru/showthread.php?t=321086)

Chris.08i 12-14-2015 05:05 AM

Posts Per Week Statistic
 
Hello,

It's me again - so I'm looking to either create a plugin, or use whatever variables that are already available to somehow come up with a way to figure out a users post per week statistic.

I am not really sure how to go about this.

Any tips to point me in the right direction would be great.

MarkFL 12-14-2015 01:43 PM

If you are wanting to display this statistic on a user's profile page, then you could create a plugin as follows:

Product: vBulletin (or whatever product you wish this to be a part of)

Hook Location: member_build_blocks_start

Title: Compute Posts Per Week

Execution Order: 5

Plugin PHP Code:

PHP Code:

$prepared['postsperweek'] = number_format($userinfo['posts']/((TIMENOW $userinfo['joindate'])/(7*86400)), 2); 

Plugin is Active: Yes

In the PHP Plugin Code, we are creating the number as part of the $prepared array since it is already registered there, and then using the number_format function to round it off to 2 decimal places to match the posts per day.

Then, edit your "memberinfo_block_statistics" template by locating the code:

HTML Code:

        <dl class="blockrow stats">
                <dt>{vb:rawphrase posts_per_day}</dt>
                <dd> {vb:raw prepared.postsperday}</dd>
        </dl>

And below it add:

HTML Code:

        <dl class="blockrow stats">
                <dt>Posts Per Week</dt>
                <dd> {vb:raw prepared.postsperweek}</dd>
        </dl>


Chris.08i 12-15-2015 03:59 AM

Thanks again Mark. I actually have another question, but I will create another thread.

For this though - I actually wanted to calculate it on a weekly basis.

I made a new column in my user table, and added a hook to newpost_complete which +1 to the count. I then added a cron job to reset the count to 0 each week (based off of there having been activity in the account in the last week to cut down on database writes)

MarkFL 12-15-2015 04:16 AM

If you want a query that returns the number of posts made by a particular user during the last week, you could use:

PHP Code:

$posts_this_week $vbulletin->db->query_first("
    SELECT COUNT(*) AS post_count
    FROM " 
TABLE_PREFIX "post AS post
    WHERE userid = " 
$userinfo['userid'] . "
    AND dateline >= " 
. (TIMENOW 7*86400)
);

$prepared[poststhisweek] = $posts_this_week['post_count']; 

Then you could run this query once a week. If you want to run a query that counts the posts made by all users during the last week, let me know. :)


All times are GMT. The time now is 12:00 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01105 seconds
  • Memory Usage 1,726KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_html_printable
  • (2)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (4)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete