Ejemplo n.º 1
0
 /**
  * Mission
  * CODE:mission_create
  */
 public function executeEdit(sfWebRequest $request)
 {
     #security
     if (!$this->getUser()->hasCredential(array('Administrator', 'Staff', 'Coordinator'), false)) {
         $this->getUser()->setFlash("warning", 'You don\'t have permission to access this url ' . $request->getReferer());
         $this->redirect('dashboard/index');
     }
     if ($request->getParameter('id')) {
         $this->mission = MissionPeer::retrieveByPK($request->getParameter('id'));
     }
     //ziyed edited
     $itine = ItineraryPeer::retrieveByPk($this->mission->getItineraryId());
     $this->itine = $itine;
     $this->passenger = PassengerPeer::retrieveByPK($this->mission->getPassengerId());
     $this->passenger_a = $this->passenger && $this->passenger->getPerson() ? $this->passenger->getPerson()->getName() : '';
     $this->requester = RequesterPeer::retrieveByPK($this->mission->getRequesterId());
     $this->requester_a = $this->requester && $this->requester->getPerson() ? $this->requester->getPerson()->getName() : '';
     $this->agency = AgencyPeer::retrieveByPK($this->mission->getAgencyId());
     $this->agencyName = $this->agency ? $this->agency->getName() : '';
     $this->camp = CampPeer::retrieveByPK($this->mission->getCampId());
     $this->campName = $this->camp ? $this->camp->getCampName() : '';
     //end of ziyed
     $this->form = new MissionForm($this->mission);
     $this->referer = $request->getReferer();
     if ($request->isMethod('post')) {
         $this->form->bind($request->getParameter('mission_edit'));
         $this->referer = $request->getReferer();
         /*$errors = $this->form->getErrorSchema()->getErrors();
           if (count($errors) > 0)
           echo 'List of Errors:' . '<br>';
           {
           foreach ($errors as $name => $error)
           {
           echo $name . ': ' . $error . '<BR>';
           }
           }*/
         if ($this->form->isValid()) {
             $this->mission->setMissionTypeId($this->form->getValue('mission_type_id'));
             $this->mission->setMissionDate($this->form->getValue('mission_date'));
             $this->mission->setDateRequested($this->form->getValue('date_requested'));
             $pass = PassengerPeer::retrieveByPK($this->form->getValue('passenger_id'));
             if (isset($pass)) {
                 $this->mission->setPassengerId($pass->getId());
             }
             $req = RequesterPeer::retrieveByPK($this->form->getValue('requester_id'));
             if ($req) {
                 $this->mission->setRequesterId($req->getId());
             }
             if ($this->form->getValue('agency_id') == 0) {
                 $this->mission->setAgencyId(null);
             } else {
                 $this->mission->setAgencyId($this->form->getValue('agency_id'));
             }
             if ($this->form->getValue('camp_id') == 0) {
                 $this->mission->setCampId(null);
             } else {
                 $this->mission->setCampId($this->form->getValue('camp_id'));
             }
             $coor = CoordinatorPeer::retrieveByPK($this->form->getValue('coordinator_id'));
             if (isset($coor)) {
                 $this->mission->setCoordinatorId($coor->getId());
             }
             $itId = ItineraryPeer::retrieveByPK($this->mission->getItineraryId());
             $mLeg = MissionLegPeer::getAllMissionLegByMissionId($request->getParameter('id'));
             $countLeg = MissionLegPeer::getMissionLegByMissionIdCount($request->getParameter('id'));
             $this->mission->setApptDate($this->form->getValue('appt_date'));
             $this->mission->setFlightTime($this->form->getValue('flight_time'));
             $this->mission->setTreatment($this->form->getValue('treatment'));
             $this->mission->setComment($this->form->getValue('comment'));
             $this->mission->setAppointment($this->form->getValue('appointment'));
             $this->mission->setMissionSpecificComments($this->form->getValue('mission_specific_comments'));
             if ($this->form->getValue('cancel_mission') == 0) {
                 if (isset($countLeg)) {
                     foreach ($mLeg as $ml) {
                         $ml->setCancelMissionLeg(0);
                         $ml->save();
                     }
                 }
             }
             $this->mission->setCancelMission($this->form->getValue('cancel_mission'));
             $this->mission->save();
             $this->getUser()->setFlash('success', 'Mission has succesfully edited!');
             $this->redirect('@mission_view?id=' . $this->mission->getId());
         }
     }
 }