예제 #1
0
파일: Currency.php 프로젝트: cargomedia/cm
 /**
  * @param CM_Model_Location $location
  * @return CM_Model_Currency|null
  */
 public static function findByLocation(CM_Model_Location $location)
 {
     $country = $location->get(CM_Model_Location::LEVEL_COUNTRY);
     if (null === $country) {
         return null;
     }
     $cache = CM_Cache_Local::getInstance();
     $cacheKey = CM_CacheConst::Currency_CountryId . '_countryId:' . $country->getId();
     if (false === ($currencyId = $cache->get($cacheKey))) {
         $currencyId = CM_Db_Db::select('cm_model_currency_country', 'currencyId', ['countryId' => $country->getId()])->fetchColumn();
         $currencyId = $currencyId ? (int) $currencyId : null;
         $cache->set($cacheKey, $currencyId);
     }
     if (null === $currencyId) {
         return null;
     }
     return new self($currencyId);
 }
예제 #2
0
 public function testGet()
 {
     foreach (self::$_fields as $level => $fields) {
         $location = new CM_Model_Location($level, $fields['id']);
         foreach (array(CM_Model_Location::LEVEL_COUNTRY, CM_Model_Location::LEVEL_STATE, CM_Model_Location::LEVEL_CITY, CM_Model_Location::LEVEL_ZIP) as $level2) {
             $location2 = $location->get($level2);
             if ($level2 > $level) {
                 $this->assertNull($location2);
             } else {
                 $this->assertInstanceOf('CM_Model_Location', $location2);
                 $this->assertSame($location->getId($level2), $location2->getId());
                 $this->assertSame($level2, $location2->getLevel());
             }
         }
     }
 }