View Full Version : Posts Per Week Statistic
Chris.08i
12-14-2015, 05:05 AM
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:
$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:
<dl class="blockrow stats">
<dt>{vb:rawphrase posts_per_day}</dt>
<dd> {vb:raw prepared.postsperday}</dd>
</dl>
And below it add:
<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:
$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. :)
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.