Jump to content

How to... New shedules search options


ARV187

Recommended Posts

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');
	}

 

Edited by ARV187
Link to comment
Share on other sites

  • 6 months later...

Search by time:

\lib\skins\YourSkin\schedule_searchform.tpl

<li class="nav-item"><a class="nav-link" href="#flighttimetab"><span><button type="button" class="btn btn-primary">Por tiempo</button></span></a></li> //write this with the others tabs code

<div id="flighttimetab" class="card-body text-white bg-dark">
		<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="" />  Horas      
		<input type="submit" name="submit" value="Buscar vuelos" />
</div>

 

 

\core\modules\Schedules\Schedules.php

		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);			
		}

 

Edited by ARV187
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...