Jump to content

Showing all schedules with searching


LanceDesigns

Recommended Posts

Hey Guys!

So I am developing my pilots center, and I had successfully modified the search form and results form. I tried using Simpilot's addon, but it is not compatible with the current PHPvms. Because I have over 8000 routes, it takes over 30 seconds for it to load. Is there a way where I can limit how many routes it loads at first so it can load faster? I tried pagination, but it still does the same thing (loads all at first then puts it in order). Attached is a photo of my schedules/view page. Is there a way where I can have a search form first, then display the schedules instead of having the schedules and search form?

post-45448-0-97325400-1424039310_thumb.png

Link to comment
Share on other sites

If you go into your core/modules/Schedules.php, look at the index() function and you should find a line similar to $this->show('schedules_results.tpl'); (or .php). Just remove that and it will not display when you open the schedules page.

Was a little confused with the screenshot, thought it was an admin center (which is obviously what the author intended it to be).

Link to comment
Share on other sites

Yea, Here it is:

<?php
/**
* phpVMS - Virtual Airline Administration Software
* Copyright © 2008 Nabeel Shahzad
* For more information, visit www.phpvms.net
* Forums: http://www.phpvms.net/forum
* Documentation: http://www.phpvms.net/docs
*
* phpVMS is licenced under the following license:
*   Creative Commons Attribution Non-commercial Share Alike (by-nc-sa)
*   View license.txt in the root, or visit http://creativecommo...s/by-nc-sa/3.0/
*
* @author Nabeel Shahzad
* @copyright Copyright © 2008, Nabeel Shahzad
* @link http://www.phpvms.net
* @license http://creativecommo...s/by-nc-sa/3.0/
*/

class Schedules extends CodonModule {

/**
 * Schedules::index()
 *
 * @return
 */
public function index() {
	$this->view();
}

/**
 * Schedules::view()
 *
 * @return
 */
public function view() {
	if (isset($this->post->action) && $this->post->action == 'findflight') {
		$this->FindFlight();
		return;
	}

	$this->showSchedules();
}

/**
 * Schedules::detail()
 *
 * @param string $routeid
 * @return
 */
public function detail($routeid = '') {
	$this->details($routeid);
}

/**
 * Schedules::details()
 *
 * @param string $routeid
 * @return
 */
public function details($routeid = '') {
	//$routeid = $this->get->id;

	if (!is_numeric($routeid)) {
		preg_match('/^([A-Za-z]{3})(\d*)/', $routeid, $matches);
		$code = $matches[1];
		$flightnum = $matches[2];

		$params = array('s.code' => $code, 's.flightnum' => $flightnum);
	} else {
		$params = array('s.id' => $routeid);
	}

	$schedule = SchedulesData::getScheduleDetailed($routeid);
	$this->set('schedule', $schedule);
	$this->render('schedule_details.tpl');
	$this->render('route_map.tpl');
}

/**
 * Schedules::brief()
 *
 * @param string $routeid
 * @return
 */
public function brief($routeid = '') {
	if ($routeid == '') {
		$this->set('message', 'You must be logged in to access this feature!');
		$this->render('core_error.tpl');
		return;
	}

	$schedule = SchedulesData::getScheduleDetailed($routeid);
	$this->set('schedule', $schedule);
	$this->render('schedule_briefing.tpl');
}

/**
 * Schedules::boardingpass()
 *
 * @param mixed $routeid
 * @return
 */
public function boardingpass($routeid) {
	if ($routeid == '') {
		$this->set('message', 'You must be logged in to access this feature!');
		$this->render('core_error.tpl');
		return;
	}

	$schedule = SchedulesData::getScheduleDetailed($routeid);

	$this->set('schedule', $schedule);
	$this->render('schedule_boarding_pass.tpl');
}

/**
 * Schedules::bids()
 *
 * @return
 */
public function bids() {
	if (!Auth::LoggedIn())
		return;

	$this->set('bids', SchedulesData::GetBids(Auth::$pilot->pilotid));
	$this->render('schedule_bids.tpl');
}

/**
 * Schedules::addbid()
 *
 * @return
 */
public function addbid() {
	if (!Auth::LoggedIn())
		return;

	$routeid = $this->get->id;

	if ($routeid == '') {
		echo 'No route passed';
		return;
	}

	// See if this is a valid route
	$route = SchedulesData::findSchedules(array('s.id' => $routeid));

	if (!is_array($route) && !isset($route[0])) {
		echo 'Invalid Route';
		return;
	}

	CodonEvent::Dispatch('bid_preadd', 'Schedules', $routeid);

	/* Block any other bids if they've already made a bid
	*/
	if (Config::Get('DISABLE_BIDS_ON_BID') == true) {
		$bids = SchedulesData::getBids(Auth::$pilot->pilotid);

		# They've got somethin goin on
		if (count($bids) > 0) {
			echo 'Bid exists!';
			return;
		}
	}

	$ret = SchedulesData::AddBid(Auth::$pilot->pilotid, $routeid);
	CodonEvent::Dispatch('bid_added', 'Schedules', $routeid);

	if ($ret == true) {
		echo 'Bid added';
	} else {
		echo 'Already in bids!';
	}
}

/**
 * Schedules::removebid()
 *
 * @return
 */
public function removebid() {
	if (!Auth::LoggedIn())
		return;

	SchedulesData::RemoveBid($this->post->id);
}

/**
 * Schedules::showSchedules()
 *
 * @return
 */
public function showSchedules() {

	$depapts = OperationsData::GetAllAirports();
	$equip = OperationsData::GetAllAircraftSearchList(true);
	$airlines = OperationsData::GetAllAirlines();

	$this->set('airlines', $airlines); #deprecated
	$this->set('airline_list', $airlines);

	$this->set('depairports', $depapts);

	$this->set('equipment', $equip); # deprecated
	$this->set('aircraft_list', $equip);

	$this->render('schedule_searchform.tpl');

	# Show the routes. Remote this to not show them.

	$schedules = SchedulesData::getSchedules();

	# Do some filtering and whatnots, take it out of the template...	  
	$today = getdate();
	$week_number = intval(($today['mday'] - 1) / 7) + 1;
	$current_day == date('w');
	$var_name = 'week'.$week_number;

	# query once, save for later
	if(Config::get('SCHEDULES_ONLY_LAST_PIREP') === true && Auth::LoggedIn() == true) {
	 $pirep_list = PIREPData::findPIREPS(array(
 'p.pilotid' => Auth::$pilot->pilotid,
 'p.accepted' => PIREP_ACCEPTED
   ), 1); // return only one
	}

	foreach($schedules as $key => $s) {

		# should we skip schedules based on day of week?
		if(Config::get('CHECK_SCHEDULE_DAY_OF_WEEK') === true) {

			if(isset($s->{$var_name}) && !empty($s->{$var_name})) {
				# check if today is in the active list for this week
				if(@substr_count($s->{$var_name}, $current_day) == 0) {
					unset($schedules[$key]);
					continue;
				}
			} else {
				if(substr_count($s->daysofweek, date('w')) == 0) {
					unset($schedules[$key]);
					continue;
				}
			}
		}

		# remove this schedule from the list if there's a bid on it
	 if(Config::get('DISABLE_SCHED_ON_BID') === true && $route->bidid != 0) {
	 unset($schedules[$key]);
			continue;
	 }


		/* This means the aircraft rank level is higher than
	 what the pilot's ranklevel, so just do "continue"
	and move onto the next route in the list  */
		if(Config::get('RESTRICT_AIRCRAFT_RANKS') === true && Auth::LoggedIn()) {
	 if($route->aircraftlevel > Auth::$pilot->ranklevel) {
	 unset($schedules[$key]);
				continue;
	 }
	 }

		if(Config::get('SCHEDULES_ONLY_LAST_PIREP') === true && Auth::LoggedIn() == true) {
	 if(count($pirep_list) > 0) {
	 # IF the arrival airport doesn't match the departure airport
	 if($pirep_list[0]->arricao != $s->depicao) {
	 unset($schedules[$key]);
					continue;
	 }
	 }
		}

	} // end foreach schedules

	$this->set('allroutes', $schedules);
	$this->set('schedule_list', $schedules);
	$this->render('schedule_list.tpl');
}

/**
 * Schedules::findFlight()
 *
 * @return
 */
public function findFlight() {


	$params = array();
	if($this->post->airlines != '') {
		$params['s.code'] = $this->post->airlines;
	}

	if ($this->post->depicao != '') {
		$params['s.depicao'] = $this->post->depicao;
	}

	if ($this->post->arricao != '') {
		$params['s.arricao'] = $this->post->arricao;
	}

	if ($this->post->equipment != '') {
		$params['a.name'] = $this->post->equipment;
	}

	if ($this->post->distance != '') {
		if ($this->post->type == 'greater')
			$value = '> ';
		else
			$value = '< ';

		$value .= $this->post->distance;

		$params['s.distance'] = $value;
	}

	$params['s.enabled'] = 1;

	$schedule_list = SchedulesData::findSchedules($params);
	$this->set('allroutes', $schedule_list); #deprecated
	$this->set('schedule_list', $schedule_list);

	$this->render('schedule_results.tpl');
}

/**
 * Schedules::statsdaysdata()
 *
 * @param mixed $routeid
 * @return
 */
public function statsdaysdata($routeid) {

	$schedule = SchedulesData::findSchedules(array('s.id' => $routeid));
	$schedule = $schedule[0];

	// Last 30 days stats
	$data = PIREPData::getIntervalDataByDays(array(
		'p.code' => $schedule->code,
		'p.flightnum' => $schedule->flightnum,
		), 30);

	$this->create_line_graph('Schedule Flown Counts', $data);
}

/**
 * Schedules::create_line_graph()
 *
 * @param mixed $title
 * @param mixed $data
 * @return
 */
protected function create_line_graph($title, $data) {

	if (!$data) {
		$data = array();
	}

	$titles = array();
	$bar_titles = array();
	foreach ($data as $val) {
		$titles[] = $val->ym;
		$values[] = floatval($val->total);
	}

	OFCharts::add_data_set($titles, $values);
	echo OFCharts::create_line_graph($title);
}
}

Link to comment
Share on other sites

Going back to this because I forgot to share my solution. Although you said you were happy with that one, it's not ideal further down the line because if you for some reason need to load all your schedules it will only show 500. So, take out the $count = '500'.

Instead, phpVMS has a few things included by default to accomodate the thing you wanted.

In core/modules/Schedules/Schedules.php, you'll see around line 169 and 170 it says:

# Show the routes. Remote this to not show them.
$this->set('allroutes', SchedulesData::GetSchedules());

Do what it says and remote the $this->set ... part:

# Show the routes. Remote this to not show them.
# $this->set('allroutes', SchedulesData::GetSchedules());

That will hide the routes when you first load the schedules page, leaving only the form. It's as simple as adding '#'.

After that, I recommend you use pagination like you mentioned in the first post, because loading all flights from major hubs like KPHX and KPHL might take a while.

Link to comment
Share on other sites

  • 2 months later...
  • 9 months later...

Just saw this post and tried removing the line as mentioned above. Mine is formatted as so;

# Show the routes. Remote this to not show them.
#$schedules = SchedulesData::getSchedules();

This now makes my schedule search form show up nicely but I get an additional error relating to the foreach() function just underneath it in the Schedules.php file. The code that is throwing the error is;

foreach($schedules as $key => $s) {

	    # should we skip schedules based on day of week?
	    if(Config::get('CHECK_SCHEDULE_DAY_OF_WEEK') === true) {

		    if(isset($s->{$var_name}) && !empty($s->{$var_name})) {
			    # check if today is in the active list for this week
			    if(@substr_count($s->{$var_name}, $current_day) == 0) {
				    unset($schedules[$key]);
				    continue;
			    }
		    } else {
			    if(substr_count($s->daysofweek, date('w')) == 0) {
				    unset($schedules[$key]);
				    continue;
			    }
		    }
	    }

	    # remove this schedule from the list if there's a bid on it
	 if(Config::get('DISABLE_SCHED_ON_BID') === true && $route->bidid != 0) {
	  unset($schedules[$key]);
		    continue;
	 }


	    /* This means the aircraft rank level is higher than
	  what the pilot's ranklevel, so just do "continue"
	  and move onto the next route in the list  */
	    if(Config::get('RESTRICT_AIRCRAFT_RANKS') === true && Auth::LoggedIn()) {
	  if($route->aircraftlevel > Auth::$pilot->ranklevel) {
	   unset($schedules[$key]);
			    continue;
	  }
	 }

	    if(Config::get('SCHEDULES_ONLY_LAST_PIREP') === true && Auth::LoggedIn() == true) {
	  if(count($pirep_list) > 0) {
	   # IF the arrival airport doesn't match the departure airport
	   if($pirep_list[0]->arricao != $s->depicao) {
	    unset($schedules[$key]);
				    continue;
	   }
	  }
	    }

    }

It looks to me like the foreach statement is calling on the $schedules that I just commented out. I have tried making this $schedules = SchedulesData(); but that didn't seem to work.

Any help anyone can give?

Thank you.

Link to comment
Share on other sites

Ok I can confirm that commenting out;

$this->set('allroutes', $schedules);

does indeed result in the same original memory error. Thank you anyway web541 as always.

That doesnt make much sense as the function would still query all schedules that way. Instead just use if in the template file.

if($schedules)

foreach($schedules as $whatever)

Not sure what you mean here mseiwald. Do you mean include the "if" statement in the schedule_searchform.php?

Link to comment
Share on other sites

No it is The foreach Loop in schedule_results.php

Ok, bear with me as I'm just learning PHP and just trying to understand this. I get the IF statement at the top of the page is just checking there are actually any routes. The bit further down in effect says, from the $schedules_list array, set each to $schedule. From this point all the echo statements are there just to show routes in separate entities on the resulting page. (tell me if I'm mistaken).

So, I am assuming that for your comment, it would need to go inside the existing foreach statement in order to turn the already created $schedules variable into something else such as $whatever, yes? What I don't get, is how this would stop the routes still being shown.

<?php if(!defined('IN_PHPVMS') && IN_PHPVMS !== true) { die(); } ?>
<?php
if(!$schedule_list)
{
echo '<p align="center">No routes have been found!</p>';
return;
}
?>
<table id="tabledlist" class="tablesorter">
<thead>
<tr>
<th>Flight Info</th>
<th>Options</th>
</tr>
</thead>
<tbody>
<?php foreach($schedule_list as $schedule) { ?>
<tr>
<td>
 <a href="<?php echo url('/schedules/details/'.$schedule->id);?>"><?php echo $schedule->code . $schedule->flightnum?>
  <?php echo '('.$schedule->depicao.' - '.$schedule->arricao.')'?>
 </a>
 <br />

 <strong>Departure: </strong><?php echo $schedule->deptime;?>         <strong>Arrival: </strong><?php echo $schedule->arrtime;?><br />
 <strong>Equipment: </strong><?php echo $schedule->aircraft; ?> (<?php echo $schedule->registration;?>)  <strong>Distance: </strong><?php echo $schedule->distance . Config::Get('UNITS');?>

Link to comment
Share on other sites

I had a look at the module now and you were right its actually in the module where you commented out this:

# Show the routes. Remote this to not show them.

// $schedules = SchedulesData::getSchedules();

a bit below is this:

foreach($schedules as $key => $s) {

and the if statement needs to go there like:

if($schedules)
foreach($schedules as $key => $s) {

Link to comment
Share on other sites

Yep, sorted it now thank you. Now showing the form correctly.

Just noticed that the events module from you (crazy creatives) does the same thing. When trying to add a scheduled flight to an event, I get a php memory error. When I look at the code, it's the same issue. The function is trying to show all schedules. I was thinking, it would make more sense for the addflights.php file to also have a form which is preset with the depicao and the arricao and then the form shows only those routes that apply, rather than all routes. It's the function addflights1 that looks like it's calling all schedules.

Would there be a way to stop all the schedules showing as with the above and just call the relevant schedules using the ICAOs?

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...