Location: PHPKode > projects > Pygalle > admin/tables/location.php
<?php
/**
 * @package		Pygalle
 * @copyright	Copyright (C) 2009 Erik Finnegan. All rights reserved.
 * @license		GNU/GPL, see LICENSE.php
 * @author 		hide@address.com
 * Joomla! and Pygalle EVE Corporate Intranet are 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.
 */

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die('Restricted access');
pyimport( 'tables.table');

class PyTableLocation extends PyTable {
	
	/**
	* @access 	protected
	*/
	function __construct( &$db ) {
		parent::__construct( '#__py_locations', 'id', $db);
	}
	
	
	/**
	 * @param int $limit
	 * @param array $ids
	 * @param string $types one of "BODIES" or "BELTS" or "SYSTEMS" to restrict locations to one type
	 * @return unknown
	 */
	function getLocations( $limit = 100, $ids = null, $types = 'ANY', $searchsystem = null) {
		$querylimit = "";
		$exactid = "";
		$type = "";
		$exactsystem = "";
		if ( $ids === null) {
			if ($limit !== null) {
				/* this is calculating the last n rows. Not needed for now.
				$query = 'SELECT count(*) FROM #__py_locations AS y WHERE y.`published` = 1';
				$db->setQuery($query);
				$numrows = $db->loadResult();
				$this->_log->trace($db);
				$limit = $numrows - $limit;
				*/
				$querylimit = " LIMIT $limit";
			}
		} else {
			if ( !is_array($ids)) { $ids = array( $ids); }
			$exactid = ' AND (';
			$_first = true;
			foreach ($ids as $minindId) {
				if ( $_first) {
					$_first = false;
				} else {
					$exactid .= ' OR ';
				}
				$exactid .= "`id` = $minindId";
			}
			$exactid .= ') '; 
		}
		switch ( $types) {
			case 'BODIES':
				$type .= ' AND belt = 0';
				break;
			case 'BELTS':
				$type .= ' AND moon = 0 AND belt <> 0';
				break;
			case 'SYSTEMS':
				$type .= ' AND planet = 0 AND moon = 0 AND belt = 0';
				break;
		}
		if ( $searchsystem !== null && strlen($searchsystem) > 0) {
			$exactsystem .= ' AND system = "' . $searchsystem . '"';
		}
			
		$query = 'SELECT *'
		 . ' FROM #__py_locations AS y'
		 . ' WHERE `published` = 1'
		 . $exactid
		 . $type
		 . $exactsystem
		 . ' ORDER BY `system`, `planet`, `moon`, `belt` ' 
		 . $querylimit;

		 return $this->loadObjectList( $query);
	}
	
}
?>
Return current item: Pygalle