1
jfebus
Post Count Synch for all Users
  • 2004/9/14 17:01

  • jfebus

  • Just popping in

  • Posts: 97

  • Since: 2004/9/1 1


Hi All,

After importing into the newbb forum the data from another forum I was in need for a All Users Postr Count Synch.

I made the following changes to \modules\system\admin\users\users.php

In function modifyUser($user) after:
echo "admin.php" method="post">n";
        echo 
"hidden" name="id" value="".$user->getVar("uid")."">";
        echo 
"hidden" name="type" value="user">n";
        echo 
"hidden" name="fct" value="users">n";
        echo 
"hidden" name="op" value="synchronize">n";
        echo 
"submit" value=""._AM_SYNCHRONIZE."">n";
        echo 
"n";


Add :
echo "admin.php" method="post">n";
        echo 
"hidden" name="id" value="".$user->getVar("uid")."">";
        echo 
"hidden" name="type" value="all users">n";
        echo 
"hidden" name="fct" value="users">n";
        echo 
"hidden" name="op" value="synchronize">n";
        echo 
"submit" value="Synchronize  All Users">n";
        echo 
"n";

This will add a Synchronize All Users button

Create a new function:
function mysynchronize($id)
{
    global 
$xoopsDB;
    
// Array of tables from which to count 'posts'
    
$tables = array();
    
// Count comments (approved only: com_status == XOOPS_COMMENT_ACTIVE)
    
include_once XOOPS_ROOT_PATH '/include/comment_constants.php';
    
$tables[] = array ('table_name' => 'xoopscomments',
 
'uid_column' => 'com_uid''criteria' => new Criteria('com_status'XOOPS_COMMENT_ACTIVE));
    
// Count forum posts
    
$tables[] = array ('table_name' => 'bb_posts'
'uid_column' => 'uid');

    
$total_posts 0;
    foreach (
$tables as $table) {
        
$criteria = new CriteriaCompo();
        
$criteria->add (new Criteria($table['uid_column'], $id));
        if (!empty(
$table['criteria'])) {
            
$criteria->add ($table['criteria']);
        }
              
$sql "SELECT COUNT(*) AS total 
FROM "
.$xoopsDB->prefix($table['table_name']) . ' ' $criteria->renderWhere();
              if ( 
$result $xoopsDB->query($sql) ) {
            if (
$row $xoopsDB->fetchArray($result)) {
                
$total_posts $total_posts $row['total'];
                  }
              }
    }
    
$sql "UPDATE ".$xoopsDB->prefix("users")." SET posts = $total_posts WHERE uid = $id";
    if ( !
$result $xoopsDB->query($sql) ) {
        exit(
sprintf(_AM_CNUUSER %,$id));
    }
}


and replace the delivered funtion:
function synchronize($id$type)
{
    global 
$xoopsDB;
       switch(
$type) {
       case 
'user':
        
mysynchronize($id);
           break;
       case 
'all users':
           
$sql "SELECT uid FROM ".$xoopsDB->prefix("users")."";
           if ( !
$result $xoopsDB->query($sql) ) {
               exit(
_AM_CNGUSERID);
           }
           while (
$row $xoopsDB->fetchArray($result)) {
               
$id $row['uid'];
               
mysynchronize($id);
           }
           break;
       default:
        break;
       }
       
redirect_header("admin.php?fct=users&op=modifyUser&uid=".$id,1,_AM_DBUPDATED);
    exit();
}


Enjoy it!


Login

Who's Online

302 user(s) are online (205 user(s) are browsing Support Forums)


Members: 0


Guests: 302


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits