1
DevlshOne
Smarty Tag / PHP Question
  • 2006/11/23 15:15

  • DevlshOne

  • Just popping in

  • Posts: 56

  • Since: 2005/4/15


I'd like to modify the system_block_newusers.html template to report how many new users have registered in the past 24 hours but am not seeing how to incorporate some type of query to provide the count. Does anyone have an example of this I could pick apart?
[size=x-small]Dawn of War Planet
RTS Planet
[/size]

2
teibaz
Re: Smarty Tag / PHP Question
  • 2006/11/24 22:58

  • teibaz

  • Not too shy to talk

  • Posts: 103

  • Since: 2004/6/13


Quote:

DevlshOne wrote:
I'd like to modify the system_block_newusers.html template to report how many new users have registered in the past 24 hours but am not seeing how to incorporate some type of query to provide the count. Does anyone have an example of this I could pick apart?


Users in last 24 hours? I would do that in this way (i wrote this for function for XOOPS 2.2.4, but i believe that it's for XOOPS 2.x)

/**
 * Get user count by last login time
 *
 * @param int $hours
 * @return int
 */
function getLastLoggedUserList$hours 24 ) {

    
/**
     * XOOPS database class
     */
    
global $xoopsDB;
    
    
/**
     * Define default return value
     */
    
$count 0;
    
    
/**
     * Get time for query
     */
    
$time = ( intval$hours ) > ) ? time() - ( intval$hours ) * 3600 ) : ( time() - 24*3600 );
    
    
/**
     * SQL query
     */
    
$sql "SELECT COUNT( last_login ) AS count FROM " $xoopsDB->prefix'user_profile' ) . " WHERE last_login >= '" $time "'";
    
    
/**
     * Get results
     */
    
list( $count ) = $xoopsDB->fetchRow$xoopsDB->query$sql ) );
    
    return 
$count;
}


If you would like such function for XOOPS 2.0.x, i believe that it's enought to change your sql to this:

$sql "SELECT COUNT( last_login ) AS count FROM " $xoopsDB->prefix'users' ) . " WHERE last_login >= '" $time "'";



So, just put this function near your other functions and call it with hours as parameter.

Hope this was helpful.

3
DevlshOne
Re: Smarty Tag / PHP Question
  • 2006/11/25 1:33

  • DevlshOne

  • Just popping in

  • Posts: 56

  • Since: 2005/4/15


Thanks much for the PHP code for this, but how would I implement that within the block I mentioned?
[size=x-small]Dawn of War Planet
RTS Planet
[/size]

4
teibaz
Re: Smarty Tag / PHP Question
  • 2006/11/25 13:13

  • teibaz

  • Not too shy to talk

  • Posts: 103

  • Since: 2004/6/13


I don't know what XOOPS version do you use, but probably it's XOOPS 2.0.x so i downloaded that version :)

File: modules\system\blocks\system_blocks.php
Lines: from 267 to 289

Now there is such code:
function b_system_newmembers_show($options)
{
    
$block = array();
    
$criteria = new CriteriaCompo(new Criteria('level'0'>'));
    
$limit = (!empty($options[0])) ? $options[0] : 10;
    
$criteria->setOrder('DESC');
    
$criteria->setSort('user_regdate');
    
$criteria->setLimit($limit);
    
$member_handler =& xoops_gethandler('member');
    
$newmembers $member_handler->getUsers($criteria);
    
$count count($newmembers);
    for (
$i 0$i $count$i++) {
        if ( 
$options[1] == ) {
            
$block['users'][$i]['avatar'] = $newmembers[$i]->getVar('user_avatar') != 'blank.gif' XOOPS_UPLOAD_URL.'/'.$newmembers[$i]->getVar('user_avatar') : '';
        } else {
            
$block['users'][$i]['avatar'] = '';
        }
        
$block['users'][$i]['id'] = $newmembers[$i]->getVar('uid');
        
$block['users'][$i]['name'] = $newmembers[$i]->getVar('uname');
        
$block['users'][$i]['joindate'] = formatTimestamp($newmembers[$i]->getVar('user_regdate'), 's');
    }
    return 
$block;
}


You should change this function into:
function b_system_newmembers_show$options ) {

    
/**
     * XOOPS database object
     */
    
$xoopsDB =& Database::getInstance();
    
    
/**
     * Old block
     */
    
$block = array();
    
$criteria = new CriteriaCompo(new Criteria('level'0'>'));
    
$limit = (!empty($options[0])) ? $options[0] : 10;
    
$criteria->setOrder('DESC');
    
$criteria->setSort('user_regdate');
    
$criteria->setLimit($limit);
    
$member_handler =& xoops_gethandler('member');
    
$newmembers $member_handler->getUsers($criteria);
    
$count count($newmembers);
    for (
$i 0$i $count$i++) {
        if ( 
$options[1] == ) {
            
$block['users'][$i]['avatar'] = $newmembers[$i]->getVar('user_avatar') != 'blank.gif' XOOPS_UPLOAD_URL.'/'.$newmembers[$i]->getVar('user_avatar') : '';
        } else {
            
$block['users'][$i]['avatar'] = '';
        }
        
$block['users'][$i]['id'] = $newmembers[$i]->getVar('uid');
        
$block['users'][$i]['name'] = $newmembers[$i]->getVar('uname');
        
$block['users'][$i]['joindate'] = formatTimestamp($newmembers[$i]->getVar('user_regdate'), 's');
    }
    
    
/**
     * Get time for query (we use here 24hours)
     */
    
$time time() - 24*3600;
    
    
/**
     * SQL query
     */
    
$sql "SELECT COUNT( last_login ) AS count FROM " $xoopsDB->prefix'user_profile' ) . " WHERE last_login >= '" $time "'";
    
    
/**
     * Get results
     */
    
list( $count ) = $xoopsDB->fetchRow$xoopsDB->query$sql ) );
    
    
/**
     * Assign results to return variable
     */
    
$block['users_in_last_24_hours'] = intval$count );
    
    return 
$block;
}


And now in your template (modules\system\templates\blocks\system_block_newusers.html) you have a new variable <{$block.users_in_last_24_hours}> and you can put it anywhere you like.


P.S.
Sorry, but i was too lazy to test this function :) i believe that it works, but i cant assure you

Good luck,
teibaz

5
DevlshOne
Re: Smarty Tag / PHP Question
  • 2006/11/26 15:25

  • DevlshOne

  • Just popping in

  • Posts: 56

  • Since: 2005/4/15


Works perfectly, thanks. And now I have an idea how to get PHP variables to work in the blocks.
[size=x-small]Dawn of War Planet
RTS Planet
[/size]

6
teibaz
Re: Smarty Tag / PHP Question
  • 2006/11/26 16:54

  • teibaz

  • Not too shy to talk

  • Posts: 103

  • Since: 2004/6/13


Just remember that if you hack smth from 'system' directory like this time - be careful with XOOPS upgrade later.

Login

Who's Online

393 user(s) are online (296 user(s) are browsing Support Forums)


Members: 0


Guests: 393


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