/** * Mission Leg * CODE:mission_leg_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->getParameter('id')) { $suc = ''; $suc2 = ''; $mission_leg = MissionLegPeer::retrieveByPK($request->getParameter('id')); if (isset($mission_leg)) { $has_pilot_req = PilotRequestPeer::getByLegId($mission_leg->getId()); if (isset($has_pilot_req) && $has_pilot_req instanceof PilotRequest) { //try{ $has_pilot_req->delete(); $suc = ' And Pilot request #' . $has_pilot_req->getId() . ' has deleted!'; //}catch (Exception $e){echo "exception-1";} } $has_discussions = DiscussionPeer::getByLegID($mission_leg->getId()); if (isset($has_discussions)) { foreach ($has_discussions as $dis) { //try{ $dis->delete(); //}catch (Exception $e){echo "exception-2";} } $suc2 = ' And Leg\'s Discussion(s) has deleted!'; } } if (isset($mission_leg) && $mission_leg instanceof MissionLeg) { try { $miss_id = $mission_leg->getMissionId(); $miss_leg_d = $mission_leg->getLegNumber(); $mission_leg->delete(); $mission_legs = MissionLegPeer::getbyMissId($miss_id); if ($mission_legs) { foreach ($mission_legs as $mleg) { if ($mleg->getLegNumber() > $miss_leg_d) { $mleg->setLegNumber($mleg->getLegNumber() - 1); $mleg->save(); } } } } catch (Exception $e) { $this->getUser()->setFlash('warning', "There are related persons to this mission leg. Please remove them first."); } $this->getUser()->setFlash('success', 'Missin Leg # ' . $mission_leg->getId() . ' has successfully deleted!' . $suc . $suc2); //}catch (Exception $e){ echo "exception-3";} if ($request->getReferer()) { $this->redirect($request->getReferer()); } else { $this->redirect('leg'); } } } }