Esempio n. 1
0
 /**
  * Set capacity
  * @param integer $capacity
  */
 public function setCapacity($capacity)
 {
     $this->seats->clear();
     for ($i = 1; $i <= $capacity; $i++) {
         $seat = new Seat();
         $seat->setHall($this);
         $seat->setNumber($i);
         $this->seats->add($seat);
     }
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 public function load(ObjectManager $manager)
 {
     $em = $this->container->get('doctrine')->getEntityManager('default');
     $userManager = $this->container->get('fos_user.user_manager');
     /**
      * Add users
      */
     foreach ($this->users as $user) {
         $newUser = $userManager->createUser();
         $newUser->setUsername($user['email']);
         $newUser->setEmail($user['email']);
         $newUser->setName($user['name']);
         $newUser->setPlainPassword($user['pass']);
         $newUser->setEnabled($user['active']);
         $newUser->setRoles(array($user['role']));
         $userManager->updateUser($newUser, true);
     }
     /**
      *Add price categories into database
      */
     foreach ($this->priceCategories as $category => $price) {
         $priceCategory = new priceCategory();
         $priceCategory->setCategory($category);
         $priceCategory->setCategoryPrice($price);
         $manager->persist($priceCategory);
     }
     $manager->flush();
     /**
      * Add clients into database
      */
     /*
           foreach ($this->clients as $i) {
               $client = new Client();
               $client->setEmail($i['email']);
               $client->setFirstname($i['firstname']);
               $client->setSurname($i['surname']);
               $client->setAddress($i['address']);
     
               $manager->persist($client);
           }
             $manager->flush();
     */
     /**
      * Add cinemas, halls and seats into database
      */
     foreach ($this->cinemas as $foo) {
         $cinema = new Cinema();
         $cinema->setName($foo['name']);
         $cinema->setAddress($foo['address']);
         for ($i = 0; $i < rand(1, 3); ++$i) {
             $hall = new Hall();
             $hall->setName($i);
             $hall->setCinema($cinema);
             for ($j = 0; $j < rand(100, 500); ++$j) {
                 $seat = new Seat();
                 $seat->setNumber($j + 1);
                 $seat->setHall($hall);
                 $manager->persist($seat);
             }
             $manager->persist($hall);
         }
         $manager->persist($cinema);
     }
     $manager->flush();
     /**
      * Add genres into database
      */
     foreach ($this->genres as $foo) {
         $genre = new MovieGenre();
         $genre->setGenre($foo);
         $manager->persist($genre);
     }
     $manager->flush();
     // Fetch genres from DB
     $repository = $em->getRepository('AppBundle:MovieGenre');
     $genres = $repository->findAll();
     /**
      * Add movies into database
      */
     foreach ($this->movies as $foo) {
         $movie = new Movie();
         $movie->setName($foo['name']);
         $movie->setYear($foo['year']);
         $genre = $genres[array_rand($genres)];
         $movie->setGenre($genre);
         $movie->setLength($foo['length']);
         $manager->persist($movie);
     }
     $manager->flush();
     /**
      * Add tickets and projections
      */
     // Fetch clients, seats and movies from database
     $repository = $em->getRepository('AppBundle:Client');
     $clients = $repository->findAll();
     $repository = $em->getRepository('AppBundle:Movie');
     $movies = $repository->findAll();
     $repository = $em->getRepository('AppBundle:Hall');
     $halls = $repository->findAll();
     // Add projections into database
     for ($i = 0; $i < 600; $i++) {
         $projection = new Projection();
         $movie = $movies[array_rand($movies)];
         $hall = $halls[array_rand($halls)];
         $date = new \DateTime();
         $date2 = new \DateTime();
         // Set attributes to projection
         $timestamp = randomTimestamp('2015/12/01', '2016/01/31');
         $date->setTimestamp($timestamp);
         $projection->setDate($date);
         $projection->setStart($date);
         $date2->setTimestamp($timestamp + $movie->getLength() * 60);
         $projection->setEnd($date2);
         $projection->setMovie($movie);
         $projection->setHall($hall);
         $manager->persist($projection);
     }
     $manager->flush();
 }