<?php
/*
* @name simplerating 1.0
* Created By Chris grVulture Michaelides
* http://www.axxis.gr
* @copyright  Copyright (C) 2009,2010  AXXIS INTERNET SOLUTIONS / All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
*/
//==============================================================================
defined('_JEXEC') or die();
//==============================================================================
class SG_HELPER {
	var $cpath = '';
	var $current = '';

	  
	function ini() {
		$this->db =  JFactory::getDBO();
		return;
	}

	function getReviewList(){ //use this to limit dropdown in front menu. dropdown is just 1 level deeper then current cpath 
		global $config;
		if(!isset($this->db)) $this->ini();
		$this->limit = JRequest::getVar('limit',$config->getValue('list_limit'));
		$this->limitstart = JRequest::getVar('limitstart', 0);
		$this->where=' WHERE v.user_id=u.id';
		if(isset($this->search) && strlen($this->search)>0){
			$this->where .= " AND ( v.review_text LIKE '%".$this->search."%' OR v.id='$this->search' ) "; 
		}
		$order = JRequest::getVar('task');
		if ($order) $order = 'v.'.$order.',';
		$query = "SELECT count(*) FROM #__users u, #__simplerating_extravote v $this->where ";
		$this->db->setQuery( $query );
		$this->total = $this->db->loadResult();
		$query = "SELECT u.name, u.username, v.user_id, v.date, v.review_text, v.rating_sum, v.option, v.id, v.extra_id, v.published FROM #__simplerating_extravote v, #__users u $this->where ORDER BY $order v.date DESC";
		$this->db->setQuery( $query, $this->limitstart, $this->limit );
		$this->rows = $this->db->loadObjectList();
		if(count($this->rows)>0){
			for($j=0;$j<count($this->rows);$j++){
				$this->temp_row='';
				$this->temp_row = $this->rows[$j];
			}
		}
	} 
	
	function getReports(){ //use this to limit dropdown in front menu. dropdown is just 1 level deeper then current cpath 
		global $config;
		if(!isset($this->db)) $this->ini();
		$this->limit = JRequest::getVar('limit',$config->getValue('list_limit'));
		$this->limitstart = JRequest::getVar('limitstart', 0);
		$this->where=' WHERE r.report_user=u.id AND r.review_id=v.id AND v.published=1';
		if(isset($this->search) && strlen($this->search)>0){
			$this->where .= " AND ( v.review_text LIKE '%".$this->search."%' OR r.report_text LIKE '%".$this->search."%' OR v.id='$this->search' ) "; 
		}
		$query = "SELECT count(*) FROM #__simplerating_extravote_reports r, #__users u, #__simplerating_extravote v $this->where ";
		$this->db->setQuery( $query );
		$this->total = $this->db->loadResult();
		$query = "SELECT r.*, u.name, u.username, v.user_id, v.review_text, v.rating_sum, v.option, v.id as reviewid, v.extra_id, v.published FROM #__simplerating_extravote_reports r, #__simplerating_extravote v, #__users u $this->where ORDER BY r.date DESC";
		$this->db->setQuery( $query, $this->limitstart, $this->limit );
		$this->rows = $this->db->loadObjectList();
		if(count($this->rows)>0){
			for($j=0;$j<count($this->rows);$j++){
				$this->temp_row='';
				$this->temp_row = $this->rows[$j];
			}
		}
	} 
	
}
?>
