Exemple #1
0
 /**
  * @param CM_Model_Location $location
  * @throws CM_Exception_Invalid
  */
 public function setCountryMapping(CM_Model_Location $location)
 {
     $country = $location->get(CM_Model_Location::LEVEL_COUNTRY);
     if (null === $country) {
         throw new CM_Exception_Invalid('Location has no country', null, ['location' => $location->getName()]);
     }
     CM_Db_Db::replace('cm_model_currency_country', ['currencyId' => $this->getId(), 'countryId' => $country->getId()]);
 }
Exemple #2
0
 /**
  * @param CM_Model_Location  $location
  * @param CM_Frontend_Render $render
  * @return array list('id' => $id, 'name' => $name[, 'description' => $description, 'img' => $img, 'class' => string])
  */
 public function getSuggestion($location, CM_Frontend_Render $render)
 {
     $names = array();
     for ($level = $location->getLevel(); $level >= CM_Model_Location::LEVEL_COUNTRY; $level--) {
         $names[] = $location->getName($level);
     }
     return array('id' => $location->toArray(), 'name' => implode(', ', array_filter($names)), 'img' => $render->getUrlResource('layout', 'img/flags/' . strtolower($location->getAbbreviation(CM_Model_Location::LEVEL_COUNTRY)) . '.png'));
 }
Exemple #3
0
 /**
  * @param string[]    $expectedNameList
  * @param array[]     $actualItemList
  * @param string|null $message
  */
 private function _assertItemsByName($expectedNameList, $actualItemList, $message = null)
 {
     $actualNameList = Functional\map($actualItemList, function (array $actualItem) {
         $actualLocation = new CM_Model_Location($actualItem['level'], $actualItem['id']);
         return $actualLocation->getName();
     });
     $this->assertSame($expectedNameList, $actualNameList, $message);
 }
Exemple #4
0
 public function testGetName()
 {
     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) {
             if ($level >= $level2) {
                 $this->assertSame(self::$_fields[$level2]['name'], $location->getName($level2));
             } else {
                 $this->assertNull($location->getId($level2));
             }
         }
     }
 }