Ejemplo n.º 1
0
 /**
  * Add/edit a pilot
  * CODE: pilot_create
  */
 public function executeUpdate(sfWebRequest $request)
 {
     if (!$this->getUser()->hasCredential(array('Administrator', 'Staff', 'Pilot', 'Coordinator', 'Volunteer'), false)) {
         $this->getUser()->setFlash("warning", 'You don\'t have permission to access this url ' . $request->getReferer());
         $this->redirect('dashboard/index');
     }
     if ($request->getParameter('member_id')) {
         $this->member = MemberPeer::retrieveByPK($request->getParameter('member_id'));
         $pilot = new Pilot();
         $this->title = 'Add Pilot';
     }
     if ($request->getParameter('id')) {
         $pilot = PilotPeer::retrieveByPK($request->getParameter('id'));
         $this->forward404Unless($pilot);
         ///ziyed////
         $this->url = $request->getReferer();
         if (strstr($this->url, '/pilot/mopAdd')) {
             $this->title = 'Add mop pilot';
             $success = 'MOP information has been successfully added!';
         } else {
             $this->title = 'Edit pilot';
             $success = 'Pilot information has been successfully changed!';
             $this->current_region = $pilot->getMopRegionsServed();
             $this->mopservedby = $pilot->getMopServedBy();
         }
         ////end//////
         $this->member = MemberPeer::retrieveByPK($pilot->getMemberId());
         if ($pilot->getPrimaryAirportId()) {
             $this->airport_id = $pilot->getPrimaryAirportId();
         }
         $this->airports = AirportPeer::doSelect(new Criteria());
     } else {
         $pilot = new Pilot();
         $this->title = 'Add Pilot';
         $success = 'Pilot information has been successfully created!';
     }
     $this->airport = trim($this->getRequestParameter('airport', '*')) == '' ? '*' : trim($this->getRequestParameter('airport', '*'));
     if ($request->getParameter('leg')) {
         $this->leg_id = $request->getParameter('leg');
     }
     if ($request->getParameter('back')) {
         $this->backup = $request->getParameter('back');
     }
     if ($request->getParameter('co')) {
         $this->backup_co = $request->getParameter('co');
     }
     if ($request->getParameter('member')) {
         $this->member = MemberPeer::retrieveByPK($request->getParameter('member'));
     }
     $this->form = new PilotForm($pilot);
     $this->pilot = $pilot;
     $this->back = $request->getReferer();
     ///////////////////Update ///////////
     if ($request->isMethod('post')) {
         $this->referer = $request->getReferer();
         $this->form->bind($request->getParameter('pilo'));
         if ($this->form->isValid() && $this->form->getValue('license_type')) {
             if ($request->getParameter('member_id')) {
                 $pilot->setMemberId($request->getParameter('member_id'));
             }
             //TODO:Set Member Flight status to command pilot
             $set_member = MemberPeer::retrieveByPK($request->getParameter('member_id'));
             if ($set_member) {
                 $set_member->setFlightStatus('Command pilot');
                 $set_member->save();
             }
             if ($request->getParameter('airport') != null) {
                 $airport = AirportPeer::getByIdent($request->getParameter('airport'));
                 if (isset($airport) && $airport instanceof Airport) {
                     $pilot->setPrimaryAirportId($airport->getId());
                 }
             } else {
                 $pilot->setPrimaryAirportId(null);
                 $member = MemberPeer::retrieveByPK($request->getParameter('member_id'));
                 $member->setFlightStatus('Non-pilot');
                 $member->save();
             }
             $pilot->setSecondaryHomeBases($this->form->getValue('secondary_home_bases'));
             $pilot->setTotalHours($this->form->getValue('total_hours'));
             $pilot->setLicenseType($this->form->getValue('license_type'));
             if ($this->form->getValue('ifr') == null) {
                 $pilot->setIfr(0);
             } else {
                 $pilot->setIfr($this->form->getValue('ifr'));
             }
             if ($this->form->getValue('multi_engine') == null) {
                 $pilot->setMultiEngine(0);
             } else {
                 $pilot->setMultiEngine($this->form->getValue('multi_engine'));
             }
             $pilot->setSeInstructor($this->form->getValue('se_instructor'));
             $pilot->setMeInstructor($this->form->getValue('me_instructor'));
             $pilot->setOtherRatings($this->form->getValue('other_ratings'));
             $pilot->setInsuranceReceived($this->form->getValue('insurance_received'));
             //ziyed task
             $pilot->setOrientedDate($this->form->getValue('oriented_date'));
             $pilot->setMopOrientedDate($this->form->getValue('mop_oriented_date'));
             if ($request->getParameter('pilot_name')) {
                 $pilot->setMopServedBy($request->getParameter('pilot_name'));
             } else {
                 $pilot->setMopServedBy(NULL);
             }
             // $pilot->setMopRegionsServed($request->getParameter('mop_regions_served'));
             if ($request->getParameter('mop_regions_served')) {
                 $pilot->setMopRegionsServed($request->getParameter('mop_regions_served'));
             } else {
                 $a = null;
                 $pilot->setMopRegionsServed($a);
             }
             //$pilot->setOrientedMemberId($this->form->getValue('oriented_member_id'));
             //$pilot->setOrientedMemberId($this->form->getValue('mop_oriented_member_id'));
             //$pilot->setMopQualifications($this->form->getValue('mop_qualifications'));
             $pilot->setHseats($this->form->getValue('hseats'));
             if ($this->form->getValue('transplant') == 1) {
                 $pilot->setTransplant(1);
             } else {
                 $pilot->setTransplant(0);
             }
             $pilot->save();
             $this->getUser()->setFlash('success', $success);
             $last = $request->getParameter('back');
             $back_url = 'pilot';
             if (strstr($last, 'member/view')) {
                 $back_url = '@member_view?id=' . $request->getParameter('member_id');
             } elseif (strstr($last, 'pilot/view')) {
                 $back_url = '@pilot_view?id=' . $pilot->getId();
             } elseif (strstr($last, 'pilot/edit')) {
                 $back_url = '@pilot_view?id=' . $pilot->getId();
             } elseif (strstr($last, 'pilot/mopAdd')) {
                 $back_url = '/pilot/mopAdd';
             }
             if ($request->getParameter('leg_id')) {
                 $back_url = '@leg_edit?id=' . $request->getParameter('leg_id');
             }
             if ($request->getParameter('leg_id')) {
                 if ($request->getParameter('leg_id') && !$request->getParameter('backup')) {
                     $set_leg = MissionLegPeer::retrieveByPK($request->getParameter('leg_id'));
                     if (isset($set_leg) && $set_leg instanceof MissionLeg) {
                         $set_leg->setPilotId($pilot->getId());
                         $set_leg->save();
                         $this->getUser()->setFlash('success', 'Mission Leg #' . $set_leg->getId() . ' \\s Pilot has been set!');
                     }
                     $back_url = '@leg_edit?id=' . $request->getParameter('leg_id');
                 }
             }
             if ($request->getParameter('leg_id')) {
                 if ($request->getParameter('leg_id') && $request->getParameter('backup')) {
                     $set_leg = MissionLegPeer::retrieveByPK($request->getParameter('leg_id'));
                     if (isset($set_leg) && $set_leg instanceof MissionLeg) {
                         $set_leg->setBackupPilotId($pilot->getId());
                         $set_leg->save();
                         $this->getUser()->setFlash('success', 'Mission Leg #' . $set_leg->getId() . ' \\s Backup Pilot has been set!');
                     }
                     $back_url = '@leg_edit?id=' . $request->getParameter('leg_id');
                 }
             }
             if ($request->getParameter('leg_id')) {
                 if ($request->getParameter('leg_id') && $request->getParameter('backup_co')) {
                     $set_leg = MissionLegPeer::retrieveByPK($request->getParameter('leg_id'));
                     if (isset($set_leg) && $set_leg instanceof MissionLeg) {
                         $set_leg->setBackupCopilotId($request->getParameter('member_id'));
                         $set_leg->save();
                         $this->getUser()->setFlash('success', 'Mission Leg #' . $set_leg->getId() . ' \\s Backup Co-Pilot has been set!');
                     }
                     $back_url = '@leg_edit?id=' . $request->getParameter('leg_id');
                 }
             }
             return $this->redirect($back_url);
         } else {
             if (!$request->getParameter('id')) {
                 $info = 'Please confirm License type and choose Member !';
             } else {
                 $info = 'Please confirm License type !';
             }
             $this->getUser()->setFlash('success', $info);
         }
     } else {
         # Set referer URL
         $this->referer = $request->getReferer() ? $request->getReferer() : '@pilot';
     }
     $this->pilot = $pilot;
 }