/** * Delete Route * * @param int $ids */ public function delete(Cms_Model_Route $route) { $result = $this->_dbTable->getAdapter()->delete('cms_route', array('id = ?' => $route->get_id())); return $result > 0; }
public function editAction() { $data = $this->getRequest()->getPost('data'); $submit = $this->getRequest()->getPost('submit'); $id = $this->_getParam('id'); $data['lang'] = $this->_getParam('langFilter'); /* get all modules */ $criteria['application_id'] = $this->_applicationId; $modules = Application_Model_ModuleMapper::getInstance()->fetchAll($criteria); //check if cancel button is pressed if ($this->_formHelper->isCancel()) { //cancel form return $this->_formHelper->returnCancel($this->view->url(array('action' => 'index')), $this->translate('Action canceled')); } if (isset($data['path']) && $data['path'] != '') { foreach ($modules as $module) { $moduleData = $module->get_data(); if (isset($moduleData['menus'])) { foreach ($moduleData['menus'] as $path => $menu) { if ($module->get_code() . "/" . $path == $data['path']) { $data['dialog_url'] = $menu['dialog_url']; } } } } } // print_r($data);die; //create form object $form = new Cms_Form_Route($data); //postback - save? if ($this->_formHelper->isSave()) { //check if valid if ($form->isValid()) { $values = $form->getValues(); //create entity object from submitted values, and save $route = new Cms_Model_Route($values); //new entity if (!isset($data['id']) || $data['id'] <= 0) { $route->set_application_id($this->_applicationId); $existingRoute = clone $route; if (Cms_Model_RouteMapper::getInstance()->checkRouteExist($existingRoute, $this->_applicationId)) { $route->set_id($existingRoute->get_id()); } } else { $existingRoute = new Cms_Model_Route(); if (!Cms_Model_RouteMapper::getInstance()->find($data['id'], $existingRoute)) { throw new Exception("Menu not found"); } if ((int) $existingRoute->get_application_id() != $this->_applicationId) { throw new Exception("Cannot edit this Route."); } } $route->set_application_id($this->_applicationId); Cms_Model_RouteMapper::getInstance()->save($route); //save done, return success return $this->_formHelper->returnSuccess($this->view->url(array('action' => 'index')), $this->translate('Route saved.')); } else { //we have errors - return json or continue $this->_formHelper->returnError($form->getMessages()); } } elseif (!$this->_formHelper->getRequest()->isPost()) { //edit action if (isset($id) && $id > 0) { $route = new Cms_Model_Route(); if (!Cms_Model_RouteMapper::getInstance()->find($id, $route)) { throw new Exception("Route not found"); } $data = $route->toArray(); //populate form with data $form->setData($data); } } $this->view->languages = Application_Model_TranslateMapper::getInstance()->getLanguages(); $this->view->modules = $modules; $page = new Cms_Model_Page(); if (isset($data['page_id'])) { Cms_Model_PageMapper::getInstance()->find($data['page_id'], $page); } $this->view->page_title = $page->get_title(); $this->view->langFilter = $data['lang']; $this->view->data = $data; }
protected function saveRoute($row) { $module = $this->modules[$this->data[$row]['Module']]; //no path - no route if (!$module['path']) { return; } $titles = explode("\n", $this->data[$row]['Name']); $route = new Cms_Model_Route(); $route->set_application_id(1); if (isset($this->data[$row]['page_id'])) { $route->set_page_id($this->data[$row]['page_id']); } $route->set_path($module['path']); if (isset($module['params'])) { $route->set_params($module['params']); } foreach ($this->languages as $langIndex => $lang) { $title = $this->getLangText($titles, $langIndex); $currRow = $row; if (!isset($module['route_uri'])) { $uriParts = array(); while (isset($this->data[$currRow])) { $currTitles = explode("\n", $this->data[$currRow]['Name']); $uriParts[] = $this->seoFilter->filter($currTitles[$langIndex]); if (!isset($this->data[$currRow]['parent'])) { break; } $currRow = $this->data[$currRow]['parent']; } //print_r($uriParts); $uriParts = array_reverse($uriParts); $uri = implode('/', $uriParts); } else { $uri = $module['route_uri']; } //check if route exists $existingRoutes = Cms_Model_RouteMapper::getInstance()->fetchAll(array('uri' => $uri, 'lang' => $lang)); if (count($existingRoutes) > 0) { continue; } $route->set_name($title)->set_lang($lang)->set_uri($uri); $route->set_id(null); //print_r($route); Cms_Model_RouteMapper::getInstance()->save($route); } $this->data[$row]['route_id'] = $route->get_id(); }
public function editAction() { $data = $this->getRequest()->getPost('data'); $submit = $this->getRequest()->getPost('submit'); $id = $this->_getParam('id'); $data['lang'] = $this->_getParam('langFilter'); /* get all modules */ $criteria['application_id'] = $this->_applicationId; //check if cancel button is pressed if ($this->_formHelper->isCancel()) { //cancel form return $this->_formHelper->returnCancel($this->view->url(array('action' => 'index')), $this->translate('Action canceled')); } //create form object $form = new Cms_Form_RouteRedirect($data); //postback - save? if ($this->_formHelper->isSave()) { //check if valid if ($form->isValid()) { $values = $form->getValues(); //create entity object from submitted values, and save $route = new Cms_Model_Route($values); $route->set_application_id($this->_applicationId); $route->set_path("cms/redirect/index"); $route->set_params("url/" . urlencode($route->get_params())); Cms_Model_RouteMapper::getInstance()->save($route); //save done, return success return $this->_formHelper->returnSuccess($this->view->url(array('action' => 'index')), $this->translate('Route saved.')); } else { //we have errors - return json or continue $this->_formHelper->returnError($form->getMessages()); } } elseif (!$this->_formHelper->getRequest()->isPost()) { //edit action if (isset($id) && $id > 0) { $route = new Cms_Model_Route(); if (!Cms_Model_RouteMapper::getInstance()->find($id, $route)) { throw new Exception("Route not found"); } $data = $route->toArray(); $data["params"] = urldecode(substr($data["params"], 4)); //populate form with data $form->setData($data); } } $this->view->languages = Application_Model_TranslateMapper::getInstance()->getLanguages(); $page = new Cms_Model_Page(); if (isset($data['page_id'])) { Cms_Model_PageMapper::getInstance()->find($data['page_id'], $page); } $this->view->page_title = $page->get_title(); $this->view->langFilter = $data['lang']; $data["path"] = "cms/redirect/index"; $this->view->data = $data; }