Hi, I’ trying to modify the search function to not only have ‘<’ or ‘>’ distance, if not between ‘distance1’ and ‘distance2’ too, and by flight time.
I have not gotten it to work for me, I don’t know if I have to modify something else, or how to implement it in the existing code. My phpvms version is v2.
Thanks!
So in SchedulesData.class.php Line 19:
class SchedulesData extends CodonData { /\*\* \* A generic find function for schedules. As parameters, do: \* \* $params = array( 's.depicao' =\> 'value', \* 's.arricao' =\> array ('multiple', 'values'), \* ); \* \* Syntax is ('s.columnname' =\> 'value'), where value can be \* an array is multiple values, or with a SQL wildcard (%) \* if that's what is desired. \* \* Columns from the schedules table should be prefixed by 's.', \* the aircraft table as 'a.' \* \* You can also pass offsets ($start and $count) in order to \* facilitate pagination \* \* @tutorial http://docs.phpvms.net/media/development/searching\_and\_retriving\_schedules \*/ public static function findSchedules($params, $count = '', $start = '') { $sql = 'SELECT s.\*, a.id as aircraftid, a.name as aircraft, a.registration, a.minrank as aircraft\_minrank, a.ranklevel as aircraftlevel, dep.name as depname, dep.lat AS deplat, dep.lng AS deplng, arr.name as arrname, arr.lat AS arrlat, arr.lng AS arrlng FROM '.TABLE\_PREFIX.'schedules AS s LEFT JOIN '.TABLE\_PREFIX.'airports AS dep ON dep.icao = s.depicao LEFT JOIN '.TABLE\_PREFIX.'airports AS arr ON arr.icao = s.arricao LEFT JOIN '.TABLE\_PREFIX.'aircraft AS a ON a.id = s.aircraft '; /\* Build the select "WHERE" based on the columns passed, this is a generic function \*/ $sql .= DB::build\_where($params); // Order matters if(Config::Get('SCHEDULES\_ORDER\_BY') != '') { $sql .= ' ORDER BY '.Config::Get('SCHEDULES\_ORDER\_BY'); } if(strlen($count) != 0) { $sql .= ' LIMIT '.$count; } if(strlen($start) != 0) { $sql .= ' OFFSET '. $start; } $ret = DB::get\_results($sql); return $ret; }
schedule_searchform.tpl at line 92
\<div id="flighttime"\> \<p\>Selecciona tiempo de vuelo:\</p\> \<select id="type" name="type"\> \<option value="greater"\>Mayor que\</option\> \<option value="less"\>Menor que\</option\> \</select\> \<input type="text" name="flighttime" value="" /\> \<input type="submit" name="submit" value="Buscar vuelos" /\> \</div\>
Schedules.php at line 175
public function findFlight() { if($this-\>post-\>depicao != '') { $params = array('s.depicao' =\> $this-\>post-\>depicao); } if($this-\>post-\>arricao != '') { $params = array('s.arricao' =\> $this-\>post-\>arricao); } if($this-\>post-\>equipment != '') { $params = array('a.name' =\> $this-\>post-\>equipment); } if($this-\>post-\>distance != '') { if($this-\>post-\>type == 'greater') $value = '\> '; if($this-\>post-\>type == 'less') $value = '\< '; $value .= $this-\>post-\>distance; $params = array('s.distance' =\> $value); } //////////////////////\* my code start \*//////////////////////// if($this-\>post-\>flighttime != '') { if($this-\>post-\>type == 'greater') $value = '\> '; if($this-\>post-\>type == 'less') $value = '\< '; $value .= $this-\>post-\>flighttime; $params = array('s.flighttime' =\> $value); } //////////////////////\* my code end \*//////////////////////// $params['s.enabled'] = 1; $this-\>set('allroutes', SchedulesData::findSchedules($params)); $this-\>render('schedule\_results.tpl'); }