Пример #1
0
 /**
  * Получить новые комменты для владельца
  *
  * @param int    $nTargetId      ID владельца коммента
  * @param string $sTargetType    Тип владельца комментария
  * @param int    $nIdCommentLast ID последнего прочитанного комментария
  *
  * @return array('comments'=>array,'iMaxIdComment'=>int)
  */
 public function GetCommentsNewByTargetId($nTargetId, $sTargetType, $nIdCommentLast)
 {
     $sCacheKey = "comment_target_{$nTargetId}_{$sTargetType}_{$nIdCommentLast}";
     if (false === ($aCommentsId = E::ModuleCache()->Get($sCacheKey))) {
         $aCommentsId = $this->oMapper->GetCommentsIdNewByTargetId($nTargetId, $sTargetType, $nIdCommentLast);
         E::ModuleCache()->Set($aCommentsId, $sCacheKey, array("comment_new_{$sTargetType}_{$nTargetId}"), 'P1D');
     }
     $aComments = array();
     if (count($aCommentsId)) {
         $aComments = $this->GetCommentsAdditionalData($aCommentsId);
     }
     if (!$aComments) {
         return array('comments' => array(), 'iMaxIdComment' => $nIdCommentLast);
     }
     $iMaxIdComment = max($aCommentsId);
     $aVars = array('oUserCurrent' => E::ModuleUser()->GetUserCurrent(), 'bOneComment' => true);
     if ($sTargetType != 'topic') {
         $aVars['bNoCommentFavourites'] = true;
     }
     $aCommentsHtml = array();
     $bAllowToComment = false;
     if ($sTargetType == 'talk') {
         $bAllowToComment = TRUE;
     } elseif ($oUserCurrent = E::User()) {
         $oComment = reset($aComments);
         if ($oComment->getTarget() && $oComment->getTarget()->getBlog()) {
             $iBlogId = $oComment->getTarget()->getBlog()->GetId();
             $bAllowToComment = E::ModuleBlog()->GetBlogsAllowTo('comment', $oUserCurrent, $iBlogId, TRUE);
         }
     }
     $aVars['bAllowToComment'] = $bAllowToComment;
     foreach ($aComments as $oComment) {
         $aVars['oComment'] = $oComment;
         $sText = E::ModuleViewer()->Fetch($this->GetTemplateCommentByTarget($nTargetId, $sTargetType), $aVars);
         $aCommentsHtml[] = array('html' => $sText, 'obj' => $oComment);
     }
     return array('comments' => $aCommentsHtml, 'iMaxIdComment' => $iMaxIdComment);
 }