<?php
/*
 * @component UserPoints
 * @copyright Copyright (C) 2015-2022 Bernard Gilly - Adrien Roussel - Martin Brampton
 * @license : GNU/GPL
 * @Website : https://remository.com
 */
namespace BlackSheepResearch\Component\UserPoints\Administrator\Models;

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die();

use Joomla\CMS\Factory;
use BlackSheepResearch\Component\UserPoints\Administrator\Model;
use BlackSheepResearch\Component\UserPoints\Site\Problems\SQL;

class Exports extends Model {
	
	function __construct(){
		parent::__construct();
	}
	

	function _export_most_active_users() 
	{
		
		$query = "SELECT * FROM #__alpha_userpoints_combined ORDER BY points DESC, name ASC";
		$result = $this->_getList($query, 0, 50);
		
		return $result;
		
	}	
	
	function _export_emails() 
	{
	
		$db = SQL::getInstance();	
		$query = "SELECT datareference FROM #__alpha_userpoints_details WHERE datareference!='' AND enabled='1'";
		$db->setQuery( $query );
		$result = $db->loadObjectList();
		
		return $result;
	}	
	
	function _exportallactivitiesuser() 
	{
		$db = SQL::getInstance();	
		$referrerid = Factory::getApplication()->input->get( 'c2id', '', 'username' );		
		$query = "SELECT * FROM #__alpha_userpoints_details_combined "
                    ." WHERE referreid={$db->quote($referrerid)} AND enabled != 0 ORDER BY insert_date DESC";
		$db->setQuery( $query );
		$result = $db->loadObjectList();
		
		return $result;
	}
	
	function _exportallactivitiesallusers() 
	{
		$db = SQL::getInstance();	
		$query = "SELECT * FROM #__alpha_userpoints_details_combined "
                    ." WHERE enabled != 0 ORDER BY insert_date DESC";
		$db->setQuery( $query );
		$result = $db->loadObjectList();
		
		return $result;
	}	
	
	function _export_coupons ()
	{	
		$db = SQL::getInstance();	
		$query = "SELECT * FROM #__alpha_userpoints_coupons";
		$db->setQuery( $query );
		$result = $db->loadObjectList();
				
		return $result;	
	}
	
}
