Location: PHPKode > projects > Chalange > com_chalange/helpers/query.php
<?php
/*
 * @component SQL 2 Excel Component
 * @copyright Copyright (C) Joomla-R-Us, joomla-r-us.com
 * @license http://www.gnu.org/licenses/gpl-3.0.html GNU/GPLv3
 */
 
class Sql2excelQuery
{

	function getBaseQuery($what, $extra_wheres=array(), $group_by='', $order_by='', $display_sections='', $hide_sections = '', $display_categories = '', $hide_categories = '') 
	{
		$user 		=& JFactory::getUser();
		$aid 		= $user->get('aid', 0);	

		if ( $order_by != '' )
			$order_by = 'ORDER BY ' . $order_by;
			

		if ( $display_sections != '' ) {
			$section_ids_where = " AND a.section IN (".$display_sections.")";
		} else {
			$section_ids_where = '';
		}

		if ( $hide_sections != '' ) {
			$section_ids_not_where = " AND a.section NOT IN (".$hide_sections.")";
		} else {
			$section_ids_not_where = '';
		}

		if ( $display_categories != '' ) {
			$category_ids_where = " AND a.category IN (".$display_categories.")";
		} else {
			$category_ids_where = '';
		}

		if ( $hide_categories != '' ) {
			$category_ids_not_where = " AND a.category NOT IN (".$hide_categories.")";
		} else {
			$category_ids_not_where = '';
		}


		if ( is_array($extra_wheres) ) {
			$wheres = $extra_wheres;		
		} else {
			$wheres = array();
		}
		
		$wheres[] = " a.id = b.wb_id ";
		$wheres[] = " b.ws_id = c.id ";
		$wheres[] = " a.published=1 ";
		$wheres[] = " c.published=1 ";
		$wheres[] = " d.published=1 ";
		$wheres[] = " a.section=d.id ";
		$wheres[] = " a.category=e.id ";
		$wheres[] = " e.published=1 ";

		if ($aid !== null) {
			$wheres[] = "a.access <= " . (int) $aid;
			$wheres[] = "c.access <= " . (int) $aid;
			$wheres[] = "d.access <= " . (int) $aid;
			$wheres[] = "e.access <= " . (int) $aid;
		}
		

		$query = " SELECT " . $what .
	 		 " FROM #__sql2excel_workbooks AS a, #__sql2excel_worksheet2book AS b, #__sql2excel_worksheets AS c, #__sql2excel_sections AS d, #__sql2excel_categories AS e " .
			 " WHERE " . implode( " AND ", $wheres ) .
	 		 $section_ids_where . $section_ids_not_where .
	 		 $category_ids_where . $category_ids_not_where .
	 		 " " . $group_by .
	 		 " " . $order_by;
	 		 
	 	return $query;
	 	
	}
	

	function getOrderingText ($ordering) {
		switch ((int)$ordering) {
			case 2:
				$orderingOutput	= 'ordering DESC';
			break;
			
			case 3:
				$orderingOutput	= 'title ASC';
			break;
			
			case 4:
				$orderingOutput	= 'title DESC';
			break;
			
			case 5:
				$orderingOutput	= 'date ASC';
			break;
			
			case 6:
				$orderingOutput	= 'date DESC';
			break;
			
			case 7:
				$orderingOutput	= 'id ASC';
			break;
			
			case 8:
				$orderingOutput	= 'id DESC';
			break;
		
			case 1:
			default:
				$orderingOutput = 'ordering ASC';
			break;
		}
		return $orderingOutput;
	}	
	
}

jimport('joomla.html.pagination');
class Sql2excelPagination extends JPagination
{

	function getLimitBox()
	{
		//global $mainframe;
		//$paramsC 		= JComponentHelper::getParams('com_sql2excel') ;		
		//$pagination 		= $paramsC->get( 'pagination', '5;10;15;20;50;100' );
		
		$cmpParms 	= Sql2excelParms::getParms();
		$pagination = Sql2excelParms::get($cmpParms,'pagination', '5;10;15;20;50;100');
		
		$paginationArray	= explode( ';', $pagination );
		
		// Initialize variables
		$limits = array ();

		foreach ($paginationArray as $paginationValue) {
			$limits[] = JHTML::_('select.option', $paginationValue);
		}
		$limits[] = JHTML::_('select.option', '0', JText::_('all'));

		$selected = $this->_viewall ? 0 : $this->limit;

		// Build the select list
		if ($mainframe->isAdmin()) {
			$html = JHTML::_('select.genericlist',  $limits, 'limit', 'class="inputbox" size="1" onchange="submitform();"', 'value', 'text', $selected);
		} else {
			$html = JHTML::_('select.genericlist',  $limits, 'limit', 'class="inputbox" size="1" onchange="this.form.submit()"', 'value', 'text', $selected);
		}
		return $html;
	}
}

?>
Return current item: Chalange