Exemplo n.º 1
0
 public function executeAjaxDeletePersonalFlight(sfWebRequest $request)
 {
     if (!$this->getUser()->hasCredential(array('Administrator', 'Pilot', 'Staff'), false)) {
         $this->getUser()->setFlash("warning", 'You don\'t have permission to access this url ' . $request->getReferer());
         $this->redirect('dashboard/index');
     }
     $personal_flight = PersonalFlightPeer::retrieveByPK($request->getParameter('id'));
     $this->forward404Unless($personal_flight);
     $this->forward404Unless($personal_flight->getPilotId() == $this->getUser()->getPilotId());
     $personal_flight->delete();
     return sfView::NONE;
 }
Exemplo n.º 2
0
 /**
  * Match according to personal flights of pilot
  * @param <type> $id
  * @param <type> $max
  * @param <type> $page
  * @return sfPropelPager
  */
 public static function getByFilterPF($id, $max = 10, $page = 1)
 {
     $personal_flight = PersonalFlightPeer::retrieveByPK($id);
     if (!$id or !isset($personal_flight)) {
         return null;
     }
     $c = new Criteria();
     $c->addAscendingOrderByColumn(self::MISSION_ID);
     $c->addJoin(self::MISSION_ID, MissionPeer::ID, Criteria::LEFT_JOIN);
     $c->addJoin(MissionPeer::MISSION_TYPE_ID, MissionTypePeer::ID, Criteria::LEFT_JOIN);
     $c->addJoin(self::ID, PilotRequestPeer::LEG_ID, Criteria::LEFT_JOIN);
     //airport
     $c->addAlias('c1', AirportPeer::TABLE_NAME);
     $c->addAlias('c2', AirportPeer::TABLE_NAME);
     $c->addJoin(self::FROM_AIRPORT_ID, AirportPeer::alias('c1', AirportPeer::ID), Criteria::LEFT_JOIN);
     $c->addJoin(self::TO_AIRPORT_ID, AirportPeer::alias('c2', AirportPeer::ID), Criteria::LEFT_JOIN);
     $criterion = $c->getNewCriterion(MissionPeer::MISSION_DATE, date('Y-m-d', strtotime($personal_flight->getDepartureDate())) . '%', Criteria::LIKE);
     $criterion->addAnd($c->getNewCriterion(AirportPeer::alias('c1', AirportPeer::CITY), '%' . $personal_flight->getOriginCity() . '%', Criteria::LIKE));
     $criterion->addAnd($c->getNewCriterion(AirportPeer::alias('c2', AirportPeer::CITY), '%' . $personal_flight->getDestinationCity() . '%', Criteria::LIKE));
     $criterion->addAnd($c->getNewCriterion(AirportPeer::alias('c1', AirportPeer::ZIPCODE), '%' . $personal_flight->getOriginZipcode() . '%', Criteria::LIKE));
     $criterion->addAnd($c->getNewCriterion(AirportPeer::alias('c2', AirportPeer::ZIPCODE), '%' . $personal_flight->getDestinationZipcode() . '%', Criteria::LIKE));
     $criterion2 = $c->getNewCriterion(AirportPeer::alias('c2', AirportPeer::CITY), $personal_flight->getOriginCity());
     $criterion2->addAnd($c->getNewCriterion(AirportPeer::alias('c1', AirportPeer::CITY), $personal_flight->getDestinationCity()));
     $criterion2->addAnd($c->getNewCriterion(MissionPeer::MISSION_DATE, date('Y-m-d', strtotime($personal_flight->getReturnDate())) . '%', Criteria::LIKE));
     $criterion2->addAnd($c->getNewCriterion(AirportPeer::alias('c2', AirportPeer::ZIPCODE), '%' . $personal_flight->getOriginZipcode() . '%', Criteria::LIKE));
     $criterion2->addAnd($c->getNewCriterion(AirportPeer::alias('c1', AirportPeer::ZIPCODE), '%' . $personal_flight->getDestinationZipcode() . '%', Criteria::LIKE));
     $criterion->addOr($criterion2);
     $c->add($criterion);
     $c->add(self::MISSION_REPORT_ID, null, Criteria::ISNULL);
     $c->add(PilotRequestPeer::PILOT_TYPE, 'Command Pilot', Criteria::NOT_EQUAL);
     $criterion = $c->getNewCriterion(PilotRequestPeer::PROCESSED, 0, Criteria::EQUAL);
     $criterion->addOr($c->getNewCriterion(PilotRequestPeer::ID, null, Criteria::ISNULL));
     $c->add($criterion);
     MissionLegPeer::addSelectColumns($c);
     /*
         $c->addAsColumn('distance', 'Round(ACos(Sin(Radians(c1.latitude)) * Sin(Radians(c2.latitude)) + Cos(Radians(c1.latitude)) * Cos(Radians(c2.latitude)) * Cos(Radians(c1.longitude)-Radians(c2.longitude))) * ((180*60)/3.1415),0)');
     
         //EFFECIENCY
         if ($home_base && $hb_airport = AirportPeer::retrieveByPK($home_base))
         {
               $c->addAsColumn('efficiency', "
               CEILING(ROUND(ACOS(SIN(RADIANS(c1.latitude))
               *SIN(RADIANS(c2.latitude))+COS(RADIANS(c1.latitude))
               *COS(RADIANS(c2.latitude))*COS(RADIANS(c1.longitude)-RADIANS(c2.longitude)))
               *((180*60)/PI()))/(ROUND(ACOS(SIN(RADIANS(c1.latitude))
               *SIN(RADIANS(c2.latitude))+COS(RADIANS(c1.latitude))
               *COS(RADIANS(c2.latitude))
               *
               COS(RADIANS(c1.longitude)-RADIANS(c2.longitude))
                 ) * ((180*60)/PI())
               )
               +
               ROUND(
                 ACOS(
                   SIN(RADIANS({$hb_airport->getLatitude()}))
                   *
                   SIN(RADIANS(c2.latitude))
                   +
                   COS(RADIANS({$hb_airport->getLatitude()}))
                   *
                   COS(RADIANS(c2.latitude))
                   *
                   COS(RADIANS({$hb_airport->getLongitude()})-RADIANS(c2.longitude))
                 ) * ((180*60)/PI())
               )
               +
               ROUND(
                 ACOS(
                   SIN(RADIANS({$hb_airport->getLatitude()}))
                   *
                   SIN(RADIANS(c1.latitude))
                   +
                   COS(RADIANS({$hb_airport->getLatitude()}))
                   *
                   COS(RADIANS(c1.latitude))
                   *
                   COS(RADIANS({$hb_airport->getLongitude()})-RADIANS(c1.longitude))
                 ) * ((180*60)/PI()))) * 200)");
     
           $c->addDescendingOrderByColumn('efficiency');
         }
     
         $c->addDescendingOrderByColumn('distance');
     */
     //    return self::doSelect($c);
     $pager = new sfPropelPager('MissionLeg', $max);
     $pager->setCriteria($c);
     $pager->setPage($page);
     $pager->init();
     return $pager;
 }