Ejemplo n.º 1
0
 /**
  * Remove car
  *
  * @param Car $car
  */
 public function removeCar(\Entity\Car $car)
 {
     $this->car->removeElement($car);
 }
Ejemplo n.º 2
0
 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     $carCount = 70;
     $status = 'A';
     $currencyArray = array('eur', 'usd');
     $dummyText = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam eget sollicitudin elit.\n                Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Duis ut turpis quis ante mattis luctus.\n                Fusce ac tortor purus. Pellentesque blandit scelerisque sagittis. Morbi quis dolor molestie, mattis felis quis, eleifend lorem.\n                Fusce rhoncus mauris sit amet sapien feugiat, quis ultricies nunc semper.";
     $cars = array('audi' => array('A7', 'Q5', '100', 'R8'), 'bmw' => array('I8', 'M1', 'M3', 'X1', 'Z8'), 'toyota' => array('auris', 'dyna', 'hiace'), 'ford' => array('capri'), 'hyundai' => array('atos'), 'renault' => array('fuego'), 'acura' => array('mdx'), 'dodge' => array('avenger'), 'ferrari' => array('f_208'), 'suzuki' => array('alto', 'baleno'));
     $categoryArray = array_keys($cars);
     $milageArray = array(5000, 10000, 15000, 20000, 25000, 40000, 50000, 55000, 65000, 70000, 75000, 90000, 100000, 125000, 150000);
     $engineArray = array(500, 800, 1000, 1200, 2000, 5000, 10000);
     $colorsArray = array('red', 'green', 'blue', 'yellow', 'black', 'orange');
     $fuelArray = array('diesel', 'petrol', 'cng', 'lpg', 'electric', 'hybrid');
     $ownersArray = array('1', '2', '3', 'more_than_3');
     $airArray = array('manually', 'automatically', 'no');
     $condtArray = array('new', 'second_hand');
     $typeArray = array('hatchBack', 'coupe', 'sedan', 'suv', 'van');
     $salvgArray = array('yes', 'no');
     $endYear = date("Y", strtotime("+5 year"));
     $startYear = date('Y');
     $equipArray = array('abs', 'eds', 'seat', 'mirror', 'window');
     for ($i = 1; $i <= $carCount; $i++) {
         $mfgYear = rand(date("Y", strtotime("-30 year")), date('Y'));
         $adObj1 = new Ad();
         $category = $categoryArray[array_rand($categoryArray)];
         $category2 = $cars[$category][array_rand($cars[$category])];
         $adObj1->setVertical($this->getReference('car'));
         $adObj1->setUser($this->getReference('user_normal_' . rand(1, 5)));
         $adObj1->setCategory1($this->getReference($category));
         $adObj1->setCategory2($this->getReference($category2));
         $adObj1->setStatus($status);
         $adObj1->setTitle($category . " " . $category2 . " " . $mfgYear);
         $adObj1->setPrice(rand(11111, 999999));
         $adObj1->setCurrency($this->getReference($currencyArray[array_rand($currencyArray)]));
         $adObj1->setDescription($dummyText);
         $adObj1->setCreatedAt(new \DateTime('NOW'));
         $manager->persist($adObj1);
         $manager->flush();
         $carObj = new Car();
         $carObj->setAd($adObj1);
         $carObj->setMfgYear($mfgYear);
         $carObj->setMileage($milageArray[array_rand($milageArray)]);
         $carObj->setEngineSize($engineArray[array_rand($engineArray)]);
         $carObj->setVin(rand(11111111, 99999999));
         $carObj->setPower(rand(111, 9999));
         $carObj->setFuelConsumption(rand(1, 500) . "L");
         $carObj->setDoors(rand(2, 8));
         $carObj->setSeats(rand(2, 10));
         $carObj->setColor($this->getReference($colorsArray[array_rand($colorsArray)]));
         $carObj->setFuelType($this->getReference($fuelArray[array_rand($fuelArray)]));
         $carObj->setOwners($this->getReference($ownersArray[array_rand($ownersArray)]));
         $carObj->setAirConditioner($this->getReference('air_' . $airArray[array_rand($airArray)]));
         $carObj->setEmission($this->getReference("eur" . rand(1, 6)));
         $carObj->setGearType($this->getReference("gear_" . rand(1, 4)));
         $carObj->setTransmission($this->getReference("trans_" . rand(1, 2)));
         $carObj->setCapacity($this->getReference("capacity_" . rand(4, 62)));
         $carObj->setTuvValidity($this->getReference('tuv_' . rand($startYear, $endYear)));
         $carObj->setConditions($this->getReference($condtArray[array_rand($condtArray)]));
         $carObj->setCarType($this->getReference('cartype_' . $typeArray[array_rand($typeArray)]));
         $carObj->setSalvage($this->getReference('salvage_' . $salvgArray[array_rand($salvgArray)]));
         $equipsArray = array_rand($equipArray, 3);
         foreach ($equipsArray as $euipment) {
             $carObj->addCarEquipment($this->getReference('car_eqp_' . $equipArray[$euipment]));
         }
         $manager->persist($carObj);
         $manager->flush();
         $this->addReference('car_data_' . $i, $carObj);
     }
 }