/** * Import multiple locations from geonames * @return void */ public function action_geonames() { $this->template->title = __('Geonames'); $this->template->scripts['footer'][] = URL::base('http') . 'themes/default/js/oc-panel/locations-geonames.js'; $location = NULL; if (intval(Core::get('id_location')) > 0) { $location = new Model_Location(Core::get('id_location')); if ($location->loaded()) { Breadcrumbs::add(Breadcrumb::factory()->set_title($location->name)->set_url(Route::url('oc-panel', array('controller' => 'location', 'action' => 'geonames')) . '?id_location=' . $location->id_location)); } else { Alert::set(Alert::ERROR, __('You are selecting a location that does not exist')); $this->redirect(Route::get($this->_route_name)->uri(array('controller' => Request::current()->controller()))); } } //update the elements related to that ad if (core::post('geonames_locations') !== "") { $geonames_locations = json_decode(core::post('geonames_locations')); if (count($geonames_locations) > 0) { $obj_location = new Model_Location(); $locations_array = array(); $insert = DB::insert('locations', array('name', 'seoname', 'id_location_parent', 'latitude', 'longitude', 'id_geoname', 'fcodename_geoname', 'order')); $i = 1; $execute = FALSE; foreach ($geonames_locations as $location) { if (!empty($location->name) and !in_array($location->seoname = $obj_location->gen_seoname($location->name), $locations_array)) { $execute = TRUE; $insert = $insert->values(array($location->name, $location->seoname, Core::get('id_location', 1), isset($location->lat) ? $location->lat : NULL, isset($location->long) ? $location->long : NULL, isset($location->id_geoname) ? $location->id_geoname : NULL, isset($location->fcodename_geoname) ? $location->fcodename_geoname : NULL, $i)); $locations_array[] = $location->seoname; $i++; } } // Insert everything with one query. if ($execute == TRUE) { $insert->execute(); Core::delete_cache(); } HTTP::redirect(Route::url('oc-panel', array('controller' => 'location', 'action' => 'index')) . '?id_location=' . Core::get('id_location', 1)); } } else { Alert::set(Alert::INFO, __('Select some locations first.')); } $this->template->content = View::factory('oc-panel/pages/locations/geonames', array('location' => $location)); }
/** * Import multiple locations from geonames * @return void */ public function action_geonames_locations() { $this->auto_render = FALSE; //update the elements related to that ad if (core::post('geonames_locations') !== "") { $geonames_locations = json_decode(core::post('geonames_locations')); if (count($geonames_locations) > 0) { $obj_location = new Model_Location(); $locations_array = array(); $insert = DB::insert('locations', array('name', 'seoname', 'id_location_parent', 'latitude', 'longitude', 'order')); $i = 1; foreach ($geonames_locations as $location) { if (!in_array($location->seoname = $obj_location->gen_seoname($location->name), $locations_array)) { $insert = $insert->values(array($location->name, $location->seoname, Core::get('id_location', 1), isset($location->lat) ? $location->lat : NULL, isset($location->long) ? $location->long : NULL, $i)); $locations_array[] = $location->seoname; $i++; } } // Insert everything with one query. $insert->execute(); Core::delete_cache(); } } else { Alert::set(Alert::INFO, __('Select some locations first.')); } HTTP::redirect(Route::url('oc-panel', array('controller' => 'location', 'action' => 'index')) . '?id_location=' . Core::get('id_location', 1)); }