示例#1
0
 public function load(ObjectManager $manager)
 {
     $lotr = $this->getReference('movie.lotr');
     $movies = new MovieList('Portal', 'portal');
     $movies->addMovie($lotr);
     $manager->persist($movies);
     $manager->flush();
 }
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return int|null
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $movieRepository = $this->entityManager->getRepository('SmoovioCoreBundle:Movie');
     $count = $movieRepository->createQueryBuilder('m')->select('COUNT(m)')->getQuery()->getSingleScalarResult();
     $list = new MovieList('Featured Movies', 'portal');
     for ($i = 0; $i < 10; $i++) {
         $movie = $movieRepository->createQueryBuilder('m')->setFirstResult(rand(0, $count - 1))->setMaxResults(1)->getQuery()->getSingleResult();
         $list->addMovie($movie);
         $output->writeln('Added ' . $movie->getTitle());
     }
     $this->entityManager->persist($list);
     $this->entityManager->flush();
     $output->writeln('Done');
     return 0;
 }
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return int|null
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $movieRepository = $this->entityManager->getRepository('SmoovioCoreBundle:Movie');
     $list = new MovieList('Featured Movies', 'portal');
     $max = 10;
     $progress = $this->getHelper('progress');
     $progress->start($output, $max);
     $movies = $movieRepository->getRandomMovies($max);
     foreach ($movies as $movie) {
         sleep(1);
         $list->addMovie($movie);
         $progress->advance();
     }
     $progress->finish();
     $this->entityManager->persist($list);
     $this->entityManager->flush();
     $output->writeln('The list now includes the following movies:');
     $output->writeln('');
     foreach ($list->getMovies() as $movie) {
         $output->writeln($movie->getTitle());
     }
     return 0;
 }