/** * */ public function load(ObjectManager $manager) { foreach ($this->individuals as $individualItem) { $individual = new Individual(); $individual->setUsername(ucfirst($individualItem['name'])); $individual->setPlainPassword($individualItem['name']); $individual->setLogin($individualItem['name']); $individual->setEmail($individualItem['name'] . '@gmail.com'); // Company binding $company = $manager->getRepository('RscineWorkerBundle:Company')->findOneByName($individualItem['company']); if ($company) { $individual->setCompany($company); } // Contact informations binding $contactInformations = new ContactInformation(); for ($i = 0; $i < 4; $i++) { $phoneNumber = $this->generateRandomPhoneNumber(); $phone = new Phone(); $phone->setNumber($phoneNumber); $phone->setType('mobile'); $contactInformations->addPhone($phone); } $email = new Email(); $email->setEmail($individualItem['name'] . '@' . strtolower($individual->getCompany()->getName()) . '.com'); $email->setType('office'); $contactInformations->addEmail($email); // Address binding $address = new Address(); $address->setNumber($individualItem['address']); $address->setStreet($individualItem['company'] . ' avenue'); $address->setPostalCode(00); $district = $manager->getRepository('RscineWorkerBundle:District')->findOneByNumber($individualItem['district']); if ($district) { $address->setDistrict($district); $address->setPostalCode(intval($district->getId() . '000')); } $contactInformations->addAddress($address); $individual->setContactInformation($contactInformations); $manager->persist($individual); } $manager->flush(); }
/** * Add email * * @param Email $email * * @return ContactInformation */ public function addEmail(Email $email) { $this->emails[] = $email; $email->setContactInformation($this); return $this; }