add node view counter option

This commit is contained in:
Simon Vieille 2022-02-19 23:33:19 +01:00
parent 03b45e89e3
commit 1f6aaf41e1
4 changed files with 70 additions and 0 deletions

View file

@ -4,6 +4,7 @@ namespace App\Core\Entity\Site;
use App\Core\Doctrine\Timestampable;
use App\Core\Entity\EntityInterface;
use App\Core\Entity\NodeView;
use App\Core\Entity\Site\Page\Page;
use App\Core\Repository\Site\NodeRepository;
use Doctrine\Common\Collections\ArrayCollection;
@ -139,10 +140,21 @@ class Node implements EntityInterface
*/
protected $contentType;
/**
* @ORM\Column(type="boolean", options={"default"=0})
*/
private $enableViewCounter = false;
/**
* @ORM\OneToMany(targetEntity=NodeView::class, mappedBy="node", orphanRemoval=true)
*/
private $nodeViews;
public function __construct()
{
$this->children = new ArrayCollection();
$this->aliasNodes = new ArrayCollection();
$this->nodeViews = new ArrayCollection();
}
public function getId(): ?int
@ -548,4 +560,46 @@ class Node implements EntityInterface
return $this;
}
public function getEnableViewCounter(): ?bool
{
return $this->enableViewCounter;
}
public function setEnableViewCounter(bool $enableViewCounter): self
{
$this->enableViewCounter = $enableViewCounter;
return $this;
}
/**
* @return Collection|NodeView[]
*/
public function getNodeViews(): Collection
{
return $this->nodeViews;
}
public function addNodeView(NodeView $nodeView): self
{
if (!$this->nodeViews->contains($nodeView)) {
$this->nodeViews[] = $nodeView;
$nodeView->setNode($this);
}
return $this;
}
public function removeNodeView(NodeView $nodeView): self
{
if ($this->nodeViews->removeElement($nodeView)) {
// set the owning side to null (unless already changed)
if ($nodeView->getNode() === $this) {
$nodeView->setNode(null);
}
}
return $this;
}
}

View file

@ -60,6 +60,19 @@ class NodeType extends AbstractType
]
);
$builder->add(
'enableViewCounter',
CheckboxType::class,
[
'label' => 'Enable view counter',
'required' => false,
'attr' => [
],
'constraints' => [
],
]
);
$builder->add(
'code',
TextType::class,

View file

@ -39,6 +39,8 @@
"Never": "Jamais"
"URL": "URL"
"Disable URL": "Désactiver l'URL"
"Enable view counter": "Activer le compteur de vues"
"Stats": "Statistiques"
"Controller": "Contrôleur"
"Leave blank for automatic generation": "Laisser vide pour une génération automatique"
"Leave blank to use the default one. Example: App\\Controller\\FooController::barAction": "Laisser vide pour utiliser celui par défaut. Exemple : App\\Controller\\FooController::barAction"

View file

@ -205,6 +205,7 @@
</div>
{{ form_row(form.disableUrl) }}
{{ form_row(form.enableViewCounter) }}
{{ form_row(form.code) }}
{{ form_row(form.contentType) }}
{{ form_row(form.controller) }}