コード例 #1
0
 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();
 }
コード例 #2
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;
     //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;
 }