Example #1
0
 /**
  * Create a aircraft
  * @param array $params
  * @return mixed
  */
 public static function create($params)
 {
     if (!empty($params)) {
         $aircraft = new Aircraft();
         $aircraft->name = $params['name'];
         $aircraft->type_id = $params['type_id'];
         $aircraft->status_id = $params['status_id'];
         $aircraft->save();
         $aircraft->refresh();
         return $aircraft->id;
     }
     return false;
 }
Example #2
0
 function topAircraft()
 {
     $other = 0;
     $result = array();
     $names = array();
     $chart = array();
     $counter = $this->query()->select(DB::raw('aircraft_id, count(aircraft_id) as counter'))->groupBy('aircraft_id')->where('aircraft_id', '!=', '')->whereNotNull('aircraft_id')->orderBy('counter', 'DESC')->lists('counter', 'aircraft_id');
     if (count($counter) > 0) {
         $namesRaw = Aircraft::whereIn('code', array_slice(array_keys($counter), 0, 5))->get();
         foreach ($namesRaw as $aircraft) {
             $names[$aircraft->code][] = $aircraft;
         }
         $other = $this->_total - array_sum($counter);
     }
     foreach ($counter as $key => $flights) {
         if (count($result) < 5 && array_key_exists($key, $names)) {
             $percentage = $this->_total == 0 ? 0 : number_format($flights / $this->_total * 100, 1);
             $result[] = array('data' => $names[$key], 'count' => $flights, 'percent' => $percentage, 'key' => $key);
             if ($percentage > 0) {
                 $chart[] = [$key, $percentage];
             }
         } else {
             $other += $flights;
         }
     }
     $result['Other'] = array('count' => $other, 'percent' => $this->_total == 0 ? 0 : number_format($other / $this->_total * 100, 1), 'key' => 'Other');
     $chart[] = ['Other', $result['Other']['percent']];
     $piechartData = piechartData($chart);
     return array('table' => $result, 'chart' => $piechartData['javascript'], 'colours' => $piechartData['colours']);
 }
Example #3
0
 public function editAction()
 {
     $id = $this->_request->getParam("id");
     $data = Aircraft::findById($id);
     $form = new Form_AircraftEdit();
     $form->name->setValue($data['name']);
     $form->type_id->addMultiOptions(App_Utils::toList(AircraftType::findAll(), 'id', 'type'));
     $form->status_id->setMultiOptions(App_Utils::toList(AircraftStatus::findAll(), 'id', 'status'));
     $form->type_id->setValue($data['type_id']);
     $form->aircraft_id->setValue($id);
     $form->populate($data);
     $options = array('title' => "Edit aircraft", 'url' => "/aircraft/edit/format/json/subaction/submit", 'button' => "Edit", 'success' => array("button" => array("title" => "Close", "action" => "close"), "redirect" => "/aircraft/index", "message" => "Aircraft {$form->name->getValue} modified correctly"), 'model' => array("class" => "Aircraft", "method" => "edit"));
     $this->ajaxFormProcessor($form, $options);
 }
Example #4
0
 public function editAction()
 {
     $id = $this->_request->getParam("id");
     $data = User::findById($id);
     $userAircrafts = App_Utils::toList($data['Aircraft'], "id", "id");
     $form = new Form_UserEdit();
     $form->role_id->addMultiOptions(App_Utils::toList(AclRole::findAll(), 'id', 'name'));
     $form->aircraft->setMultiOptions(App_Utils::toList($data['Aircraft'], 'id', 'name'));
     $form->aircraft_available->setMultiOptions(App_Utils::toList(Aircraft::findAll(array('exclude' => $userAircrafts)), 'id', 'name'));
     $form->role_id->setValue($data['role_id']);
     $form->user_id->setValue($id);
     $form->populate($data);
     $options = array('title' => "Edit User", 'url' => "/user/edit/format/json/subaction/submit", 'button' => "Edit", 'success' => array("button" => array("title" => "Close", "action" => "close"), "redirect" => "/user/list", "message" => "User {$form->first_name->getValue()} {$form->last_name->getValue()} modified correctly"), 'model' => array("class" => "User", "method" => "edit"));
     $this->ajaxFormProcessor($form, $options);
 }
Example #5
0
 /**
  * Declares an association between this object and a Aircraft object.
  *
  * @param      Aircraft $v
  * @return     MissionReport The current object (for fluent API support)
  * @throws     PropelException
  */
 public function setAircraft(Aircraft $v = null)
 {
     if ($v === null) {
         $this->setAircraftId(NULL);
     } else {
         $this->setAircraftId($v->getId());
     }
     $this->aAircraft = $v;
     // Add binding for other direction of this n:n relationship.
     // If this object has already been added to the Aircraft object, it will not be re-added.
     if ($v !== null) {
         $v->addMissionReport($this);
     }
     return $this;
 }
Example #6
0
 /**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database.  In some cases -- especially when you override doSelect*()
  * methods in your stub classes -- you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by doSelect*()
  * and retrieveByPK*() calls.
  *
  * @param      Aircraft $value A Aircraft object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(Aircraft $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getId();
         }
         // if key === null
         self::$instances[$key] = $obj;
     }
 }
Example #7
0
 public function getAircraftName()
 {
     $aircraft = Aircraft::model()->findByAttributes(array('nIataCode' => strtolower($this->aircraftCode)));
     if ($aircraft) {
         return $aircraft->fullTitle;
     }
     return '';
 }
 public function indexAction()
 {
     $this->_addHeadTitle("Aircraft list");
     $this->view->aircrafts = Aircraft::findAll();
 }
Example #9
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;
 }
Example #10
0
 public static function edit($params)
 {
     if (!empty($params)) {
         $user = Doctrine::getTable("User")->findOneById($params['user_id']);
         $user->id = $params['user_id'];
         $user->first_name = $params['first_name'];
         $user->last_name = $params['last_name'];
         if (isset($params['role_id'])) {
             $user->role_id = $params['role_id'];
         }
         $user->language = $params['language'];
         if (!empty($params['aircraft']) || !empty($params['aircraft_available'])) {
             $params['aircraft'] = isset($params['aircraft']) ? $params['aircraft'] : array();
             $params['aircraft_available'] = isset($params['aircraft_available']) ? $params['aircraft_available'] : array();
             Aircraft::deleteUserAircrafts($user->id, $params['aircraft']);
             foreach ($params['aircraft_available'] as $aircraft) {
                 $user->Aircraft[] = Doctrine::getTable("Aircraft")->findOneById($aircraft);
             }
         }
         $user->save();
         return $user->id;
     }
     return false;
 }
Example #11
0
 public function outputUnit()
 {
     $ac = new Aircraft();
     $ac->build();
     return $ac;
 }