Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

lib/search.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************************
00003  This program is free software; you can redistribute it and/or
00004  modify it under the terms of the GNU General Public License
00005  as published by the Free Software Foundation; either version 2
00006  of the License, or (at your option) any later version.
00007 
00008  This program is distributed in the hope that it will be useful,
00009  but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011  GNU General Public License for more details.
00012 
00013  You should have received a copy of the GNU General Public License
00014  along with this program; if not, write to the Free Software
00015  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00016  ***************************************************************************/
00017 
00023 class Search
00024 {
00025     var $oDB;   
00026     var $oUser; 
00027 
00032     function Search ( &$oDB, &$oUser )
00033     {
00034         $this->oDB =& $oDB;
00035         $this->oUser =& $oUser;
00036     }
00037 
00038     function doSearch ( $strName = '', $strGuild = '', $intGuild = 0, $intX = 0, $intY = 0, $intRadius = 0, $strOrder = '' )
00039     {
00040         // check order
00041         switch ( $strOrder )
00042         {
00043             case 'position':
00044                 $strOrderBy = '`x`, `y`';
00045                 break;
00046             case 'guild':
00047                 $strOrderBy = 'g.`tag`, p.name';
00048                 break;
00049             case 'town':
00050                 $strOrderBy = 't.name';
00051                 break;
00052             default:
00053                 $strOrderBy = 'p.`name`';
00054         }
00055 
00056         // Set SQL Filter
00057         $strFilter = '';
00058         if ( $strName != '' )
00059         {
00060             $strFilter .= " AND UPPER(`p`.`name`) LIKE UPPER('%$strName%')";
00061         }
00062 
00063         if ( $strGuild != '' )
00064         {
00065             $strFilter .= " AND UPPER(`g`.`tag`) LIKE UPPER('%$strGuild%')";
00066         }
00067 
00068         if ( $intX > 0 )
00069         {
00070             $strFilter .= " AND t.`x` BETWEEN ".($intX-$intRadius)." AND ".($intX+$intRadius);
00071         }
00072 
00073         if ( $intY > 0 )
00074         {
00075             $strFilter .= " AND t.`y` BETWEEN ".($intY-$intRadius)." AND ".($intY+$intRadius);
00076         }
00077 
00078         if ( $intGuild > 0 && $strFilter == '' )
00079         {
00080             $strFilter = ' AND `p`.`guild_id`='.$intGuild;
00081         }
00082 
00083         if ( $this->oUser->intLimitView > 0 )
00084         {
00085             // user has not full view
00086             $strFilter .= ' AND t.x BETWEEN '.( $this->oUser->intHomeX - $this->oUser->intLimitView).' AND '.($this->oUser->intHomeX + $this->oUser->intLimitView);
00087             $strFilter .= ' AND t.y BETWEEN '.( $this->oUser->intHomeY - $this->oUser->intLimitView).' AND '.($this->oUser->intHomeY + $this->oUser->intLimitView);
00088         }
00089 
00090         $sqlResult = $this->oDB->query("SELECT p.`name`, t.`name` AS `townname`, g.`tag` AS `guild_tag`, t.`x`, t.`y`, p.`guild_id`, m.building ".
00091                              "FROM `".$this->oDB->tblTown."` t ".
00092                              "LEFT JOIN `".$this->oDB->tblMapData."` m ON (t.x=m.x AND t.y=m.y) ".
00093                              "LEFT JOIN `".$this->oDB->tblPlayer."` p ON (t.`player_id`=p.`player_id`) ".
00094                              "LEFT JOIN `".$this->oDB->tblGuild."` g  ON (p.`guild_id`=g.`guild_id`) ".
00095                              "WHERE t.`town_id`>0  AND m.`building` > '-10' ".$strFilter." ".
00096                              "ORDER BY $strOrderBy;");
00097 
00098         $aResult = array();
00099         while ( $aRow = $this->oDB->fetch_assoc ($sqlResult) )
00100         {
00101             if ( !isset ( $aRow['guild_tag'] ) ) $aRow['guild_tag'] = '';
00102             if ( !isset ( $aRow['guild_id'] ) )  $aRow['guild_id']  = 0;
00103             $aRow['prefix'] = ( $aRow['building'] == -2 ) ? '~' : '';
00104             $aResult[] = $aRow;
00105         }
00106         return $aResult;
00107     }
00108 }

Generated on Sun May 8 19:29:45 2005 for PhpMap by  doxygen 1.4.2