Эх сурвалжийг харах

Ajout de la possibilité d'update les notes et les coms

François 5 жил өмнө
parent
commit
dc117826f6

+ 42 - 0
src/AppBundle/Command/UpdateCommentairesCommand.php

@@ -0,0 +1,42 @@
+<?php
+
+namespace AppBundle\Command;
+
+use AppBundle\Service\NoteMoyenne;
+use Doctrine\ORM\EntityManagerInterface;
+use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+
+class UpdateCommentairesCommand extends ContainerAwareCommand
+{
+    private $em;
+    private $notesAndComs;
+
+    public function __construct(EntityManagerInterface $em, NoteMoyenne $notesAndComs)
+    {
+        $this->em = $em;
+        $this->notesAndComs = $notesAndComs;
+        parent::__construct();
+    }
+
+    protected function configure()
+    {
+        $this
+            ->setName('app:commentaires:update')
+            ->setDescription('Update les notes et nb coms')
+        ;
+    }
+
+    protected function execute(InputInterface $input, OutputInterface $output)
+    {
+        $films = $this->em->getRepository('AppBundle:Film')->findAll();
+        foreach ($films as $film)
+        {
+            $this->notesAndComs->calculerMoyenne($film);
+        }
+
+        $output->writeln('Tous les coms et toutes les notes sont mis à jour');
+    }
+
+}