Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\DataFixtures;
- use App\Entity\BackLink;
- use App\Entity\Company;
- use App\Entity\User;
- use App\Entity\Website;
- use DateTime;
- use Doctrine\Bundle\FixturesBundle\Fixture;
- use Doctrine\Persistence\ObjectManager;
- use Doctrine\ORM\EntityManagerInterface;
- use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
- class BackLinkFixtures extends Fixture
- {
- private $companyList = [];
- private $websiteList = [];
- public function load(): void
- {
- foreach ($this->websiteList as $website) {
- $id = mt_rand(1, 100);
- $this->createBackLink(
- true,
- 'Technology' . $id,
- 'www.technology.com' . $id,
- 'Technology Comment' . $id,
- $website
- );
- }
- }
- private function createBackLink(bool $pulse, string $keyword, string $link, string $comment, Website $website, User $user): void {
- $backLink = new BackLink($user);
- $backLink->setPulse($pulse);
- $backLink->setCreatedBy($user);
- $backLink->setComment($comment);
- $backLink->setKeyword($keyword);
- $backLink->setLink($link);
- $backLink->setWebsite($website);
- $this->em->persist($backLink);
- $this->em->flush();
- }
- private function createCompanies(): void
- {
- for ($i = 0; $i < 3; $i++) {
- array_push($this->companyList, $this->newCompany($companyObject));
- }
- }
- private function createWebsites(string $url): void
- {
- for ($i = 0; $i < 10; $i++) {
- array_push($this->websiteList, $this->newWebsite($this->companyList[mt_rand(0, count($this->companyList))], $url));
- }
- }
- private function newWebsite(Company $company, string $url): Website
- {
- $user = new User();
- $website = new Website($this->newUser($user));
- $website->setCompany($company)
- ->setUrl($url);
- $this->em->persist($website);
- $this->em->flush();
- return $website;
- }
- private function newCompany(Company $company): Company
- {
- $company
- ->setName($company['name'])
- ->setSiret($company['siret'])
- ->setAddressLine1($company['AddressLine1'])
- ->setAddressLine2($company['AddressLine2'])
- ->setPostalCode($company['PostalCode'])
- ->setCity($company['city'])
- ->setCountry($company['country'])
- ->setPhone($company['phone'])
- ->setEmail($company['email']);
- $this->em->persist($company);
- return $company;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement