/**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     $machineCount = 30;
     $machine = $this->getReference('machine');
     $status = 'A';
     $currency = $this->getReference('eur');
     $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.";
     $machines = array('agriculture' => array('farming'), 'construction' => array('bagger', 'lader'), 'forestry' => array('forwarder', 'harwarder'));
     $machineArray = array_keys($machines);
     $milageArray = array(5000, 10000, 15000, 20000, 25000, 40000, 50000, 55000, 65000, 70000, 75000, 90000, 100000, 125000, 150000);
     $colorsArray = array('red', 'green', 'blue', 'yellow', 'black', 'orange');
     $fuelArray = array('diesel', 'petrol', 'cng', 'lpg', 'electric', 'hybrid');
     $ownersArray = array('1', '2', '3', 'more_than_3');
     $condtArray = array('new', 'second_hand');
     $salvgArray = array('yes', 'no');
     $makeArray = array('accord', 'amazon', 'bell', 'atlas', 'becker', 'borco');
     for ($i = 1; $i <= $machineCount; $i++) {
         $mfgYear = rand(date("Y", strtotime("-30 year")), date('Y'));
         $category = $machineArray[array_rand($machineArray)];
         $category2 = $machines[$category][array_rand($machines[$category])];
         $adObj4 = new Ad();
         $adObj4->setUser($this->getReference('user_normal_' . rand(1, 5)));
         $adObj4->setVertical($machine);
         $adObj4->setCategory1($this->getReference($category));
         $adObj4->setCategory2($this->getReference($category2));
         $adObj4->setStatus($status);
         $adObj4->setPrice(rand(11111, 999999));
         $adObj4->setCurrency($currency);
         $adObj4->setTitle($category . " " . $category2 . " " . $mfgYear);
         $adObj4->setDescription($dummyText);
         $adObj4->setCreatedAt(new \DateTime('NOW'));
         $manager->persist($adObj4);
         $manager->flush();
         $this->addReference('machine_vertical' . $i, $adObj4);
         $machineObj = new Machine();
         $machineObj->setAd($adObj4);
         $machineObj->setMfgYear($mfgYear);
         $machineObj->setMileage($milageArray[array_rand($milageArray)]);
         $machineObj->setVin(rand(11111111, 99999999));
         $machineObj->setPower(rand(111, 9999));
         $machineObj->setFuelConsumption(rand(1, 500) . "L");
         $machineObj->setCapacity($this->getReference("capacity_" . rand(4, 62)));
         $machineObj->setModel('random');
         $machineObj->setColor($this->getReference($colorsArray[array_rand($colorsArray)]));
         $machineObj->setMachineMake($this->getReference('machine_' . $makeArray[array_rand($makeArray)]));
         $machineObj->setFuelType($this->getReference($fuelArray[array_rand($fuelArray)]));
         $machineObj->setOwners($this->getReference($ownersArray[array_rand($ownersArray)]));
         $machineObj->setConditions($this->getReference($condtArray[array_rand($condtArray)]));
         $machineObj->setSalvage($this->getReference('salvage_' . $salvgArray[array_rand($salvgArray)]));
         $manager->persist($machineObj);
         $manager->flush();
     }
 }
 /**
  */
 public function step2Action(Request $request)
 {
     $adData = $request->getSession()->get('ad');
     $em = $this->getDoctrine()->getManager();
     $vertical = $em->getRepository('Entity:Vertical')->find($adData['vertical_id']);
     $category1 = $em->getRepository('Entity:Category1')->find($adData['category1_id']);
     $category2 = $em->getRepository('Entity:Category2')->find($adData['category2_id']);
     $category3 = $em->getRepository('Entity:Category3')->find($adData['category3_id']);
     $className = '\\Entity\\' . $vertical->getAdClass();
     $formName = 'Rmc\\' . $vertical->getAdClass() . '\\PostBundle\\Form\\' . $vertical->getAdClass() . 'PostType';
     $obj = new $className();
     $formType = new $formName();
     if ($vertical->getAdClass() != 'Ad') {
         $adObj = new Ad();
         $adObj->setVertical($vertical);
         $adObj->setCategory1($category1);
         $adObj->setCategory2($category2);
         $adObj->setCategory3($category3);
         $adObj->setStatus('A');
         $obj->setAd($adObj);
     } else {
         $obj->setVertical($vertical);
         $obj->setCategory1($category1);
         $obj->setCategory2($category2);
         $obj->setCategory3($category3);
     }
     // Electronics
     //$obj      = new Ad();
     //$formType = new AdPostType();
     // Car
     //$obj      = new Car();
     //$formType = new CarPostType();
     $form = $this->createForm($formType, $obj);
     $form->add('save', SubmitType::class, array('label' => 'Save'));
     $form->handleRequest($request);
     if ($form->isSubmitted() && $form->isValid()) {
         $em->persist($obj);
         $em->flush();
         $solrIndexService = AdSolrIndexServiceFactory::getIndexManager($this->container, $obj->getAd()->getVertical()->getCode());
         $solrIndexService->updateSolrIndex($obj);
         $request->getSession()->getFlashBag()->set('success', 'Your advert has been successfully placed');
         return $this->redirectToRoute('rmc_core_base_homepage');
     }
     return $this->render('RmcCoreAdPostBundle:Default:step2.html.twig', array('form' => $form->createView()));
 }
 /**
  * {@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);
     }
 }