Exemplo n.º 1
0
 /**
  * @desc Выводит список черновиков текущего пользователя
  * @param Int $blogId Идентификатор блога
  * @param String $template Имя файла шаблона для вывода
  * @return string|array
  */
 public function draughtsList($blogId = false, $template = 'default', $limit = false)
 {
     list($sTemplateBlock, $sTemplateLine) = self::loadTemplates('blogs20/' . $template, 'posts_list_block', 'posts_list_line');
     $page = (int) getRequest('p');
     $oBlog = null;
     $oHierarchy = umiHierarchy::getInstance();
     if ($blogId === false) {
         $iTmp = getRequest('param0');
         if ($iTmp) {
             $blogId = (int) $iTmp;
         }
     }
     $hierarchyTypes = umiHierarchyTypesCollection::getInstance();
     $blogHierachyTypeId = $hierarchyTypes->getTypeByName("blogs20", "blog")->getId();
     $sel = new umiSelection();
     $hierarchy_type_id = $hierarchyTypes->getTypeByName("blogs20", "post")->getId();
     $sel->addElementType($hierarchy_type_id);
     $typesCollection = umiObjectTypesCollection::getInstance();
     $typeId = $typesCollection->getTypeByHierarchyTypeId($hierarchy_type_id);
     $postType = $typesCollection->getType($typeId);
     $userId = cmsController::getInstance()->getModule('users')->user_id;
     $sel->addOwnerFilter(array($userId));
     if ($blogId !== false) {
         $oBlog = $oHierarchy->getElement($blogId);
         if ($oBlog && $oBlog->getHierarchyType() == $blogHierachyTypeId) {
             $sel->addHierarchyFilter($blogId);
         }
     }
     $sel->addActiveFilter(false);
     $sel->setOrderByProperty($postType->getFieldId('publish_time'), false);
     $sel->addLimit($limit ? $limit : $this->posts_per_page, $page);
     self::applyTimeRange($sel, $postType);
     $result = umiSelectionsParser::runSelection($sel);
     $total = umiSelectionsParser::runSelectionCounts($sel);
     $aLines = array();
     foreach ($result as $iPostId) {
         $oPost = $oHierarchy->getElement($iPostId);
         if (!$oPost) {
             continue;
         }
         if (!$oBlog) {
             $oBlog = $oHierarchy->getElement($oPost->getRel());
         }
         if (!$oBlog) {
             continue;
         }
         $sPostLink = '/blogs20/postView/' . $iPostId . '/';
         $sBlogLink = $oHierarchy->getPathById($oBlog->getId(), true);
         $aLineParam = array();
         $aLineParam['attribute:id'] = $iPostId;
         $aLineParam['attribute:author_id'] = $oPost->getObject()->getOwnerId();
         $aLineParam['node:name'] = $oPost->getName();
         $aLineParam['post_link'] = $sPostLink;
         $aLineParam['blog_link'] = $sBlogLink;
         $aLineParam['bid'] = $oBlog->getId();
         $aLineParam['blog_title'] = $oBlog->getValue('title');
         $aLineParam['title'] = $oPost->getValue('title');
         $aLineParam['content'] = $oPost->getValue('content');
         $aLineParam['cut'] = $this->prepareCut($aLineParam['content'], $sPostLink, $template);
         $aLineParam['subnodes:tags'] = $this->prepareTags($oPost->getValue('tags'));
         $aLineParam['comments_count'] = $oHierarchy->getChildsCount($iPostId, false);
         $this->pushEditable("blogs20", "post", $iPostId);
         $aLines[] = self::parseTemplate($sTemplateLine, $aLineParam, $iPostId);
     }
     $aBlockParam = array();
     $aBlockParam['void:lines'] = $aBlockParam['subnodes:items'] = $aLines;
     $aBlockParam['bid'] = $blogId;
     $aBlockParam['per_page'] = $limit ? $limit : $this->posts_per_page;
     $aBlockParam['total'] = $total;
     return self::parseTemplate($sTemplateBlock, $aBlockParam);
 }