<?php
#********************************************************************
#* Virtuemart Stats module:
#* @author		Joomill.nl <info@joomill.nl>
#* @link		http://www.joomill.nl
#* @copyright 	Copyright (C) 2011 Joomill.nl  
#* @license 	http://www.gnu.org/copyleft/gpl.html GNU/GPL 
#* 
#* Virtuemart Stats module is free software: you can redistribute it  
#* and/or modify it under the terms of the GNU General Public License 
#* as published by the Free Software Foundation, either version 3 of 
#* the License, or(at your option) any later version.
#*
#* Virtuemart Stats module is distributed in the hope that it will be 
#* useful, but WITHOUT ANY WARRANTY; without even the implied 
#* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
#* See the GNU General Public License for more details.
#*
#* You should have received a copy of the GNU General Public License
#* along with Virtuemart Stats module.
#* If not, see <http://www.gnu.org/licenses/>.
#* 
#*******************************************************************
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' ); 

class modStatsHelper
{
	
	// get Categories
	static function getCategories($params)
	{
		$db		= JFactory::getDbo();
		$query	= $db->getQuery(true);
		$query->select('COUNT(virtuemart_category_id) AS count_items');
		$query->from('#__virtuemart_categories');
		$query->where('published = true');
        $db->setQuery($query);
		$categories = $db->loadResult();
		return $categories;
	}

	// get Products
	static function getProducts($params)
	{
		$db		= JFactory::getDbo();
		$query	= $db->getQuery(true);
		$query->select('COUNT(virtuemart_product_id) AS count_items');
		$query->from('#__virtuemart_products');
		$query->where('published = true');
        $db->setQuery($query);
		$products = $db->loadResult();
		return $products;
	}
	
	// get Stock
	static function getStock($params)
	{
		$db		= JFactory::getDbo();
		$query	= $db->getQuery(true);
		$query->select('SUM(product_in_stock) AS count_hits');
		$query->from('#__virtuemart_products');
        $db->setQuery($query);
		$stock = $db->loadResult();
		return $stock;
	}
	// get Customers
	static function getCustomers($params)
	{
		$db		= JFactory::getDbo();
		$query	= $db->getQuery(true);
		$query->select('COUNT(virtuemart_user_id) AS count_items');
		$query->from('#__virtuemart_vmusers');
        $db->setQuery($query);
		$customers = $db->loadResult();
		return $customers;
	}
				
	// get Orders
	static function getOrders($params)
	{
		$db		= JFactory::getDbo();
		$query	= $db->getQuery(true);
		$query->select('COUNT(virtuemart_order_id) AS count_items');
		$query->from('#__virtuemart_orders');
        $db->setQuery($query);
		$orders = $db->loadResult();
		return $orders;
	}
	
	// get Reviews
	static function getReviews($params)
	{
		$db		= JFactory::getDbo();
		$query	= $db->getQuery(true);
		$query->select('COUNT(virtuemart_rating_review_id) AS count_items');
		$query->from('#__virtuemart_rating_reviews');
		$query->where('published = true');
        $db->setQuery($query);
		$reviews = $db->loadResult();
		return $reviews;
	}
	
	// get Ratings
	static function getRatings($params)
	{
		$db		= JFactory::getDbo();
		$query	= $db->getQuery(true);
		$query->select('COUNT(virtuemart_rating_vote_id) AS count_items');
		$query->from('#__virtuemart_rating_votes');
        $db->setQuery($query);
		$ratings = $db->loadResult();
		return $ratings;
	}
	
}