Jump to content

Recommended Posts

  • Moderators
Posted

Hi is there an easy way of listing a pilots last arrival in their profile? What im trying to do is have pilots follow on from their arrival airport as in the real world but on different equipment. So ay one day i do EGKK to EHAM then when i come back id start from EHAM which would be listed in my profile as a reminder.

Thanks

  • Administrators
Posted

Nice idea.

What you can do is:

$lastreport = PIREPData::GetLastReports($pilotid, 1);
$lastreport->arricao; // This is the airport they arrived at

$pilotid is their pilot number, without the code (so 001, etc)

If you're doing it in the profile_main.tpl, you can do:

echo 'Your arrival apt was '.$report->arricao;

Since I pull the last report to show the latest PIREP. Any other template/page you can do the above code (before this one)

  • 4 months later...
Posted

This is a fantastic Idea.

Nabeel would I be correct with teh following statement

			<li><strong>Total Money: </strong><?php echo FinanceData::FormatMoney($userinfo->totalpay) ?></li>
<?php
$lastreport = PIREPData::GetLastReports($pilotid, 1);
$lastreport->arricao; // This is the airport they arrived at
if(!$lastreport)
{
?>
		<li><strong>Current Location: </strong>You have not submitted a Pirep yet</li>
<?php
}
else
{
?>
		<li><strong>Current Location: </strong><?php echo $report->arricao; ?></li>
<?php
}
?>

The Idea here is for new pilots. so If they have not flown yet, it will say that no pirep has been flown yet.

Would it be possible to do a check that if a pirep has been submitted, it will then take the data from the selected hub they registered for?

All this brings me to my next question, probably more aimed at a feture request i guess,  but its directly related to this topic.

On the live map, is there a possiblity to show an icon of the current location of a pilot. It does this already when flying, but I am talking about when they are not?

Thanks for all the help

Posted

Hi Guys

I changed it slight to look like the following:

<?php
$lastreport = PIREPData::GetLastReports($pilotid, 1);
$lastreport->arricao; // This is the airport they arrived at
if($lastreport->arricao<>'')
{
?>
		<li><strong>Current Location: </strong>You have not submitted a Pirep yet"</li>
<?php
}
else
{
?>
		<li><strong>Current Location: </strong><?php echo $report->arricao; ?></li>
<?php
}
?>

Now that seems to kinda work. What happens now is it either shows teh Icao code of teh arrival airport or it will show nothing.

Nabeel, is it possible to rather show the airport name instead of the ICAO code?

In the current code format in this post will eitehr show teh icao code or show nothing. If I put an Excalmation mark there in teh begining:

if(!$lastreport->arricao<>'')

The it either shows me the "You have not submitted a Pirep yet" or it shows me black. So I can see that the if / else statement is kinda working, but its not showing the else part

I hope that makes any sense  ;D

  • Administrators
Posted

Use arrname

And you can do:

<?php
$lastreport = ...

if(!$lastreport)
{
    echo 'no reports';
}
?>

It will return false if there's no results.

If you do print_r or var_dump() on the $report variable, you'll see all the available fields

Posted

Hey Nabeel

I am sorry but I just cannot get it right at all.

Again I only a one side result, it either show me nothing or somthng

I.e. If there are no reports it will result "No Reports"

If there are report then it does not show any results.

I am just not undertsanding this thing

This is what I am looking for (On the profile_main.tpl file)

if there are no pireps then it shoud read:

Current Location: FAGC - Grand Central (As an example - this would default to the hub selected)

If there are pireps filed the the same line should read

Current Location: FAMB - Middleburg (Again just using an example)

The idea is to only have a 1 line entry, but to show either state.

I kinda understand what you are saying, but I just cannot get it to work at all  ???.

I am used to a normal sql and php code, but this I just cannot seem to clear my head on. I really am sorry if I am wasting your time on this

  • Administrators
Posted

Then it would be something like:

<?php
$lastreport = PIREPData::GetLastReports($pilotid, 1);
if(!$lastreport)
{
?>
         <li><strong>Current Location: </strong><?php echo $userinfo->hub;?></li>
<?php
}
else
{
?>
         <li><strong>Current Location: </strong><?php echo $report->arricao; ?></li>
<?php
}
?>

$userinfo might be $pilot

Or to clean it up...

<?php
$lastreport = PIREPData::GetLastReports($pilotid, 1);
if(!$lastreport)
{
    $location = $userinfo->hub;
}
else
{
    $location = $lastreport->arricao;
}
?>

<li><strong>Current Location: </strong><?php echo $location; ?></li>

Posted

Hey Nabeel

Yes I replaced the names and now it works like a charm - Thanks for that when I look at teh api docs what you did makes even more sense, but also not totally. May I ask another question?

I am struggeling to tie up two values from different tables

Now that I have teh correct icao code based on airport location I want to ty up teh airport icao code with teh airport name.

So when I check you api doc I see to get teh airport name I need to use the OperationData::GetAirportInfo($icao) function

Easy enough I though

now what I cannot do is tie up teh current location icao with teh airport name  :D

here is what I wrote:

<?php $lastreport = PIREPData::GetLastReports($userinfo, 1);
$locname = OperationsData::GetAirportInfo($icao['name']);
$userinfo->pilotid;
$icao->id;
$test = $icao->name;
if(!$lastreport)
{
    $location = $userinfo->hub;
}
else
{
    $location = $lastreport->arricao;
}
?>

<li><strong>Current Location: </strong><?php echo $location; ?> - <?php echo $test; ?></li>

I also tried shifting teh position and did teh following:

<?php
$lastreport = PIREPData::GetLastReports($userinfo, 1);
if(!$lastreport)
{
    $location = $userinfo->hub;
}
else
{
    $location = $lastreport->arricao;
}
$locname = OperationsData::GetAirportInfo($icao['name']);
$userinfo->pilotid;
$icao->id;
$test = $icao->name;

?>

<li><strong>Current Location: </strong><?php echo $location; ?> - <?php echo $test; ?></li

Would you mind giving me an example of teh print_r / Var_dump and how it works.

I either get null or all I get it what I oput inside teh bracket, almost like teh echo command

How far off am I in understanding your code? ;D ;D

  • Administrators
Posted

Sure, first thing, everything is returned as objects from the API, unless there's multiple rows.

We can check out GetLastReports()

It's plural, so it'll return a list.

So we can do (I'm just using 1 to return the reports from user number 1)

<?php
$lastreport = PIREPData::GetLastReports(1, 1);
print_r($lastreport);

Which will show this:

stdClass Object
(
    [pirepid] => 65
    [pilotid] => 1
    [code] => ABC
    [flightnum] => 38
    [depicao] => LFPG
    [arricao] => KJFK
    [aircraft] => 4
    [flighttime] => 5.3
    [distance] => 0
    [submitdate] => 2008-12-21 10:04:16
    [accepted] => 2
    [log] => 
    [load] => 24000
    [price] => 5
    [flighttype] => C
    [pilotpay] => 120
)

We can see it says "stdClass Object", so it returned an object

So now we can do:

<?php
echo $lastreport->depicao; /// Will say "LFPG"
?>

Now let's return the last 2 reports..

<?php
$lastreport = PIREPData::GetLastReports(1, 2);
print_r($lastreport);

Which will echo out:

Array
(
    [list][*] => stdClass Object[/list]
        (
            [pirepid] => 65
            [pilotid] => 1
            [code] => ABC
            [flightnum] => 38
            [depicao] => LFPG
            [arricao] => KJFK
            [aircraft] => 4
            [flighttime] => 5.3
            [distance] => 0
            [submitdate] => 2008-12-21 10:04:16
            [accepted] => 2
            [log] => 
            [load] => 24000
            [price] => 5
            [flighttype] => C
            [pilotpay] => 120
        )

    [1] => stdClass Object
        (
            [pirepid] => 61
            [pilotid] => 1
            [code] => ABC
            [flightnum] => 4004
            [depicao] => KORD
            [arricao] => KDTW
            [aircraft] => 2
            [flighttime] => 5.3
            [distance] => 0
            [submitdate] => 2008-11-30 20:25:35
            [accepted] => 1
            [log] => 
            [load] => 77
            [price] => 140
            [flighttype] => P
            [pilotpay] => 120
        )

)

This one says "Array", and there's results in  => ..., and [1] => ..., meaning the first value (0) has the first report, then the second (1) has the second report. Numbering starts from 0

Now do mess with this we do:

<?php
// This will loop through each one, and assign each report, one 
// at a time, to $report
foreach($lastreport as $report)
{
     // Now we use $report as a normal object
     echo $report->depicao .'<br />';
}

Which will output:

LFPG
KORD

All the API functions operate this way

Hopefully that helps!

Posted

ok that sounds good. I cant say I can put it into practice yet  :'(

Obviously I have now got all the information. I have exactly where the pilot is . It displays the correct Icao code for his arrival airport. If he is a new pilot and has not flown yet, then his default hub location shows.

Now What I am trying to do is more complicated. I have spent most of this afternoon trying, but I simple cannot get the information teh way I want it

I am now using this code to retive all the airport information:

$airports = OperationsData::GetAllAirports();

I print_r that info and get the entire list.

I cannot only extract the names like your example, and I think this has to do with teh fact that there are multiple field, hence having to use the foreach command

So now I have a list of all the airport names, now here come teh dumb question!!!

How do I ty those names up with teh location Icao.

I.e I have a result that tells me where the pilot is now located, I now want to write that icao code as well as that specific airport name

If I try a foreach comman as follows (my wierd logic - please excuse)

foreach($location as $airportloaction)
{
echo $airportlocation->name;
}

That resurns a result Invalid argument supplied for foreach()

In english I would have said select teh airport name where $location - $airporticao

But that does not work either  ;D ;D

Why can I simply not tie them together, am I being too complicated??

  • Administrators
Posted

You would use:

$airport_info = OperationsData::GetAirportInfo ($icao);

Using the proper $icao variable, of course

Also, you have a mispelling:

foreach($location as $airportloaction)

{

  echo $airportlocation->name;

}

Posted

I am a real dumb$#@

I tried what you suggested and still could not get it right. I had used teh $icao to get data and I kept on getting zero results.

Back and forth back and forth, but no joy.

Untill it suddenly dawned on me, Literally as I was replying to yiou post (with other feedback than what I am writing now)

The command

$airport_info = OperationsData::GetAirportInfo($icao);

Cannot be written exactly as that, somehow I need to parse what teh actual icao code is  ??? ??? :'( aarrrggg I cant believ I never saw that.

So I moved teh lines below teh $location statement and instead of using $icao i use $location, getting teh data form the previous array. I did not even have to use teh foreach statement as teh result was not plural at all.

so now after an etire day of stupidity teh light buld suddenlt switches on.

Nabeel I apologise that you had to struggle this way with me, lets hope teh light buld stays on for a little while longer  ;D

So now this is what teh complete code looks like:

<?php
$lastreport = PIREPData::GetLastReports($userinfo, 1);

if(!$lastreport)
{
    $location = $userinfo->hub;
}
else
{
    $location = $lastreport->arricao;
}

?>
<?php
$airport_info = OperationsData::GetAirportInfo($location);

   $airportname = $airport_info->name;
?>

<li><strong>Current Location: </strong><?php echo $location; ?> - <?php echo $airportname; ?></li>

For anyone who wishes to use it.

Whats teh difference

Teh previos correct code with only show teh result as teh icao code. This new code will show teh icao code as well as teh associated airport name i.e

FAPN - Pilansburg

Now just to get my spelling correct

  • 6 months later...
Posted

HI

I have a problem with Pilot location . since i added pilot location in public profile , current location show current location for pilot id 1 for all pilot.

I want show current location for each pilot in public profile and main profile !

Thank you

  • Administrators
Posted

You would use the same method as above, in each of those places. You alreayd have the pilot's information, so it's a matter of calling the getlastpirep

  • 5 months later...
Posted

Thanks for posting this,

Having installed the landings stats mod, ive implemented the code to allow the arrival ICAO be displayed as the Airports Name instead.... Just to make it easier for those who arnt sure on what airport the icao stands for....

btw Sorry to "bump/reply" to an old thread, but wanted to say thank you :)

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