Guest lorathon Posted March 22, 2012 Report Posted March 22, 2012 I will try and do some testing and come up with a good script today.
Guest lorathon Posted March 22, 2012 Report Posted March 22, 2012 <?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.
Jakes Posted March 22, 2012 Author Report Posted March 22, 2012 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....
Guest lorathon Posted March 23, 2012 Report Posted March 23, 2012 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.
Jakes Posted March 23, 2012 Author Report Posted March 23, 2012 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; } }
Guest lorathon Posted March 23, 2012 Report Posted March 23, 2012 $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.
Guest lorathon Posted March 23, 2012 Report Posted March 23, 2012 I have added the changes that Nabeel suggested to the code a couple of post above this. Please try.
Txmmy83 Posted March 24, 2012 Report Posted March 24, 2012 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
Guest lorathon Posted March 24, 2012 Report Posted March 24, 2012 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; } }
redcoals Posted March 25, 2012 Report Posted March 25, 2012 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!
Txmmy83 Posted March 26, 2012 Report Posted March 26, 2012 gives that error Fatal error: Call to undefined method Aircraft_Condition::__constructor() in /home/flyeurop/public_html/core/modules/Aircraft_Condition/Aircraft_Condition.php on line 6
Guest lorathon Posted March 26, 2012 Report Posted March 26, 2012 <?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.
redcoals Posted March 26, 2012 Report Posted March 26, 2012 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
Guest lorathon Posted March 27, 2012 Report Posted March 27, 2012 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.
redcoals Posted March 27, 2012 Report Posted March 27, 2012 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
Jakes Posted March 27, 2012 Author Report Posted March 27, 2012 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
Txmmy83 Posted March 27, 2012 Report Posted March 27, 2012 <?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
redcoals Posted March 27, 2012 Report Posted March 27, 2012 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.
redcoals Posted March 27, 2012 Report Posted March 27, 2012 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.
redcoals Posted March 27, 2012 Report Posted March 27, 2012 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,
Guest lorathon Posted March 27, 2012 Report Posted March 27, 2012 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.
redcoals Posted March 27, 2012 Report Posted March 27, 2012 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?
redcoals Posted March 27, 2012 Report Posted March 27, 2012 Hi lorathon, Found the code so going to do a few tests and will report back, Hold thumbs Thank you for your support
Guest lorathon Posted March 27, 2012 Report Posted March 27, 2012 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;
redcoals Posted March 27, 2012 Report Posted March 27, 2012 So this I will add below the updating line? Just as given above? If so, I will do so and report back hoping to achieve something, Your help is much appreciated lorathon
redcoals Posted March 27, 2012 Report Posted March 27, 2012 For some reason I think I am completely misunderstanding yor last post lorathon, So sorry but could you please be more specific
redcoals Posted March 28, 2012 Report Posted March 28, 2012 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
Guest lorathon Posted March 28, 2012 Report Posted March 28, 2012 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);
redcoals Posted March 28, 2012 Report Posted March 28, 2012 Hi lorathon, Thank you so much for thi It makes sense so i will add it to the code and give it a try Tested earlier on using the editAircraft and we had no errors however, still no update. Will report back
redcoals Posted March 28, 2012 Report Posted March 28, 2012 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
Recommended Posts