diff --git a/core/Entity/Analytic/Referer.php b/core/Entity/Analytic/Referer.php index 7565a84..0281d3c 100644 --- a/core/Entity/Analytic/Referer.php +++ b/core/Entity/Analytic/Referer.php @@ -22,7 +22,7 @@ class Referer implements EntityInterface /** * @ORM\ManyToOne(targetEntity=Node::class, inversedBy="nodeViews") - * @ORM\JoinColumn(nullable=false) + * @ORM\JoinColumn(nullable=false, onDelete="CASCADE") */ private $node; diff --git a/core/Entity/Analytic/View.php b/core/Entity/Analytic/View.php index fd15938..a5db1b9 100644 --- a/core/Entity/Analytic/View.php +++ b/core/Entity/Analytic/View.php @@ -22,7 +22,7 @@ class View implements EntityInterface /** * @ORM\ManyToOne(targetEntity=Node::class, inversedBy="nodeViews") - * @ORM\JoinColumn(nullable=false) + * @ORM\JoinColumn(nullable=false, onDelete="CASCADE") */ private $node; diff --git a/core/Entity/Site/Node.php b/core/Entity/Site/Node.php index 3d4131b..35a684e 100644 --- a/core/Entity/Site/Node.php +++ b/core/Entity/Site/Node.php @@ -12,6 +12,8 @@ use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; use Gedmo\Mapping\Annotation as Gedmo; use function Symfony\Component\String\u; +use App\Core\Entity\Analytic\View; +use App\Core\Entity\Analytic\Referer; /** * @Gedmo\Tree(type="nested") @@ -143,12 +145,24 @@ class Node implements EntityInterface /** * @ORM\Column(type="boolean", options={"default"=0}) */ - private $enableViewCounter = false; + protected $enableAnalytic = false; + + /** + * @ORM\OneToMany(targetEntity=View::class, mappedBy="node") + */ + protected $analyticViews; + + /** + * @ORM\OneToMany(targetEntity=Referer::class, mappedBy="node") + */ + protected $analyticReferers; public function __construct() { $this->children = new ArrayCollection(); $this->aliasNodes = new ArrayCollection(); + $this->analyticViews = new ArrayCollection(); + $this->analyticReferers = new ArrayCollection(); } public function getId(): ?int @@ -555,14 +569,74 @@ class Node implements EntityInterface return $this; } - public function getEnableViewCounter(): ?bool + public function getEnableAnalytic(): ?bool { - return $this->enableViewCounter; + return $this->enableAnalytic; } - public function setEnableViewCounter(bool $enableViewCounter): self + public function setEnableAnalytic(bool $enableAnalytic): self { - $this->enableViewCounter = $enableViewCounter; + $this->enableAnalytic = $enableAnalytic; + + return $this; + } + + /** + * @return Collection|View[] + */ + public function getAnalyticViews(): Collection + { + return $this->analyticViews; + } + + public function addAnalyticView(View $view): self + { + if (!$this->analyticViews->contains($view)) { + $this->analyticViews[] = $view; + $view->setNode($this); + } + + return $this; + } + + public function removeAnalyticView(View $view): self + { + if ($this->analyticViews->removeElement($view)) { + // set the owning side to null (unless already changed) + if ($view->getNode() === $this) { + $view->setNode(null); + } + } + + return $this; + } + + /** + * @return Collection|Referer[] + */ + public function getAnalyticReferers(): Collection + { + return $this->analyticReferers; + } + + public function addAnalyticReferer(Referer $referer): self + { + if (!$this->analyticReferers->contains($referer)) { + $this->analyticReferers[] = $referer; + $referer->setNode($this); + } + + return $this; + } + + public function removeAnalyticReferer(Referer $referer): self + { + if ($this->analyticReferers->removeElement($referer)) { + // set the owning side to null (unless already changed) + if ($referer->getNode() === $this) { + $referer->setNode(null); + } + } return $this; } diff --git a/core/Form/Site/NodeType.php b/core/Form/Site/NodeType.php index 184cf55..4f41c1d 100644 --- a/core/Form/Site/NodeType.php +++ b/core/Form/Site/NodeType.php @@ -61,10 +61,10 @@ class NodeType extends AbstractType ); $builder->add( - 'enableViewCounter', + 'enableAnalytic', CheckboxType::class, [ - 'label' => 'Enable view counter', + 'label' => 'Enable analytic', 'required' => false, 'attr' => [ ], diff --git a/core/Resources/translations/messages.fr.yaml b/core/Resources/translations/messages.fr.yaml index 26a9430..7f02595 100644 --- a/core/Resources/translations/messages.fr.yaml +++ b/core/Resources/translations/messages.fr.yaml @@ -39,8 +39,7 @@ "Never": "Jamais" "URL": "URL" "Disable URL": "Désactiver l'URL" -"Enable view counter": "Activer le compteur de vues" -"Stats": "Statistiques" +"Enable analytic": "Activer l'analyse" "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" diff --git a/core/Resources/views/site/node_admin/_form.html.twig b/core/Resources/views/site/node_admin/_form.html.twig index b1d7d78..44064ce 100644 --- a/core/Resources/views/site/node_admin/_form.html.twig +++ b/core/Resources/views/site/node_admin/_form.html.twig @@ -205,7 +205,7 @@ {{ form_row(form.disableUrl) }} - {{ form_row(form.enableViewCounter) }} + {{ form_row(form.enableAnalytic) }} {{ form_row(form.code) }} {{ form_row(form.contentType) }} {{ form_row(form.controller) }}