Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.64 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.     private $websiteList = [];
  19.  
  20.     public function load(): void
  21.     {
  22.         foreach ($this->websiteList as $website) {
  23.             $id = mt_rand(1, 100);
  24.             $this->createBackLink(
  25.                 true,
  26.                 'Technology' . $id,
  27.                 'www.technology.com' . $id,
  28.                 'Technology Comment' . $id,
  29.                 $website
  30.             );
  31.         }
  32.     }
  33.  
  34.     private function createBackLink(bool $pulse, string $keyword, string $link, string $comment, Website $website, User $user): void {
  35.         $backLink = new BackLink($user);
  36.         $backLink->setPulse($pulse);
  37.         $backLink->setCreatedBy($user);
  38.         $backLink->setComment($comment);
  39.         $backLink->setKeyword($keyword);
  40.         $backLink->setLink($link);
  41.         $backLink->setWebsite($website);
  42.         $this->em->persist($backLink);
  43.         $this->em->flush();
  44.     }
  45.  
  46.     private function createCompanies(): void
  47.     {
  48.         for ($i = 0; $i < 3; $i++) {
  49.             array_push($this->companyList, $this->newCompany($companyObject));
  50.         }
  51.     }
  52.  
  53.     private function createWebsites(string $url): void
  54.     {
  55.         for ($i = 0; $i < 10; $i++) {
  56.             array_push($this->websiteList, $this->newWebsite($this->companyList[mt_rand(0, count($this->companyList))], $url));
  57.         }
  58.     }
  59.  
  60.     private function newWebsite(Company $company, string $url): Website
  61.     {
  62.         $user = new User();
  63.         $website = new Website($this->newUser($user));
  64.         $website->setCompany($company)
  65.             ->setUrl($url);
  66.         $this->em->persist($website);
  67.         $this->em->flush();
  68.         return $website;
  69.     }
  70.  
  71.     private function newCompany(Company $company): Company
  72.     {
  73.         $company
  74.             ->setName($company['name'])
  75.             ->setSiret($company['siret'])
  76.             ->setAddressLine1($company['AddressLine1'])
  77.             ->setAddressLine2($company['AddressLine2'])
  78.             ->setPostalCode($company['PostalCode'])
  79.             ->setCity($company['city'])
  80.             ->setCountry($company['country'])
  81.             ->setPhone($company['phone'])
  82.             ->setEmail($company['email']);
  83.         $this->em->persist($company);
  84.         return $company;
  85.     }
  86.  
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement