Esempio n. 1
0
 /**
  * Agency delete 
  * Check related records and if noting has related it will deleted
  * CODE:airport_delete
  */
 public function executeDelete(sfWebRequest $request)
 {
     # security
     if (!$this->getUser()->hasCredential(array('Administrator'), false)) {
         $this->getUser()->setFlash("warning", 'You don\'t have permission to access this url ' . $request->getReferer());
         $this->redirect('dashboard/index');
     }
     if ($request->isMethod('post')) {
         $this->airport = AirportPeer::retrieveByPK($request->getParameter('id'));
         $is_in_camp = CampPeer::getByAirportId($this->airport->getId());
         $is_in_fbo = FboPeer::getByAirportId($this->airport->getId());
         $is_in_pilot = PilotPeer::getByAirportId($this->airport->getId());
         if ($this->airport->getWingId() || $is_in_camp || $is_in_fbo || $is_in_pilot) {
             if ($is_in_camp) {
                 $reason = 'Camp';
             } elseif ($is_in_fbo) {
                 $reason = 'FBO';
             } elseif ($is_in_pilot) {
                 $reason = 'Pilot';
             }
             $this->getUser()->setFlash('success', 'Can not delete the airport! There is using data in the  ' . $reason . '.');
         } else {
             $this->forward404Unless($this->airport);
             $this->getUser()->setFlash('success', 'Airport information has been successfully deleted!');
             $this->airport->delete();
         }
     }
     return $this->redirect('@airport');
 }