Example #1
0
 public function AddNewsTreeAction()
 {
     $newsModel = new NewsModel();
     $request = Project::getRequest();
     $user = Project::getUser()->getDbUser();
     $isAdmin = $user->user_type_id == 1 ? true : false;
     $this->_view->clearFlashMessages();
     if ($request->frmAction == 'add') {
         $noErrors = true;
         if (!$request->news_tree_id) {
             $this->_view->addFlashMessage(FM::ERROR, "Выберите в какой категории будет находиться новый раздел");
             $noErrors = false;
         }
         if (!trim($request->news_tree_name)) {
             $this->_view->addFlashMessage(FM::ERROR, "Введите название категории");
             $noErrors = false;
         }
         if (!$user->id) {
             $this->_view->addFlashMessage(FM::ERROR, "Необходимо зарегистрироваться для добавления новых разделов");
             $noErrors = false;
         }
         if ($noErrors) {
             $category_tag = trim($request->category_tag);
             $type = $category_tag ? 1 : 0;
             // 0 - 1 Rss => 1 NewsTreeCastegory; 1 - 1 Rss => N NewsTreeCategory
             $creation_date = date("Y-m-d H:i:s");
             if ($user->user_type_id == 1 || $user->user_type_id == 4) {
                 // partner or Admin
                 $is_partner = 1;
                 $state = 0;
                 $text_parse_type = 0;
             } else {
                 // registred user
                 $is_partner = 0;
                 $state = 1;
                 $text_parse_type = 2;
             }
             $news_tree_id = $newsModel->addNewsTree($request->news_tree_id, $user->id, $request->news_tree_name, 0);
             //Project::getResponse()->redirect(Project::getRequest()->createUrl('News', 'ChangeNewsTree')."/tree_id:".$news_tree_id);
             Project::getResponse()->redirect(Project::getRequest()->createUrl('News', 'AddNewsTree') . "/isadded:1");
         }
     }
     if ($request->isadded == 1) {
         $this->_view->assign('isAdded', true);
         $this->_view->addFlashMessage(FM::INFO, "Раздел отправлен на модерацию");
     } else {
         $this->_view->assign('isAdded', false);
         $aListNews = $newsModel->getAllNews();
         $this->_view->assign('news_list', $aListNews);
         // all News tree
     }
     $this->_view->assign('tab_list', TabController::getNewsTabs($user->id, $isAdmin, false, false, false, true));
     // Show tabs
     $this->_view->assign('frmAction', 'add');
     $this->_view->assign('submitValue', 'Добавить');
     $this->_view->assign('news_tree_name', '');
     $this->_view->AddNewsTreePage();
     $this->_view->parse();
 }