/**
  * Получить комменты по владельцу
  *
  * @param  int $sId ID владельца коммента
  * @param  string $sTargetType Тип владельца комментария
  * @param  int $iPage Номер страницы
  * @param  int $iPerPage Количество элементов на страницу
  * @return array('comments'=>array,'iMaxIdComment'=>int)
  */
 public function GetCommentsByTargetId($sId, $sTargetType, $iPage = 1, $iPerPage = 0)
 {
     if (Config::Get('module.comment.use_nested')) {
         return $this->GetCommentsTreeByTargetId($sId, $sTargetType, $iPage, $iPerPage);
     }
     if (false === ($aCommentsRec = $this->Cache_Get("comment_target_{$sId}_{$sTargetType}"))) {
         $aCommentsRow = $this->oMapper->GetCommentsByTargetId($sId, $sTargetType);
         if (count($aCommentsRow)) {
             $aCommentsRec = $this->BuildCommentsRecursive($aCommentsRow);
         }
         $this->Cache_Set($aCommentsRec, "comment_target_{$sId}_{$sTargetType}", array("comment_new_{$sTargetType}_{$sId}"), 60 * 60 * 24 * 2);
     }
     if (!isset($aCommentsRec['comments'])) {
         return array('comments' => array(), 'iMaxIdComment' => 0);
     }
     $aComments = $aCommentsRec;
     $aComments['comments'] = $this->GetCommentsAdditionalData(array_keys($aCommentsRec['comments']));
     foreach ($aComments['comments'] as $oComment) {
         $oComment->setLevel($aCommentsRec['comments'][$oComment->getId()]);
     }
     return $aComments;
 }
Beispiel #2
0
 /**
  * Получить комменты по владельцу
  *
  * @param  int|object $xTarget     ID/экземпляр владельца комментария
  * @param  string     $sTargetType Тип владельца комментария
  * @param  int        $iPage       Номер страницы
  * @param  int        $iPerPage    Количество элементов на страницу
  *
  * @return array('comments'=>array,'iMaxIdComment'=>int)
  */
 public function GetCommentsByTargetId($xTarget, $sTargetType, $iPage = 1, $iPerPage = 0)
 {
     if (Config::Get('module.comment.use_nested')) {
         return $this->GetCommentsTreeByTargetId($xTarget, $sTargetType, $iPage, $iPerPage);
     }
     if (is_object($xTarget)) {
         $iTargetId = $xTarget->getId();
         $oTarget = $xTarget;
     } else {
         $iTargetId = intval($xTarget);
         $oTarget = null;
     }
     $sCacheKey = "comment_target_{$iTargetId}_{$sTargetType}";
     if (false === ($aCommentsRec = E::ModuleCache()->Get($sCacheKey))) {
         $aCommentsRow = $this->oMapper->GetCommentsByTargetId($iTargetId, $sTargetType);
         if (count($aCommentsRow)) {
             $aCommentsRec = $this->BuildCommentsRecursive($aCommentsRow);
         }
         E::ModuleCache()->Set($aCommentsRec, $sCacheKey, array("comment_new_{$sTargetType}_{$iTargetId}"), 'P2D');
     }
     if (!isset($aCommentsRec['comments'])) {
         return array('comments' => array(), 'iMaxIdComment' => 0);
     }
     $aComments = $aCommentsRec;
     $aCommentsId = array_keys($aCommentsRec['comments']);
     if ($aCommentsId) {
         if ($oTarget) {
             $aAdditionalData = array('target' => array($sTargetType => array($iTargetId => $oTarget)));
         } else {
             $aAdditionalData = array();
         }
         $aComments['comments'] = $this->GetCommentsAdditionalData($aCommentsId, null, $aAdditionalData);
         foreach ($aComments['comments'] as $oComment) {
             $oComment->setLevel($aCommentsRec['comments'][$oComment->getId()]);
         }
     }
     return $aComments;
 }