Jump to content

Landing rates and condition


Jakes

Recommended Posts

  • Replies 94
  • Created
  • Last Reply

Top Posters In This Topic

Guest lorathon

<?php

class Aircraft_Condition extends CodonModule
{

public function __construct() {

	CodonEvent::addListener('Aircraft_Condition');
	parent::__constructor();

}

public function EventListener($eventinfo) {

	if($eventinfo[0] == 'pirep_filed') {

  $pirepinfo = $eventinfo[2];		
	 $aircraft = OperationsData::getAircraftByReg($pirepinfo->registration);

  $pirepinfo->landingrate = intval($pirepinfo->landingrate);

  if($pirepinfo->landingrate < -100 && $pirepinfo->landingrate > -500)
	  $cond = $aircraft->cond -20;
	 else
	  $cond = 100;

	 $update = $this->updateAircraft($aircraft->id, $cond);
	}

}

private function updateAircraft($id, $cond) {

 $sql = 'UPDATE '.TABLE_PREFIX."aircraft
  SET `cond` = '$cond'
  WHERE `id` = '$id'";

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

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

 CodonCache::delete('all_aircraft');
 CodonCache::delete('all_aircraft_enabled');
 CodonCache::delete('all_aircraft_search');
 CodonCache::delete('all_aircraft_search_enabled');

 return true;
}
}

Try the above. I went back again and started from scratch. I have not tested but it follows the documentation on hooking in. The math was also wrong. It was impossible for the if to ever be true. I also added an else just so that you can get some data back into the aircraft table. I also deleted the cache files on successful update. The update may still be able to be handled with the OperationsData:editAircraft function but I just am not sure what the stable phpVMS code looks like anymore.

Link to comment
Share on other sites

Thanks Jeffrey, for your help! I have tested it, with no luck though, and that gave me second thoughts on the event it is based on, named Pirep_filed. Why I am saying this is, when will the condition be updated? when the pilot press the file pirep button, or when it is approved? Secondly, IF it is updated when the pirep is filed, then, with approval, I guess the condition is updated again? so basically two scripts updating the same condition. So I am back to square 1... Where is the initial code that update the condition....

Link to comment
Share on other sites

Guest lorathon

Actually this should only update the table one time. When the pirep is filed. From the API doc there are events fired when a pirep is sent. prefile and file. This script should hook and fire after the pirep filing has completed. Let me see if Nabeel sees the problem here.

Link to comment
Share on other sites

Ok, my question now is this:

in the code below the Aircraft registration is retrieved from the pirep, but the database must write to the ID. now how is the ID coupled to the registration here? Even if you have the pirep read by ID as well, how does the Pirep ID which is

$aircraft->id

connect to the ID in suppose to write to the DB here:

private function updateAircraft($id, $cond) {

the entire code:

<?php
class Aircraft_Condition extends CodonModule
{
public function __construct() {
		    CodonEvent::addListener('Aircraft_Condition');

}
public function EventListener($eventinfo) {

		    if($eventinfo[0] == 'pirep_filed') {

  $pirepinfo = $eventinfo[2];		 
			 $aircraft = OperationsData::getAircraftByReg($pirepinfo->registration);

  if($pirepinfo->landingrate < -100 && $pirepinfo->landingrate > -500)
			  $cond = $aircraft->cond -20;
			 else
			  $cond = 100;

			 $update = $this->updateAircraft($aircraft->id, $cond);
		    }

}
private function updateAircraft($id, $cond) {
 $sql = 'UPDATE '.TABLE_PREFIX."aircraft
  SET `cond` = '$cond'
  WHERE `id` = '$id'";

 $res = DB::query($sql);
 if(DB::errno() != 0)
  return false;

 CodonCache::delete('all_aircraft');
 CodonCache::delete('all_aircraft_enabled');
 CodonCache::delete('all_aircraft_search');
 CodonCache::delete('all_aircraft_search_enabled');

 return true;
}
}

Link to comment
Share on other sites

Guest lorathon

$aircraft = OperationsData::getAircraftByReg($pirepinfo->registration);

The above code retrieves the aircraft row based on the registration supplied in the $pirepinfo. This will include all columns for the aircraft row.

Link to comment
Share on other sites

I have added the changes that Nabeel suggested to the code a couple of post above this. Please try.

what post do you mean #32?

if yes! getting that error with the code

Fatal error: Call to undefined method CodonModule::__constructor() in /home/flyeurop/public_html/core/modules/Aircraft_Condition/Aircraft_Condition.php on line 9

Link to comment
Share on other sites

Guest lorathon

How about this?

<?php
class Aircraft_Condition extends CodonModule
{
public function __construct() {
		    CodonEvent::addListener('Aircraft_Condition');
		    Aircraft_Condition::__constructor();

}
public function EventListener($eventinfo) {

		    if($eventinfo[0] == 'pirep_filed') {

  $pirepinfo = $eventinfo[2];		 
			 $aircraft = OperationsData::getAircraftByReg($pirepinfo->registration);
  $pirepinfo->landingrate = intval($pirepinfo->landingrate);
  if($pirepinfo->landingrate < -100 && $pirepinfo->landingrate > -500)
			  $cond = $aircraft->cond -20;
			 else
			  $cond = 100;

			 $update = $this->updateAircraft($aircraft->id, $cond);
		    }

}
private function updateAircraft($id, $cond) {
 $sql = 'UPDATE '.TABLE_PREFIX."aircraft
  SET `cond` = '$cond'
  WHERE `id` = '$id'";

 $res = DB::query($sql);
 if(DB::errno() != 0)
  return false;

 CodonCache::delete('all_aircraft');
 CodonCache::delete('all_aircraft_enabled');
 CodonCache::delete('all_aircraft_search');
 CodonCache::delete('all_aircraft_search_enabled');

 return true;
}
}

Link to comment
Share on other sites

Hi

From what I understand, one could also use the existing event in the PIREPAdmin php (line 292) and tie an additional listener to it!? The listener (i assume) would be in the module so, how would this be altered in the PIREPAdmin php to give the desired function? Just need a push in the right direction here,

Thanks a ton!

Link to comment
Share on other sites

Guest lorathon

<?php
class Aircraft_Condition extends CodonModule
{
public function __construct() {
		    CodonEvent::addListener('Aircraft_Condition');

}
public function EventListener($eventinfo) {

		    if($eventinfo[0] == 'pirep_filed') {

  $pirepinfo = $eventinfo[2];		 
			 $aircraft = OperationsData::getAircraftByReg($pirepinfo->registration);
  $pirepinfo->landingrate = intval($pirepinfo->landingrate);
  if($pirepinfo->landingrate < -100 && $pirepinfo->landingrate > -500)
			  $cond = $aircraft->cond -20;
			 else
			  $cond = 100;

			 $update = $this->updateAircraft($aircraft->id, $cond);
		    }

}
private function updateAircraft($id, $cond) {
 $sql = 'UPDATE '.TABLE_PREFIX."aircraft
  SET `cond` = '$cond'
  WHERE `id` = '$id'";

 $res = DB::query($sql);
 if(DB::errno() != 0)
  return false;

 CodonCache::delete('all_aircraft');
 CodonCache::delete('all_aircraft_enabled');
 CodonCache::delete('all_aircraft_search');
 CodonCache::delete('all_aircraft_search_enabled');

 return true;
}
}

I have checked out simpilots TopPilots code and the hook is setup the same so I am not sure why this is not working. Are you sure that you have a column in the aircraft table named 'cond'?

I am wondering if the $pirepinfo is actually being filed.

Link to comment
Share on other sites

Hi lorathon,

Would you be able to support my issue (please read up)

I understand that the existing event in the PIREPAdmin php can be used and an additional listener can be tied to this event. The listener as I understand is obviously set up in the module? So, how would I alter the PIREPAdmin php to get the desired result in calculating the aircraft condition and writing/updating to the DB by using the existing event in addition to the additional listener? Just a push in the right direction will be much appreciated. If I need to be more clear, please do tell me :) Thankyou

Link to comment
Share on other sites

Guest lorathon

The best thing would be to edit the PIREPData.class.php file. Not the PIREPAdmin. When a pirep is filed it is routed though this code not the pirepadmin code. That is only used for viewing/editing/deleting/accepting/etc....

Adding the code to change the aircraft condition should be placed into the fileReport function. With that said the easiest way would be to create a module that you would call from the filereport function.

Like create a module named "Aircraft_Condition" with a function of changeCondition($pirepid). In the last line of the filereport before the return you should then be able to call this module and use the pirepid to get all of the information necessary for changing the condition of the aircraft. Doing it this way would require only one line added to the PIREPData::fileReport function.

But once again this would be modifying the base files. Any upgrade of phpVMS would overwrite the changes.

Link to comment
Share on other sites

Hi lorathon,

Thank you for the response. The only reason for my assumption regarding the PIREPAdmin.php is because Mr. David Clark suggested either creating an event or using the existing one that is used to accept pireps. I will get back to you shortly,

Thank you so much

Link to comment
Share on other sites

But once again this would be modifying the base files. Any upgrade of phpVMS would overwrite the changes.

We have many modifications to our site anyway, that is not standard, like Search by Squadron, ect that does not work after the latest update. I do not mind adding it again after an update.

Thanks Jeffrey, Me and redcoals will check it out, and report

Link to comment
Share on other sites

<?php
class Aircraft_Condition extends CodonModule
{
public function __construct() {
			CodonEvent::addListener('Aircraft_Condition');

}
public function EventListener($eventinfo) {

			if($eventinfo[0] == 'pirep_filed') {

  $pirepinfo = $eventinfo[2];		
			 $aircraft = OperationsData::getAircraftByReg($pirepinfo->registration);
  $pirepinfo->landingrate = intval($pirepinfo->landingrate);
  if($pirepinfo->landingrate < -100 && $pirepinfo->landingrate > -500)
			  $cond = $aircraft->cond -20;
			 else
			  $cond = 100;

			 $update = $this->updateAircraft($aircraft->id, $cond);
			}

}
private function updateAircraft($id, $cond) {
 $sql = 'UPDATE '.TABLE_PREFIX."aircraft
  SET `cond` = '$cond'
  WHERE `id` = '$id'";

 $res = DB::query($sql);
 if(DB::errno() != 0)
  return false;

 CodonCache::delete('all_aircraft');
 CodonCache::delete('all_aircraft_enabled');
 CodonCache::delete('all_aircraft_search');
 CodonCache::delete('all_aircraft_search_enabled');

 return true;
}
}

I have checked out simpilots TopPilots code and the hook is setup the same so I am not sure why this is not working. Are you sure that you have a column in the aircraft table named 'cond'?

I am wondering if the $pirepinfo is actually being filed.

yes cond table is aircraft table in DB also the Pirep is filed without Problems ;)

Link to comment
Share on other sites

I seem to be very 'vague' about what's going on here really however, also looking at the top pilots module, I note it functions between itself and its own data.class so, is there no way we could use the code as given above and just create a data.class for this module? Seem to be issues in making a tie from the module to an existing event. I am not too familiar with the codon framework but in general, where and what else would be altered in order for this to work? Also, the setup as given in this thread, is it sure to work in regard to calculating the condition according to the landing rates as well as write to the db? At this stage (and from what I see), it seems to be more of a writing and updating issue.

Link to comment
Share on other sites

I seem to be very 'vague' about what's going on here really however, also looking at the top pilots module, I note it functions between itself and its own data.class so, is there no way we could use the code as given above and just create a data.class for this module? Seem to be issues in making a tie from the module to an existing event. I am not too familiar with the codon framework but in general, where and what else would be altered in order for this to work? Also, the setup as given in this thread, is it sure to work in regard to calculating the condition according to the landing rates as well as write to the db? At this stage (and from what I see), it seems to be more of a writing and updating issue.

Link to comment
Share on other sites

Hi guys, quick update

Spoken with Nabeel and my new understanding ::

In the module code as given above, the closing seems to be completely wrong as the $update is being used. The call to updateAircraft should be replaced with the editAircraft parameter instead!

This said, I am also unsure about the whole sql section belong the actual closing as the API should handle this.

Finally, here is what I have now BUT I am NOT sure about what values I need to include::

OperationsData::editAircraft(array(

  'id' => THE ID

  'cond' => $cond

));

NOW, I am not sure about what should be placed in THE ID ...

Could anyone please check on this for me and give update as I am sure this will have this mod working :) hope this helps,

Waiting for some feedback,

Link to comment
Share on other sites

Guest lorathon

As i stated a few posts ago if you use this, editAircraft will change the minrank to 0. So you must send the min rank also. (Check the code) That said the aircraft row is the id that is needed.

Link to comment
Share on other sites

Thank you for the response, can't remember seeing that post but will go through the thread again :) so, I assume this being done, the mod will work? Also, would you be able to perhaps alter the code and add the editAircraft instead of the updateAircraft?

Ps. What bout the sql section?

Link to comment
Share on other sites

Guest lorathon

After looking over the editAircraft function again you will also have to put the enabled into the updating array also. Otherwise the following will set the aircraft enabled to "0"

if ($data['enabled'] === true || $data['enabled'] == '1')
   $data['enabled'] = 1;
else 
   $data['enabled'] = 0;

Link to comment
Share on other sites

Hi lorathon,

So what you suggest is placing the lines you gave above within the closing (array ??

I don't understand why this is so hard as its simply a matter of getting th event, getting the aircraft, doing the calculations and closing on editAircraft

The code as it is now doesn't throw any errors but still not updating the 'cond' in the database. And, this is closing with the editAircraft. The call is getAircraftByReg instead of getAircraftInfo as shows in an earlier post (also without the sql input)

Any help would be appreciated,

Just a writing/updating issue now it seems

Link to comment
Share on other sites

Guest lorathon

The edit Aircraft function that will be handling the 'cond' update (using the API) will require more information than just the 'cond' and 'id'. If you just send these two pieces of data to the API the API will set the minrank to 0 and enabled to 0. The proper array to send to the API would be as follows.

$params = array (
   'id'    => $aircraft->id,
   'cond'    => $cond,
   'minrank'    => $aircraft->minrank,
   'enabled'    => $aircraft->enabled,
   );
$update = OperationsData::editAircraft($params);

Link to comment
Share on other sites

Hi again lorathon,

Attempted to work with the code above and, still not throwing any errors BUT, still not updating in the database either. Is something set wrong in the code? What could this be? As I understand it could only be the code in the module!? Desperate now hehe :)

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...