Example #1
0
 function &getBlogSocieties()
 {
     $blog_model_societies = new BlogModelSocieties();
     $blog_model_societies->loadByUserId($this->id);
     return $blog_model_societies;
 }
 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('Societies', '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 BlogModelSocieties();
     $blog_model->loadByUserId($user_id);
     $blog_id = (int) $blog_model->id;
     if ($blog_id <= 0) {
         Project::getResponse()->redirect($request->createUrl('Societies', 'Edit'));
     }
     $parent_tree_model = new BlogTreeModelSocieties();
     $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 BlogTreeModelSocieties();
     $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 BlogModelSocieties();
         $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_societies');
             $tree_model->key = $n->key->__toString();
         }
         if (!$parent_node) {
             $node = new Node(new Key($tree_model->id), 'ub_tree_societies');
             $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('Societies', 'PostList'));
     } elseif ($request->delete) {
         $tree_model->delete($branch_id);
         $blog_model->deletePostsByUb_tree_id($branch_id);
         Project::getResponse()->redirect($request->createUrl('Societies', 'PostList'));
     }
 }