Hello and Happy New Year. I need some here. I have a script that pulls a count from my database to display totals by user. The time element is by:
// CONFIG: Numbers of Month to show MOST COMMENTS modules
$shown_months = array(10, 11, 12);
Now with the new year, this will pull 2012 months. Is there a way to pull the previous 2011 months in that array without rewriting the script?
Something like…
$shown_months = array(10/2011, 11/2011, 12/2011);
My php script is below…
[php]<?php
// CONFIG: Numbers of Month to show MOST COMMENTS modules
$shown_months = array(10, 11, 12);
// CONFIG: blocked users list
$blocked_users = array(
‘admin’,
);
function finduser($userid, $aUsers) {
for($i=0;$i<count($aUsers);$i++) {
if($aUsers[$i][‘userid’] == $userid) {
return i;
}
}
return -1;
}
global $_CONF;
$prefix = $_CONF[‘db’][‘prefix’];
$oSrvSec = &App::getModuleService(‘Account’, ‘Security’);
$aUser = $oSrvSec->getCurrentUserLogin();
$oTpl = &App::getTemplate();
$oTpl->assign(“prefix”, “$prefix”);
$oTpl->assign(“aUser”, “$aUser”);
$activity_pts = 10;
$u_rating = 10;
$profile_v = 10;
$referrals = 10;
// Pass to template months names
$counter = 1;
foreach ($shown_months as $month_num) {
$month_name = date(“F”, mktime(0, 0, 0, $month_num, 1, 2000));
$oTpl->assign(“month” . $counter++, $month_name);
}
$oDb = &Database::get();
// Prepare where condition for blocked users (if any)
$blocked_where = ‘’;
if (is_array($blocked_users) && count($blocked_users)) {
$blocked_where = " WHERE user NOT IN (’" . implode("’, ‘", $blocked_users) . "’)";
}
// Get stats for needed months
$counter = 1;
foreach ($shown_months as $month_num) {
$sql = “SELECT id, user, sum(cnt) AS topfirst FROM (”
."(SELECT u.id, u.user, count(vc.cm_text) AS cnt FROM " .App::getT(‘videos_comments’) ." AS vc LEFT JOIN " . App::getT(‘user’) ." AS u on vc.cm_userid = u.id WHERE YEAR(DATE(FROM_UNIXTIME(vc.cm_time))) = YEAR(CURDATE()) AND MONTH(DATE(FROM_UNIXTIME(vc.cm_time))) = $month_num GROUP BY u.id)"
." UNION ALL"
."(SELECT u.id, u.user, count(cm.text) AS cnt FROM " .App::getT(‘comments’) ." AS cm LEFT JOIN " . App::getT(‘user’) ." AS u on cm.userid = u.id WHERE YEAR(DATE(FROM_UNIXTIME(cm.time))) = YEAR(CURDATE()) AND MONTH(DATE(FROM_UNIXTIME(cm.time))) = $month_num GROUP BY u.id)"
." UNION ALL"
."(SELECT u.id, u.user, count(post.postid) AS cnt FROM " .App::getT(‘vb_post’) ." AS post LEFT JOIN " . App::getT(‘user’) ." AS u on post.username = u.user WHERE YEAR(DATE(FROM_UNIXTIME(post.dateline))) = YEAR(CURDATE()) AND MONTH(DATE(FROM_UNIXTIME(post.dateline))) = $month_num GROUP BY u.id)"
.") AS tmp "
. $blocked_where
." GROUP BY id "
." ORDER BY topfirst DESC"
." LIMIT " . $activity_pts;
$users = $oDb->getRows($sql);
// Filling in table
for ($i = count($users)+1; $i <= $activity_pts; $i++) {
$users[] = “”;
}
$oTpl->assign(“aUsersForMonth” . $counter++, $users);
}
?>[/php]