Comments > List * @copyright Tamaranga * @property CommentsBlock $parent */ class CommentsListBlock extends Block { /** @var array Данные о комментариях */ public $comments = []; /** @var int Текущий уровень вложенности комментариев */ public $level = 1; /** @var int Максимально допустимое видимое кол-во комментариев */ public $perPage = 10; public function init() { parent::init(); $this->setTemplate('item/comments.list', 'listings'); } public function data() { if (empty($this->comments) || ! $this->parent) { return false; } $data = parent::data(); $data['perPage'] = $this->config('listings.comments.collapse' . ($this->level > 1 ? '.answers' : ''), $this->perPage, TYPE_UINT); $data['hideReasons'] = $this->parent->comments->getHideReasons(); $data['lang'] = [ 'you' => _t('comments', 'Your comment'), 'author' => _t('comments', 'Listing author'), 'you_delete' => _t('comments', 'You have deleted this comment'), 'answer' => _t('comments', 'Reply'), 'delete' => _t('comments', 'Delete'), 'cancel' => _t('', 'Cancel'), 'date' => _t('comments', 'd.m.Y at H:i'), 'show_answers' => _t('comments', 'Show all replies'), ]; if ($this->level === 1) { $data['lang']['show_more'] = _t('comments', 'More comments ([num])', [ 'num' => (count($this->comments) - $data['perPage']), ]); } # Вложенные комментарии foreach ($this->comments as &$comment) { if (empty($comment['sub'])) { continue; } $comment['sub_comments'] = $this->parent->getList( $comment['sub'], $this->level + 1 ); } unset($comment); $data['comments'] = $this->comments; $data['itemID'] = $this->parent->itemID; $data['itemUserID'] = $this->parent->itemUserID; $data['userID'] = $this->parent->userID; $data['allowAdd'] = ! $this->parent->areCommentsClosed() && $this->parent->isUserLogined(); return $data; } }