|
|
@@ -31,12 +31,6 @@ class Film
|
|
|
#[Assert\Url()]
|
|
|
private ?string $lien = null;
|
|
|
|
|
|
- #[ORM\Column(name: "note", type: Types::FLOAT, nullable: true)]
|
|
|
- private ?float $note = null;
|
|
|
-
|
|
|
- #[ORM\Column(name: "nb_coms", type: Types::INTEGER, nullable: true)]
|
|
|
- private ?int $nbComs = null;
|
|
|
-
|
|
|
/*
|
|
|
#[Assert\Valid()]
|
|
|
#[ORM\OneToOne(targetEntity: MediaVideo::class, cascade: ["persist","remove"])]
|
|
|
@@ -257,30 +251,6 @@ class Film
|
|
|
return $this;
|
|
|
}
|
|
|
|
|
|
- public function getNote(): ?float
|
|
|
- {
|
|
|
- return $this->note;
|
|
|
- }
|
|
|
-
|
|
|
- public function setNote(?float $note): self
|
|
|
- {
|
|
|
- $this->note = $note;
|
|
|
-
|
|
|
- return $this;
|
|
|
- }
|
|
|
-
|
|
|
- public function getNbComs(): ?int
|
|
|
- {
|
|
|
- return $this->nbComs;
|
|
|
- }
|
|
|
-
|
|
|
- public function setNbComs(?int $nbComs): self
|
|
|
- {
|
|
|
- $this->nbComs = $nbComs;
|
|
|
-
|
|
|
- return $this;
|
|
|
- }
|
|
|
-
|
|
|
public function getInformation(): ?string
|
|
|
{
|
|
|
return $this->information;
|
|
|
@@ -347,5 +317,33 @@ class Film
|
|
|
return $this;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Calcule et retourne la note moyenne du film à partir de ses commentaires.
|
|
|
+ * @return float|null La note moyenne (entre 1 et 5), ou null s'il n'y a pas de notes valides.
|
|
|
+ */
|
|
|
+ public function getAverageNote(): ?float
|
|
|
+ {
|
|
|
+ $notes = [];
|
|
|
+ foreach ($this->getCommentaires() as $commentaire) {
|
|
|
+ $note = $commentaire->getNote();
|
|
|
+ if ($note !== null && $note > 0) {
|
|
|
+ $notes[] = $note;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (empty($notes)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ return array_sum($notes) / count($notes);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Retourne le nombre total de commentaires.
|
|
|
+ */
|
|
|
+ public function getCommentCount(): int
|
|
|
+ {
|
|
|
+ return count($this->getCommentaires());
|
|
|
+ }
|
|
|
|
|
|
}
|