Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.69 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\DataFixtures;
  4.  
  5. use App\Entity\BackLink;
  6. use App\Entity\Company;
  7. use App\Entity\User;
  8. use App\Entity\Website;
  9. use DateTime;
  10. use Doctrine\Bundle\FixturesBundle\Fixture;
  11. use Doctrine\Persistence\ObjectManager;
  12. use Doctrine\ORM\EntityManagerInterface;
  13. use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
  14.  
  15. class BackLinkFixtures extends Fixture
  16. {
  17.     private $companyList = [];
  18.  
  19.     private function createCompanies(): void
  20.     {
  21.         for ($i = 0; $i < 3; $i++) {
  22.             array_push($this->companyList);
  23.         }
  24.     }
  25.  
  26.     private function createWebsites(string $url): void
  27.     {
  28.         for ($i = 0; $i < 10; $i++) {
  29.             $this->newWebsite($this->companyList[mt_rand(0, count($this->companyList))], $url);
  30.         }
  31.     }
  32.  
  33.     private function newWebsite(Company $company, string $url): Website
  34.     {
  35.         $user = new User();
  36.         $website = new Website($this->newUser($user));
  37.         $website->setCompany($company)
  38.             ->setUrl($url);
  39.         $this->em->persist($website);
  40.         $this->em->flush();
  41.         return $website;
  42.     }
  43.  
  44.     private function newCompany(Company $company): Company
  45.     {
  46.         $company
  47.             ->setName($company['name'])
  48.             ->setSiret($company['siret'])
  49.             ->setAddressLine1($company['AddressLine1'])
  50.             ->setAddressLine2($company['AddressLine2'])
  51.             ->setPostalCode($company['PostalCode'])
  52.             ->setCity($company['city'])
  53.             ->setCountry($company['country'])
  54.             ->setPhone($company['phone'])
  55.             ->setEmail($company['email']);
  56.         $this->em->persist($company);
  57.         return $company;
  58.     }
  59.  
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement