/** * Получает комменты используя nested set * * @param int $sId ID владельца коммента * @param string $sTargetType Тип владельца комментария * @param int $iPage Номер страницы * @param int $iPerPage Количество элементов на страницу * @return array('comments'=>array,'iMaxIdComment'=>int,'count'=>int) */ public function GetCommentsTreeByTargetId($sId, $sTargetType, $iPage = 1, $iPerPage = 0) { if (!Config::Get('module.comment.nested_page_reverse') and $iPerPage and $iCountPage = ceil($this->GetCountCommentsRootByTargetId($sId, $sTargetType) / $iPerPage)) { $iPage = $iCountPage - $iPage + 1; } $iPage = $iPage < 1 ? 1 : $iPage; if (false === ($aReturn = $this->Cache_Get("comment_tree_target_{$sId}_{$sTargetType}_{$iPage}_{$iPerPage}"))) { /** * Нужно или нет использовать постраничное разбиение комментариев */ if ($iPerPage) { $aComments = $this->oMapper->GetCommentsTreePageByTargetId($sId, $sTargetType, $iCount, $iPage, $iPerPage); } else { $aComments = $this->oMapper->GetCommentsTreeByTargetId($sId, $sTargetType); $iCount = count($aComments); } $iMaxIdComment = count($aComments) ? max($aComments) : 0; $aReturn = array('comments' => $aComments, 'iMaxIdComment' => $iMaxIdComment, 'count' => $iCount); $this->Cache_Set($aReturn, "comment_tree_target_{$sId}_{$sTargetType}_{$iPage}_{$iPerPage}", array("comment_new_{$sTargetType}_{$sId}"), 60 * 60 * 24 * 2); } $aReturn['comments'] = $this->GetCommentsAdditionalData($aReturn['comments']); return $aReturn; }
/** * Получает комменты используя nested set * * @param int|object $xTarget ID/экземпляр владельца коммента * @param string $sTargetType Тип владельца комментария * @param int $iPage Номер страницы * @param int $iPerPage Количество элементов на страницу * * @return array('comments'=>array, 'iMaxIdComment'=>int, 'count'=>int) */ public function GetCommentsTreeByTargetId($xTarget, $sTargetType, $iPage = 1, $iPerPage = 0) { if (is_object($xTarget)) { $iTargetId = $xTarget->getId(); $oTarget = $xTarget; } else { $iTargetId = intval($xTarget); $oTarget = null; } if (!Config::Get('module.comment.nested_page_reverse') && $iPerPage && ($iCountPage = ceil($this->GetCountCommentsRootByTargetId($iTargetId, $sTargetType) / $iPerPage))) { $iPage = $iCountPage - $iPage + 1; } $iPage = $iPage < 1 ? 1 : $iPage; $sCacheKey = "comment_tree_target_{$iTargetId}_{$sTargetType}_{$iPage}_{$iPerPage}"; if (false === ($aReturn = E::ModuleCache()->Get($sCacheKey))) { // * Нужно или нет использовать постраничное разбиение комментариев if ($iPerPage) { $aComments = $this->oMapper->GetCommentsTreePageByTargetId($iTargetId, $sTargetType, $iCount, $iPage, $iPerPage); } else { $aComments = $this->oMapper->GetCommentsTreeByTargetId($iTargetId, $sTargetType); $iCount = count($aComments); } $iMaxIdComment = count($aComments) ? max($aComments) : 0; $aReturn = array('comments' => $aComments, 'iMaxIdComment' => $iMaxIdComment, 'count' => $iCount); E::ModuleCache()->Set($aReturn, $sCacheKey, array("comment_new_{$sTargetType}_{$iTargetId}"), 'P2D'); } if ($aReturn['comments']) { if ($oTarget) { // If there'is target object in arguments then sets in as predefined data $aAdditionalData = array('target' => array($sTargetType => array($iTargetId => $oTarget))); } else { $aAdditionalData = array(); } $aReturn['comments'] = $this->GetCommentsAdditionalData($aReturn['comments'], null, $aAdditionalData); } return $aReturn; }