Skip to content
Snippets Groups Projects
Select Git revision
  • e3c8eb91030b24a95dde65b6e097abf10b3b5a5e
  • main default
  • 35-cgu
  • 34-peertube-support
  • 27-add-autoplay-to-iframe
  • 33-bug-on-youtube-embed-urls
  • RC-Rekall-v1.1-fix_lpo
  • tuleap-140-go-back-to-my-capsules-page-when-i-m-on-capsule-preview-page
  • RC-Rekall-v1.2-fix10
  • RC-Rekall-v1.2-fix9
  • RC-Rekall-v1.2-fix8
  • RC-Rekall-v1.2-fix7
  • RC-Rekall-v1.2-fix6
  • RC-Rekall-v1.2-fix5
  • RC-Rekall-v1.2-fix4
  • RC-Rekall-v1.2-fix3
  • RC-Rekall-v1.2-fix2
  • RC-Rekall-v1.2-fix1
  • RC-Rekall-v1.1-fix-3
  • RC-Rekall-v1.1-fix-2
  • RC-Rekall-v1.1-fix-1
  • RC-Rekall-v1.1-delivered
  • preprod20220209-1535
23 results

GroupFixtures.php

Blame
  • GroupFixtures.php 1.22 KiB
    <?php
    
    namespace App\DataFixtures;
    
    use App\Entity\Group;
    use App\Entity\User;
    use Doctrine\Bundle\FixturesBundle\Fixture;
    use Doctrine\Common\DataFixtures\DependentFixtureInterface;
    use Doctrine\Persistence\ObjectManager;
    use Symfony\Contracts\Translation\TranslatorInterface;
    
    class GroupFixtures extends Fixture implements DependentFixtureInterface
    {
        private TranslatorInterface $translator;
    
        public function __construct(TranslatorInterface $translator)
        {
            $this->translator = $translator;
        }
    
        public function load(ObjectManager $manager): void
        {
            $user_repository = $manager->getRepository(User::class);
            $group_author = $user_repository->findOneBy(['email' => "defaultUser@localhost.com"]);
            if (! $group_author instanceof User) {
                throw new \Exception("User does not exist.");
            }
    
            //TODO: refacto with real group
            $group_all = new Group();
            $group_all->setName($this->translator->trans('groups.filter.no_filter'));
            $group_all->setAuthor($group_author);
            $manager->persist($group_all);
            $manager->flush();
        }
    
        public function getDependencies(): array
        {
            return [
                UserFixtures::class,
            ];
        }
    }