Jump to content

Separate schedule pages


Jon

Recommended Posts

Hello All,

I am looking to create separate pages for my virtual airline's schedules. Is there a get a schedule function? In the API, I can see you can find by dep icao and arr icao but it doesn't mention anything about by airline.Does this just get called in the main module.php and then just set a variable?

Thanks in advance

Jon

Link to comment
Share on other sites

Guest lorathon

Open the core/common/SchedulesData.class.php file. At the top you will see the following. It has instructions on how to pull schedules using the SchedulesData::findSchedules Function.

/**
    * 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);

       if(!$ret) {
           return array();
       }

       return $ret;
   }

Link to comment
Share on other sites

Guest lorathon

Is it a possibility to get an example of how to seperate schedules by airline?

Sure.

<?php

$code = 'AA';  // insert the airline code into here
$count = 10;   // set the number of schedules you wish returned

$params = array(
       's.code'     => $code,
       's.enabled'  => 1,
       );

$scheds = SchedulesData::finsSchedules($params);  // This will give you all of the (enabled) schedules with the airline code plugged into $code
$scheds = SchedulesData::findSchedules($params, $count);  // This will give $count number of (enabled) schedules with the airline code

Link to comment
Share on other sites

Guest lorathon

What I would do is to write a new module using that code. (NONE OF THIS HAS BEEN TESTED. I WROTE IT HERE. )

core/modules/custom_schedules.php

<?php

class custom_schedules extends CodonModule
{

   public static index() {

       $this->set('airlines', OperationsData::getAllAirlines(true);
       $this->render('custom_schedules_main.tpl');
   }

   public static airlineSched($code) {

       $params = array(
           's.code'     => $code,
           's.enabled'  => 1,
           );

       $scheds = SchedulesData::findSchedules($params);

       $this->set('scheds', $scheds);
       $this->render('custom_schedules_airline.tpl');
   }
}



So you will need to construct two templates

custom_schedules_main.tpl

<table>
   <thead>
       <th>Airline Code</th>
       <th>Details</th>
   </thead>
   <tbody>
   <?php
       if($airlines) {
           foreach($airlines as $row) {
   ?>
       <tr>
           <td><?php echo $row->code?></td>
           <td><a href="<?php echo SITE_URL.'/index.php/custom_schedules/airlineSched/'.$row->code?>">LINK</a></td>
       </tr>
   <?php
           }
       } else {
   ?>
       <tr>
           <td>No Airlines Available</td>
       </tr>
   </tbody>
</table>

custom_schedules_airline.tpl

<table>
   <thead>
       <th>Flight #</th>
   </thead>
   <tbody>
   <?php
       if($scheds) {
           foreach($scheds as $row) {
   ?>
       <tr>
           <td><?php echo $row->code.$row->flightnum?></td>            
       </tr>
   <?php
           }
       } else {
   ?>
       <tr>
           <td>No Schedules for this Airline</td>
       </tr>
   </tbody>
</table>

Then you should be able to call the module from www.YOURSITE.com/index.php/custom_schedules

Link to comment
Share on other sites

Module code:

<?php

class airlineschedules extends CodonModule
{

public function index() {

   	$this->set('airlines', OperationsData::getAllAirlines(true));
   	$this->render('custom_schedules_main.tpl');
}

public function airlineSched($code) {

   	$params = array(
       	's.code' 	=> $code,
       	's.enabled'  => 1,
       	);

   	$scheds = SchedulesData::findSchedules($params);

   	$this->set('scheds', $scheds);
   	$this->render('custom_schedules_airline.tpl');
}
}
?>

NB: I changed the name of the module

you had public static index, should have been public function or public static function, but function works just fine. Also with the SchedulesData::findSchedules, you had fat fingered the keyboard, and had finsSchedules hehe.

custom_schedules_airline:

<table>
<thead>
   	<th>Flight #</th>
   	<th>Dep. airport</th>
   	<th>Arr. Airport</th>
   	<th>Book</th>
</thead>
<tbody>
<?php
   	if($scheds) {
       	foreach($scheds as $row) {
?>
   	<tr>
       	<td><a href="<?php echo url('/schedules/details/'.$row->id);?>"><?php echo $row->code.$row->flightnum?></a></td>
       	<td><?php echo $row->depicao . ' '. $row->depname;?></td>
       	<td><?php echo $row->arricao .' '. $row->arrname;?></td> 
       	<td><?php if(Auth::LoggedIn())
		{
		 ?>
			<a id="<?php echo $row->id; ?>" class="addbid" 
				href="<?php echo url('/schedules/addbid');?>">Add to Bid</a>
		<?php			 
		}

	?> 	</td>  	
   	</tr>
<?php
       	}
   	} else {
?>
   	<tr>
       	<td>No Schedules for this Airline</td>
   	</tr>
   	<?php
}
?>
</tbody>
</table>

NB: I have edited to my own liking.

Main problem was you never closed the else statement, the same with the custom_schedules_main.tpl

Custome_schedules_main.tpl:

<table border="1" class="display" id="schedule">
<thead>
   	<th>Airline Code</th>
   	<th>Details</th>
</thead>
<tbody>
<?php
   	if($airlines) {
       	foreach($airlines as $row) {
?>
   	<tr>
       	<td><?php echo $row->code?></td>
       	<td><a href="<?php echo SITE_URL.'/index.php/airlineschedules/airlineSched/'.$row->code?>">View Schedules</a></td>
   	</tr>
<?php
       	}
   	} else {
?>
   	<tr>
       	<td>No Airlines Available</td>
   	</tr>
   	<?php 
}
?>
</tbody>
</table>

NB:I have edited this to my liking.

Link to comment
Share on other sites

  • 1 year later...

I get an error :(

How does it "grab" the schedule data from the sql database? Is it because I have a different code for my database, other than phpvms_ Here is the error:

[b]	Not Found[/b]

The requested URL /CPCfile:///index.php/airlineschedules/airlineSched/CPC was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

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