84 lines
2.2 KiB
PHP
84 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace KupShop\CommentsBundle\Twig\Components\Comments;
|
|
|
|
use KupShop\ComponentsBundle\Attributes\Component;
|
|
use KupShop\ComponentsBundle\Attributes\Version;
|
|
use KupShop\ComponentsBundle\Twig\BaseComponent;
|
|
use KupShop\ComponentsBundle\Twig\DataProvider\CommentsTrait;
|
|
use KupShop\ComponentsBundle\Twig\DataProvider\TextHelperTrait;
|
|
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;
|
|
use Symfony\UX\TwigComponent\Attribute\PreMount;
|
|
|
|
#[AsTwigComponent(template: '@Comments/components/Comments/Header/Header.1.html.twig')]
|
|
#[Component(1, [
|
|
new Version(1, newJs: null),
|
|
])]
|
|
class Header extends BaseComponent
|
|
{
|
|
use TextHelperTrait;
|
|
use CommentsTrait;
|
|
|
|
private int $id_object;
|
|
private string $type_object;
|
|
private bool $allowAnonymous = false;
|
|
public string $title = '';
|
|
|
|
public function getCount(): int
|
|
{
|
|
if ($this->type_object == self::TYPE_PRODUCT) {
|
|
$this->getComments($this->id_object, self::TYPE_PRODUCT);
|
|
} else {
|
|
$this->getComments($this->id_object, self::TYPE_ARTICLE);
|
|
}
|
|
|
|
return $this->commentsCount ?? 0;
|
|
}
|
|
|
|
public function getModalPath(): string
|
|
{
|
|
$parameters = [
|
|
'template' => 'commentsForm',
|
|
'id_parent' => null,
|
|
'ref_name' => null,
|
|
'ref_comment' => null,
|
|
];
|
|
|
|
switch ($this->type_object) {
|
|
case self::TYPE_PRODUCT:
|
|
$parameters['id_product'] = $this->id_object;
|
|
break;
|
|
|
|
case self::TYPE_ARTICLE:
|
|
default:
|
|
$parameters['id_article'] = $this->id_object;
|
|
break;
|
|
}
|
|
|
|
return path('kupshop_components_modal_modal', $parameters);
|
|
}
|
|
|
|
public function setIdObject(int $id_object): void
|
|
{
|
|
$this->id_object = $id_object;
|
|
}
|
|
|
|
public function setTypeObject(string $type_object): void
|
|
{
|
|
$this->type_object = $type_object;
|
|
}
|
|
|
|
public function isAllowAnonymous(): bool
|
|
{
|
|
return $this->allowAnonymous;
|
|
}
|
|
|
|
#[PreMount]
|
|
public function preMount(): void
|
|
{
|
|
if (findModule(\Modules::COMMENTS, \Modules::SUB_COMMENTS_ANONYMOUS)) {
|
|
$this->allowAnonymous = true;
|
|
}
|
|
}
|
|
}
|