예제 #1
0
 /**
  * Add or edit aircraft
  * CODE:aircraft_create
  */
 public function executeUpdate(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');
     }
     sfContext::getInstance()->getConfiguration()->loadHelpers('Partial');
     slot('nav_menu', array('reference', ''));
     if ($request->getParameter('id')) {
         $aircraft = AircraftPeer::retrieveByPK($request->getParameter('id'));
         $this->forward404Unless($aircraft);
         $this->title = 'Edit aircraft';
         $success = 'Aircraft information has been successfully changed!';
     } else {
         $aircraft = new Aircraft();
         $this->title = 'Add aircraft';
         $success = 'Aircraft information has been successfully created!';
     }
     if ($request->getParameter('leg')) {
         $this->leg_id = $request->getParameter('leg');
     }
     $this->form = new AircraftForm($aircraft);
     if ($request->isMethod('post')) {
         $this->referer = $request->getReferer();
         $this->form->bind($request->getParameter('craft'));
         if ($this->form->isValid() && $this->form->getValue('cost')) {
             $aircraft->setMake($this->form->getValue('make'));
             $aircraft->setModel($this->form->getValue('model'));
             $aircraft->setName($this->form->getValue('name'));
             $aircraft->setFaa($this->form->getValue('faa'));
             if ($this->form->getValue('engines') == null) {
                 $aircraft->setEngines(0);
             } else {
                 $aircraft->setEngines($this->form->getValue('engines'));
             }
             if ($this->form->getValue('def_seats') == null) {
                 $aircraft->setDefSeats(0);
             } else {
                 $aircraft->setDefSeats($this->form->getValue('def_seats'));
             }
             $aircraft->setSpeed($this->form->getValue('speed'));
             if ($this->form->getValue('pressurized') == null) {
                 $aircraft->setPressurized(0);
             } else {
                 $aircraft->setPressurized($this->form->getValue('pressurized'));
             }
             $aircraft->setCost($this->form->getValue('cost'));
             $aircraft->setRange($this->form->getValue('range'));
             $aircraft->setAcLoad($this->form->getValue('ac_load'));
             if ($aircraft->isNew()) {
                 $content = $this->getUser()->getName() . ' added new Aircraft: ' . $aircraft->getMakeModel();
                 ActivityPeer::log($content);
             }
             $aircraft->save();
             $this->getUser()->setFlash('success', $success);
             $back = '@aircraft';
             if ($request->getParameter('leg_id')) {
                 $back = '@leg_edit?id=' . $request->getParameter('leg_id');
             }
             return $this->redirect($back);
         }
     } else {
         # Set referer URL
         $this->referer = $request->getReferer() ? $request->getReferer() : '@aircraft';
     }
     $this->aircraft = $aircraft;
 }