<?php
/**
* @package		UserPoints for Joomla 4.x
* @copyright	Copyright (C) 2015-2016. All rights reserved.
* @license		GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/

// no direct access
defined('_JEXEC') or die('Restricted access');

use BlackSheepResearch\Component\UserPoints\Site\UserPoints;
use BlackSheepResearch\Component\UserPoints\Site\Problems\SQL;

class modUserPointsOnlineUsersHelper {

	public static function getList($params) {

		$db			      = SQL::getInstance();
		$user			  = UserPoints::getUser();
		$count		      = intval($params->get('count', 5));
		$showavatar		  = intval($params->get('showavatar', 1));
		$showself			= intval($params->get('showself', 0));
		$usrname		  = trim($params->get('usrname', 'name'));
		
                $q = "SELECT a.userid, a.points, a.$usrname AS usrname, a.referreid FROM #__alpha_userpoints_combined AS a "
                    . " INNER JOIN #__session AS s ON s.userid = a.userid "
                    . " WHERE a.published='1' AND s.guest='0' AND s.client_id='0' AND s.username!='' ";
		if(!$showself) {
                    $q .= " AND a.userid != $user->id";
                }
		$q .= " ORDER BY a.points DESC, a.$usrname ASC";
		$db->setQuery($q, 0, $count);
		$rows = $db->loadObjectList();
	
		return $rows;
	
	}
}
