Files
kupshop/bundles/KupShop/CommentsBundle/View/CommentsView.php
2025-08-02 16:30:27 +02:00

86 lines
1.7 KiB
PHP

<?php
namespace KupShop\CommentsBundle\View;
use KupShop\CommentsBundle\Util\CommentList;
use KupShop\KupShopBundle\Views\View;
class CommentsView extends View
{
protected $template = 'comments/comments.tpl';
private $type;
private $objectId;
private $languageId;
private $page;
private $commentList;
public function __construct(CommentList $commentList)
{
$this->commentList = $commentList;
}
public function getTemplateVariables()
{
$vars = parent::getTemplateVariables();
$pager = $this->commentList->createPager($this->page);
$vars['data'] = [
'config' => [
'objectId' => $this->objectId,
'type' => $this->type,
],
'pager' => $pager,
'comments' => $this->getComments($pager),
'totalCount' => $pager->total,
];
return $vars;
}
public function getComments(\Pager $pager): array
{
$totalCount = 0;
$this->commentList->andSpec($pager->getSpec());
$comments = $this->commentList->getComments($this->objectId, $this->type, $this->languageId, $totalCount);
$pager->setTotal($totalCount);
return $comments;
}
public function setLanguageId(?string $languageId): self
{
$this->languageId = $languageId;
return $this;
}
public function setPage(int $page): self
{
$this->page = $page;
return $this;
}
public function setType(string $type): self
{
$this->type = $type;
return $this;
}
public function setObjectId(int $objectId): self
{
$this->objectId = $objectId;
return $this;
}
}