예제 #1
0
 function SaveBranchAction()
 {
     $request = Project::getRequest();
     $request_user_id = (int) Project::getUser()->getShowedUser()->id;
     $user_id = (int) Project::getUser()->getDbUser()->id;
     if ($request_user_id != $user_id) {
         Project::getResponse()->redirect($request->createUrl('Blog', 'EditBranch', array($branch_id)));
     }
     $branch_id = (int) $request->branch_id;
     $name = $request->branch_name;
     $catalog_id = (int) $request->blog_catalog;
     $parent_id = (int) $request->parent_branch;
     $access = (int) $request->branch_access;
     $this->BaseSiteData();
     $info = array();
     $this->BaseBlogData($info);
     $blog_model = new BlogModel();
     $blog_model->loadByUserId($user_id);
     $blog_id = (int) $blog_model->id;
     if ($blog_id <= 0) {
         Project::getResponse()->redirect($request->createUrl('Blog', 'Edit'));
     }
     $parent_tree_model = new BlogTreeModel();
     $parent_tree_model->load($parent_id);
     $parent_node = $parent_tree_model->getNode();
     if ($parent_tree_model->level > 1) {
         $this->_view->addFlashMessage(FM::ERROR, "Неверно выбран родительский раздел");
         $this->EditBranchAction($branch_id);
         return;
     }
     if (!$name) {
         $this->_view->addFlashMessage(FM::ERROR, "Имя раздела не может быть пустым");
         $this->EditBranchAction($branch_id);
         return;
     }
     $tree_model = new BlogTreeModel();
     $tree_model->load($branch_id);
     $n = $tree_model->getNode();
     if ($n instanceof Node) {
         $child = $n->getLastChildKey();
     } else {
         $child = null;
     }
     //if ($child&&$child!=$tree_model->key){
     //	$this -> _view -> addFlashMessage(FM::ERROR, "Невозможно изменить раздел: есть зависимые разделы");
     //	$this -> EditBranchAction($branch_id);
     //	return;
     //}
     if ($request->save) {
         $tree_model->name = $name;
         $tree_model->blog_id = $blog_id;
         $tree_model->access = $access;
         $tree_model->blog_catalog_id = $catalog_id;
         $blogModel = new BlogModel();
         $blog_banner = $blogModel->getBlogBannerById($tree_model->blog_banner_id);
         if ($blog_banner) {
             $blog_banner_id = $tree_model->blog_banner_id;
             $blogModel->changeBlogBanner($tree_model->blog_banner_id, $request->blog_banner_code);
         } else {
             $blog_banner_id = $blogModel->addBlogBanner($request->blog_banner_code);
         }
         $tree_model->blog_banner_id = $blog_banner_id;
         $n = $tree_model->getNode();
         if (!$n) {
             $tree_model->key = '';
             if ($parent_node) {
                 $tree_model->level = 1;
             } else {
                 $tree_model->level = 1;
             }
             $branch_id = $tree_model->save();
             $n = new Node(new Key($branch_id), 'ub_tree');
             $tree_model->key = $n->key->__toString();
         }
         if (!$parent_node) {
             $node = new Node(new Key($tree_model->id), 'ub_tree');
             $tree_model->key = $node->key->__toString();
             $tree_model->level = 1;
         }
         $branch_id = $tree_model->save();
         if ($parent_node) {
             $n->changeParent($parent_node);
         }
         Project::getResponse()->redirect($request->createUrl('Blog', 'PostList'));
     } elseif ($request->delete) {
         $tree_model->delete($branch_id);
         $blog_model->deletePostsByUb_tree_id($branch_id);
         Project::getResponse()->redirect($request->createUrl('Blog', 'PostList'));
     }
 }
예제 #2
0
 function AjaxBlogTreeAction()
 {
     $request = Project::getRequest();
     $request_user_id = (int) Project::getUser()->getShowedUser()->id;
     $user_id = (int) Project::getUser()->getDbUser()->id;
     $info = array();
     $tree_id = (int) $request->getKeyByNumber(0);
     $level = (int) $request->getKeyByNumber(1);
     $filter = (int) $request->getKeyByNumber(2);
     $direction = (int) $request->getKeyByNumber(3);
     $tree_model = new BlogTreeModel();
     $info['blog_catalog'] = $tree_model->loadListByParentId($tree_id);
     $subscribe_model = new BlogSubscribeModel();
     if ($direction === 1) {
         foreach ($info['blog_catalog'] as $key => &$item) {
             $subscribed = $subscribe_model->isSubscribed($user_id, $item['id']);
             $count_subitems = $tree_model->countSubItems($item['key']);
             if (!$filter || $subscribed || $count_subitems) {
                 if ($level >= 1) {
                     $count_subitems = 0;
                 }
                 $item['count_subitems'] = $count_subitems;
                 $item['need_subscribe'] = true;
                 $item['subscribed'] = $subscribed;
             } else {
                 unset($info['blog_catalog'][$key]);
             }
         }
         $info['level'] = $level + 1;
     } else {
         $info['level'] = $level;
     }
     $info['id'] = $tree_id;
     $info['direction'] = $direction;
     $info['filter'] = $filter;
     $this->_view->AjaxBlogTree($info);
     $this->_view->ajax();
 }