/** * Request a group Missions * CODE:mission_request_group_create */ public function executeRequestGroupMission(sfWebRequest $request) { #security 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'); } $camp = CampPeer::retrieveByPK($request->getParameter('id')); if (isset($camp) && $camp instanceof Camp) { $this->camp_id = $camp->getId(); $missions = MissionPeer::getByCampId($camp->getId()); } $this->dates = array(); $this->home_base = null; $this->number_of_seats = null; $this->total_carry = null; $this->multi_pick = null; $this->date_choice = null; $this->comment = null; $this->request_as = null; $this->acc_cre = null; $this->pilot_ma = null; $this->IFR = null; $this->aircraft = null; $this->tail = null; $this->other_pilot = null; $miss_dates = array(); //$appt_dates = array(); //$count = 0; //$count2 = 0; foreach ($missions as $mission) { if ($mission->getMissionDate()) { $miss_dates[$mission->getMissionDate('m/d/Y')] = $mission->getMissionDate(); //$count++; //it may change $this->mission_date = $mission->getMissionDate(); $this->appt_date = $mission->getApptDate(); // } /* if($mission->getApptDate()){ $appt_dates[$count2] = $mission->getApptDate(); $count2++; }*/ $miss_id = $mission->getId(); } $this->mission_dates = array(); $this->mission_dates = $miss_dates; if (isset($miss_id)) { $legs = MissionLegPeer::getbyMissId($miss_id); $this->mission = MissionPeer::retrieveByPK($miss_id); foreach ($legs as $leg) { if ($leg->getToAirportId()) { $this->leg = $leg; $airport = AirportPeer::retrieveByPK($leg->getToAirportId()); if (isset($airport) && $airport instanceof Airport) { $this->destination_airport = $airport; } } } } /* if(isset($miss_dates[$count-1])){ $this->mission_date = $miss_dates[$count-1]; } if(isset($appt_dates[$count2-1])){ $this->appt_date = $appt_dates[$count2-1]; } */ //$this->mission_leg = MissionLegPeer::retrieveByPK($request->getParameter('id')); $member = MemberPeer::getByPersonId($this->getUser()->getId()); if (isset($member)) { $this->pilot = PilotPeer::getByMemberId($member->getId()); $this->pilot_aircrafts = PilotAircraftPeer::getByMemberId($member->getId()); $this->pre_requests = PilotRequestPeer::getByMemnerIdLegIdCamp($member->getId(), $this->leg->getId()); } if ($request->isMethod('post')) { if ($request->getParameter('id')) { //set post variables $this->dates = $request->getParameter('dates[]', array()); $this->home_base = $request->getParameter('home_base'); $this->number_of_seats = $request->getParameter('number_of_seats'); $this->total_carry = $request->getParameter('total_carry'); $this->multi_pick = $request->getParameter('multi_pick'); $this->date_choice = $request->getParameter('date_choice'); $this->comment = $request->getParameter('comment'); $this->request_as = $request->getParameter('request_as'); $this->acc_cre = $request->getParameter('acc_cre'); $this->pilot_ma = $request->getParameter('pilot_ma'); $this->IFR = $request->getParameter('IFR'); $this->aircraft = $request->getParameter('aircraft'); $this->tail = $request->getParameter('tail'); $this->other_pilot = $request->getParameter('other_pilot'); if (count($this->dates) > 0 && $request->getParameter('home_base') && $request->getParameter('number_of_seats') && $request->getParameter('total_carry')) { //check if this pilot requested this camp already? $c = $has_requested = PilotRequestPeer::getByMemberIdCampId($member->getId(), $request->getParameter('camp_id')); if (!$has_requested) { $pilot_request = new PilotRequest(); if ($member) { $pilot_request->setMemberId($member->getId()); } $pilot_request->setGroupCampId($request->getParameter('camp_id')); if ($request->getParameter('home_base')) { $airport_hb = AirportPeer::getByIdent($request->getParameter('home_base')); if (isset($airport_hb) && $airport_hb instanceof Airport) { $pilot_request->setHomeBase($airport_hb->getIdent()); } else { $this->getUser()->setFlash('warning', 'Home Base is not found!'); $this->redirect($request->getReferer()); } } if ($request->getParameter('number_of_seats')) { if (is_integer((int) $request->getParameter('number_of_seats'))) { $pilot_request->setNumberSeats((int) $request->getParameter('number_of_seats')); } else { $this->getUser()->setFlash('warning', 'Number of seats is in wrong format!'); $this->redirect($request->getReferer()); } } if ($request->getParameter('total_carry')) { if (is_int((int) $request->getParameter('total_carry'))) { $pilot_request->setTotalWeight((int) $request->getParameter('total_carry')); } else { $this->getUser()->setFlash('success', 'Total of carry value is in wrong format!'); $this->redirect($request->getReferer()); } } $pilot_request->setMultiplePick($request->getParameter('multi_pick')); $pilot_request->save(); if (count($this->dates) > 0) { #check is has Pilot Date //$has_pilot_date = PilotDatePeer::getByMemberId($member->getId()); for ($y = 0; $y < count($this->dates); $y++) { $pilot_date = new PilotDate(); $pilot_date->setMemberId($member->getId()); $pilot_date->setDate($this->dates[$y]); $pilot_date->setPilotRequestId($pilot_request->getId()); $pilot_date->save(); } } if (count($this->dates) == 0) { $pilot_request->setDate($this->dates[0]); } $pilot_request->setNumberDateAssign($request->getParameter('date_choice', 1)); $pilot_request->setPilotType($request->getParameter('request_as')); $pilot_request->setComment($request->getParameter('comment')); $pilot_request->setAircraftId($request->getParameter('aircraft')); $pilot_request->setTail($request->getParameter('tail')); //check pilot_type if ($request->getParameter('other_pilot') == 1) { ////mission assistant,earth angel $pilot_request->setMissionAssistantWanted(0); $pilot_request->setIfrBackupWanted(0); $pilot_request->setAccepted(0); $pilot_request->setProcessed(0); $pilot_request->setOnHold(0); } else { ////command pilot $pilot_request->setProcessed(1); if ($request->getParameter('acc_cre') == 1) { $pilot_request->setMissionAssistantWanted(0); #set pilot as mission assistant if ($member->getPerson()) { $pilot_request->setMissionAssistantName($member->getPerson()->getLastName() . ' ' . $member->getPerson()->getFirstName()); } } else { $pilot_request->setMissionAssistantWanted(0); #set pilot's mission assistant as mission assistant if ($request->getParameter('pilot_ma')) { $pilot_request->setMissionAssistantName($request->getParameter('pilot_ma')); } } if ($request->getParameter('IFR') == 0) { $pilot_request->setIfrBackupWanted(0); } else { $pilot_request->setIfrBackupWanted(1); } } $pilot_request->setCreatedAt(date('m/d/y')); $pilot_request->save(); $this->getUser()->setFlash('success', 'Your request has been saved on Camp ID#' . $request->getParameter('camp_id')); // $this->redirect('@pilot_thanks?id='.$request->getParameter('id')); } else { $this->getUser()->setFlash('success', 'You have already requested this Camp Mission!'); // $this->redirect('@pilot_thanks?id='.$request->getParameter('id')); } } else { if (count($this->dates) < 1) { $this->date_other_e = 1; $this->type = $request->getParameter('request_as'); } if (!$request->getParameter('home_base')) { $this->home = 1; } if (!$request->getParameter('number_of_seats')) { $this->number_of = 1; } if (!$request->getParameter('total_carry')) { $this->carry = 1; } } } } }