Jump to content

Accepting PIREPs - what's updated?


ln-asm

Recommended Posts

Hello everybody!

I've tried to search for this, but I can't seem to find anything...I'm just wondering, what exactly is updated in the database when accepting a PIREP?

What I have so far:

- PIREP status set to 1 (accepted)

- Added hours to pilot's account

- Added number of flights to pilot's account

but is there anything else than this?

Also: is there anyone who knows where I can find the SQL query for pending PIREPs?

Thank you very much for your replies! :)

Anders

Link to comment
Share on other sites

  • Members

I dont know what you want to do but, when you or your acars software send a pirep then a function with the name filepirep is executed

This function is located in PIREPData.class

https://github.com/nshahzad/phpVMS/blob/master/core/common/PIREPData.class.php

And starts from line 547 till line 837 the sql statement is located in line 748

Link to comment
Share on other sites

I was actually thinking more of what happens when you hit the "Accept"-button for pending PIREPs in the administration center, not how the PIREP itself it filed. But it looks like there could be something in this file anyway, I'll try to figure out something! But yeah, if anyone knows exactly which tables and what columns are updated in the database when you accept a PIREP, that'd be highly appreciated :)

Anders

Link to comment
Share on other sites

  • Members

Ok my bad.

This is the Pirepadmin module in admin section

https://github.com/n.../PIREPAdmin.php

in line 298 is function approve_pirep_post where if you put side by side the pirepdata.class you will be able to see what is happening

For example

protected function approve_pirep_post()
{
$pirepid = $this->post->id;

if($pirepid == '') return;

$pirep_details = PIREPData::GetReportDetails($pirepid);

# See if it's already been accepted
if(intval($pirep_details->accepted) == PIREP_ACCEPTED) return;

# Update pilot stats
SchedulesData::IncrementFlownCount($pirep_details->code, $pirep_details->flightnum);
--------------------------------------------------------------------------------------------------------------------------------
public static function IncrementFlownCount($code, $flightnum) /located in schedulesData.class.php
{
$schedid = intval($schedid);

$code = strtoupper($code);
$flightnum = strtoupper($flightnum);

$sql = 'UPDATE '.TABLE_PREFIX."schedules
SET timesflown=timesflown+1
WHERE code='{$code}' AND flightnum='{$flightnum}'";

$res = DB::query($sql);

if(DB::errno() != 0)
return false;

return true;
}

--------------------------------------------------------------------------------------------------------------------------------
PIREPData::ChangePIREPStatus($pirepid, PIREP_ACCEPTED); // 1 is accepted
--------------------------------------------------------------------------------------------------------------------------------
public static function ChangePIREPStatus($pirepid, $status)// located in PIREPData.class.php
{
return self::editPIREPFields($pirepid, array('accepted' => $status));
}
with

public static function editPIREPFields($pirepid, $fields)
{
if(!is_array($fields))
{
return false;
}

$sql = "UPDATE `".TABLE_PREFIX."pireps` SET ";
$sql .= DB::build_update($fields);
$sql .= ' WHERE `pirepid`='.$pirepid;

$res = DB::query($sql);

if(DB::errno() != 0)
{
return false;
}

return true;
}
-------------------------------------------------------------------------------------------------------------------------------------------------------------------

PilotData::UpdateFlightData($pirep_details->pilotid, $pirep_details->flighttime, 1);
PilotData::UpdatePilotPay($pirep_details->pilotid, $pirep_details->flighttime);

RanksData::CalculateUpdatePilotRank($pirep_details->pilotid);
PilotData::GenerateSignature($pirep_details->pilotid);
StatsData::UpdateTotalHours();

LogData::addLog(Auth::$userinfo->pilotid, 'Approved PIREP #'.$pirepid);

# Call the event
CodonEvent::Dispatch('pirep_accepted', 'PIREPAdmin', $pirep_details);
}

end etc

In a summary when you click on accept pirep these functions are executed


$pirep_details = PIREPData::GetReportDetails($pirepid);


# Update pilot stats
SchedulesData::IncrementFlownCount($pirep_details->code, $pirep_details->flightnum);
PIREPData::ChangePIREPStatus($pirepid, PIREP_ACCEPTED); // 1 is accepted
PilotData::UpdateFlightData($pirep_details->pilotid, $pirep_details->flighttime, 1);
PilotData::UpdatePilotPay($pirep_details->pilotid, $pirep_details->flighttime);

RanksData::CalculateUpdatePilotRank($pirep_details->pilotid);
PilotData::GenerateSignature($pirep_details->pilotid);
StatsData::UpdateTotalHours();

LogData::addLog(Auth::$userinfo->pilotid, 'Approved PIREP #'.$pirepid);

# Call the event
CodonEvent::Dispatch('pirep_accepted', 'PIREPAdmin', $pirep_details);

I hope i have solved your questions if not here we are :)

if you want tomorrow i can make a post with the sql queries only

Link to comment
Share on other sites

You might want to look at the DB directly, via PHP-Admin. If you look at the PIREP table it will give you a better visualisation of what gets updated. Of course, as you can see from what Vangelis has shown you, other tables get populated also, such as PIREP comments etc. At least it's easier to see than staring at code!

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