Esempio n. 1
0
 /**
  * Retrieve a country by ISO code (long or short)
  * 
  * @param mixed $country_code
  * @return Country
  */
 public static function retrieveByCountryCode($country_iso_code)
 {
     // If it's a long-code search
     if (strlen($country_iso_code) == 3) {
         return \CountryQuery::create()->filterByIsoCode($country_iso_code)->findOne();
         // Short code
     } elseif (strlen($country_iso_code) == 2) {
         return \CountryQuery::create()->filterByIsoShortCode($country_iso_code)->findOne();
     }
 }
Esempio n. 2
0
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param      PropelPDO $con
  * @return void
  * @throws PropelException
  * @throws Exception
  * @see        BaseObject::setDeleted()
  * @see        BaseObject::isDeleted()
  */
 public function delete(PropelPDO $con = null)
 {
     if ($this->isDeleted()) {
         throw new PropelException("This object has already been deleted.");
     }
     if ($con === null) {
         $con = Propel::getConnection(CountryPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = CountryQuery::create()->filterByPrimaryKey($this->getPrimaryKey());
         $ret = $this->preDelete($con);
         // symfony_behaviors behavior
         foreach (sfMixer::getCallables('BaseCountry:delete:pre') as $callable) {
             if (call_user_func($callable, $this, $con)) {
                 $con->commit();
                 return;
             }
         }
         if ($ret) {
             $deleteQuery->delete($con);
             $this->postDelete($con);
             // symfony_behaviors behavior
             foreach (sfMixer::getCallables('BaseCountry:delete:post') as $callable) {
                 call_user_func($callable, $this, $con);
             }
             $con->commit();
             $this->setDeleted(true);
         } else {
             $con->commit();
         }
     } catch (Exception $e) {
         $con->rollBack();
         throw $e;
     }
 }
Esempio n. 3
0
 /**
  * Return the shop country
  *
  * @throws LogicException if no shop country is defined
  */
 public static function getShopLocation()
 {
     $dc = CountryQuery::create()->findOneByShopCountry(true);
     if ($dc == null) {
         throw new \LogicException(Translator::getInstance()->trans("Cannot find the shop country. Please select a shop country."));
     }
     return $dc;
 }
Esempio n. 4
0
 /**
  * Return the shop country
  *
  * @throws LogicException if no shop country is defined
  */
 public static function getShopLocation()
 {
     $countryId = ConfigQuery::getStoreCountry();
     // return the default country if no shop country defined
     if (empty($countryId)) {
         return self::getDefaultCountry();
     }
     $shopCountry = CountryQuery::create()->findPk($countryId);
     if ($shopCountry === null) {
         throw new \LogicException(Translator::getInstance()->trans("Cannot find the shop country. Please select a shop country."));
     }
     return $shopCountry;
 }
Esempio n. 5
0
 /**
  * Get the associated Country object
  *
  * @param      PropelPDO $con Optional Connection object.
  * @return                 Country The associated Country object.
  * @throws PropelException
  */
 public function getCountry(PropelPDO $con = null)
 {
     if ($this->aCountry === null && $this->country_id !== null) {
         $this->aCountry = CountryQuery::create()->findPk($this->country_id, $con);
         /* The following can be used additionally to
               guarantee the related object contains a reference
               to this object.  This level of coupling may, however, be
               undesirable since it could result in an only partially populated collection
               in the referenced object.
               $this->aCountry->addStates($this);
            */
     }
     return $this->aCountry;
 }
Esempio n. 6
0
 /**
  * Returns the number of related Country objects.
  *
  * @param      Criteria $criteria
  * @param      boolean $distinct
  * @param      PropelPDO $con
  * @return int             Count of related Country objects.
  * @throws PropelException
  */
 public function countCountrys(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
 {
     if (null === $this->collCountrys || null !== $criteria) {
         if ($this->isNew() && null === $this->collCountrys) {
             return 0;
         } else {
             $query = CountryQuery::create(null, $criteria);
             if ($distinct) {
                 $query->distinct();
             }
             return $query->filterByCurrency($this)->count($con);
         }
     } else {
         return count($this->collCountrys);
     }
 }