Esempio 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;
 }
Esempio n. 2
0
 /**
  * Returns the number of related PersonalFlight objects.
  *
  * @param      Criteria $criteria
  * @param      boolean $distinct
  * @param      PropelPDO $con
  * @return     int Count of related PersonalFlight objects.
  * @throws     PropelException
  */
 public function countPersonalFlights(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
 {
     if ($criteria === null) {
         $criteria = new Criteria(PilotPeer::DATABASE_NAME);
     } else {
         $criteria = clone $criteria;
     }
     if ($distinct) {
         $criteria->setDistinct();
     }
     $count = null;
     if ($this->collPersonalFlights === null) {
         if ($this->isNew()) {
             $count = 0;
         } else {
             $criteria->add(PersonalFlightPeer::PILOT_ID, $this->id);
             $count = PersonalFlightPeer::doCount($criteria, $con);
         }
     } else {
         // criteria has no effect for a new object
         if (!$this->isNew()) {
             // the following code is to determine if a new query is
             // called for.  If the criteria is the same as the last
             // one, just return count of the collection.
             $criteria->add(PersonalFlightPeer::PILOT_ID, $this->id);
             if (!isset($this->lastPersonalFlightCriteria) || !$this->lastPersonalFlightCriteria->equals($criteria)) {
                 $count = PersonalFlightPeer::doCount($criteria, $con);
             } else {
                 $count = count($this->collPersonalFlights);
             }
         } else {
             $count = count($this->collPersonalFlights);
         }
     }
     return $count;
 }
Esempio n. 3
0
 /**
  * Retrieve multiple objects by pkey.
  *
  * @param      array $pks List of primary keys
  * @param      PropelPDO $con the connection to use
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function retrieveByPKs($pks, PropelPDO $con = null)
 {
     if ($con === null) {
         $con = Propel::getConnection(PersonalFlightPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria(PersonalFlightPeer::DATABASE_NAME);
         $criteria->add(PersonalFlightPeer::ID, $pks, Criteria::IN);
         $objs = PersonalFlightPeer::doSelect($criteria, $con);
     }
     return $objs;
 }
Esempio n. 4
0
 /**
  * Populates the object using an array.
  *
  * This is particularly useful when populating an object from one of the
  * request arrays (e.g. $_POST).  This method goes through the column
  * names, checking to see whether a matching key exists in populated
  * array. If so the setByName() method is called for that column.
  *
  * You can specify the key type of the array by additionally passing one
  * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
  * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
  * The default key type is the column's phpname (e.g. 'AuthorId')
  *
  * @param      array  $arr     An array to populate the object from.
  * @param      string $keyType The type of keys the array uses.
  * @return     void
  */
 public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
 {
     $keys = PersonalFlightPeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setId($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setPilotId($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setName($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setDepartureDate($arr[$keys[3]]);
     }
     if (array_key_exists($keys[4], $arr)) {
         $this->setReturnDate($arr[$keys[4]]);
     }
     if (array_key_exists($keys[5], $arr)) {
         $this->setOriginCity($arr[$keys[5]]);
     }
     if (array_key_exists($keys[6], $arr)) {
         $this->setOriginZipcode($arr[$keys[6]]);
     }
     if (array_key_exists($keys[7], $arr)) {
         $this->setDestinationCity($arr[$keys[7]]);
     }
     if (array_key_exists($keys[8], $arr)) {
         $this->setDestinationZipcode($arr[$keys[8]]);
     }
 }
Esempio n. 5
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;
 }