/**
  * @param $row
  * @return City
  */
 protected function _getCity($row)
 {
     if (!isset($this->_columns['city'])) {
         return null;
     }
     $cityName = $this->_getValue($this->_columns['city'], $row);
     return City::getCityByName($cityName);
 }
Beispiel #2
0
 public function run()
 {
     $row = $this->_startFromRow;
     print 'p';
     $branches = $this->_getBranches();
     print 'b';
     while ($name = $this->_getName($row)) {
         $phones = $this->_getPhones($row);
         $work = $this->_getWork($row);
         $city = $this->_getCity($row);
         $street = $this->_getStreet($row);
         $house = $this->_getHouse($row);
         $address = $this->_getAddress($row);
         if (!$address) {
             $address = trim($street . ',' . $house, ', ');
         } else {
             if (!$city) {
                 $address = $this->_replaceText(array(', ' => ',', 'поселок' => 'п.', 'пос.' => 'п.', 'дер.' => 'д.'), trim(preg_replace('#([0-9]{6})#', '', $address)));
                 $parts = explode(',', $address);
                 while (isset($parts[0]) && !in_array(mb_substr($parts[0], 0, 2), array('г.', 'п.', 'д.'))) {
                     array_shift($parts);
                 }
                 if (!$parts) {
                     if (!$this->_canSkipAddress($address)) {
                         print "\naddress?:" . $address;
                     }
                     $row++;
                     continue;
                 }
                 $cityName = array_shift($parts);
                 $city = City::getCityByName($cityName);
                 $address = implode(',', $parts);
             }
         }
         $values = array('bank_id' => $this->_bank->id, 'name' => $name, 'city_id' => $city->id, 'address' => trim($address, ' ,'), 'phones' => trim($phones), 'working_hours' => $work);
         $uniqueValue = $values[$this->_uniqueFieldName];
         if (isset($branches[$uniqueValue])) {
             $branch = $branches[$uniqueValue];
             unset($branches[$uniqueValue]);
         } else {
             $branch = new BankBranch();
             $pos = Yii::app()->geocoder->addressToPos($city->title . ',' . $values['address']);
             if ($pos) {
                 $branch->longitude = $pos[0];
                 $branch->latitude = $pos[1];
             }
         }
         $branch->attributes = $values;
         $branch->save(false);
         $row++;
         print '+';
     }
     foreach ($branches as $branch) {
         $branch->delete();
         print '-';
     }
     return true;
 }
 public function displayTop()
 {
     $id_lang = $this->context->language->id;
     $cities = DB::getInstance()->executeS("\n            SELECT `c`.`id_city`, `cl`.`name`\n            FROM `" . _DB_PREFIX_ . "city` AS `c`\n            LEFT JOIN `" . _DB_PREFIX_ . "city_lang` AS `cl` ON `cl`.`id_city` = `c`.`id_city`\n            LEFT JOIN `" . _DB_PREFIX_ . "phone_city` AS `pc` ON `pc`.`id_city` = `c`.`id_city`\n            WHERE (`pc`.`mobile` != '' OR `pc`.`phone` != '') AND `cl`.`id_lang` = {$this->context->language->id}\n        ");
     if (!empty($this->context->cookie->id_city) && !empty($this->context->cookie->id_city_manual)) {
         $city = new City($this->context->cookie->id_city, $id_lang);
     } else {
         $city = City::getCityByIP();
         if (!$city || !($city = City::getCityByName($city['city'], $id_lang)) || !Validate::isLoadedObject($city)) {
             $city = City::getCityByName('Москва', $id_lang);
         }
         $this->context->cookie->id_city = $city->id;
         $this->context->cookie->id_city_manual = false;
     }
     $this->smarty->assign(array('cities' => $cities, 'city' => $city));
     $html = $this->display(__FILE__, 'blockmycity.tpl');
     return $html;
 }