/** * CRUD controller: UPDATE */ public function action_update() { $this->template->title = __('Update') . ' ' . __($this->_orm_model) . ' ' . $this->request->param('id'); $this->template->scripts['footer'][] = 'js/gmaps.min.js'; $this->template->scripts['footer'][] = 'js/oc-panel/locations-gmap.js'; $this->template->scripts['async_defer'][] = '//maps.google.com/maps/api/js?libraries=geometry&v=3&key=' . core::config("advertisement.gm_api_key") . '&callback=initLocationsGMap'; $form = new FormOrm($this->_orm_model, $this->request->param('id')); $location = new Model_Location($this->request->param('id')); if ($this->request->post()) { if ($success = $form->submit()) { if ($form->object->id_location == $form->object->id_location_parent) { Alert::set(Alert::INFO, __('You can not set as parent the same location')); $this->redirect(Route::get($this->_route_name)->uri(array('controller' => Request::current()->controller(), 'action' => 'update', 'id' => $form->object->id_location))); } //check if the parent is loaded/exists avoiding errors $parent_loc = new Model_Location($form->object->id_location_parent); if (!$parent_loc->loaded()) { Alert::set(Alert::INFO, __('You are assigning a parent location that does not exist')); $this->redirect(Route::get($this->_route_name)->uri(array('controller' => Request::current()->controller(), 'action' => 'create'))); } $form->object->description = Kohana::$_POST_ORIG['formorm']['description']; try { $form->object->save(); } catch (Exception $e) { throw HTTP_Exception::factory(500, $e->getMessage()); } $form->object->parent_deep = $form->object->get_deep(); try { $form->object->save(); } catch (Exception $e) { throw HTTP_Exception::factory(500, $e->getMessage()); } $this->action_deep(); //rename icon name if ($location->has_image and $location->seoname != $form->object->seoname) { $location->rename_icon($form->object->seoname); } Core::delete_cache(); Alert::set(Alert::SUCCESS, __('Item updated')); $this->redirect(Route::get($this->_route_name)->uri(array('controller' => Request::current()->controller()))); } else { Alert::set(Alert::ERROR, __('Check form for errors')); } } return $this->render('oc-panel/pages/locations/update', array('form' => $form, 'location' => $location)); }