Пример #1
0
 public function edit()
 {
     // auth
     Auth::isAdminAuthorized($this->signedUser, 'admin.page', true, '/page');
     // check
     $id = Converter::int('id');
     $pid = Converter::int('pid', 'get', 1);
     $page = \Rebond\Cms\Page\Data::loadById($id);
     if (!isset($page)) {
         $page = new \Rebond\Cms\Page\Model();
         $title = Lang::lang('newPage');
     } else {
         $title = Lang::lang('edit') . ' ' . $page->getTitle();
     }
     if ($page->getId() != 1 && $page->getParentId() == 1) {
         $page->setParentId($pid);
     }
     $form = new \Rebond\Cms\Page\Form($page);
     // action
     $save = Converter::string('save', 'post');
     if (isset($save)) {
         Auth::isAdminAuthorized($this->signedUser, 'admin.page.edit', true, '/page');
         if ($form->setFromPost()->validate()->isValid()) {
             // set new friendly url hidden
             $page->setFriendlyUrl(strtolower($page->getFriendlyUrl()));
             $fuh = \Rebond\Cms\Page\Data::fullFriendlyUrl($page->getParentId());
             $page->setFriendlyUrlPath($fuh);
             $page->save();
             // update children pages
             \Rebond\Cms\Page\Data::updateChildrenFriendlyUrl($page->getId(), $page->getFriendlyUrlPath(), $page->getFriendlyUrl());
             Session::adminSuccess('saved', '/page');
         } else {
             Session::set('adminError', $form->getValidation()->getMessage());
         }
     }
     // view
     $this->setTpl();
     // main
     $tplMain = new Template(Template::MODULE, ['cms', 'page']);
     $tplMain->set('title', $title);
     $tplMain->set('siteUrl', 'http://' . \Rebond\Config::getPath('siteUrl'));
     $tplMain->set('item', $form);
     // layout
     if (Auth::isAdminAuthorized($this->signedUser, 'admin.page.edit', false)) {
         $this->tplLayout->set('column1', $tplMain->render('editor'));
     } else {
         $this->tplLayout->set('column1', $tplMain->render('view'));
     }
     // master
     $this->tplMaster->set('layout', $this->tplLayout->render('layout-1-col'));
     $this->tplMaster->set('jsLauncher', 'page');
     return $this->tplMaster->render('tpl-default');
 }