|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Genres\DataFixtures; |
|
4
|
|
|
|
|
5
|
|
|
use App\Genres\Entity\Genre; |
|
6
|
|
|
use App\Genres\Entity\GenreTranslations; |
|
7
|
|
|
use Doctrine\Bundle\FixturesBundle\Fixture; |
|
8
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
|
9
|
|
|
use Doctrine\ORM\EntityManager; |
|
10
|
|
|
|
|
11
|
|
|
class GenresFixtures extends Fixture |
|
12
|
|
|
{ |
|
13
|
|
|
public const GENRE_DRAMA_ID = 1; |
|
14
|
|
|
public const GENRE_DRAMA_TMDB_ID = 18; |
|
15
|
|
|
public const GENRE_COMEDY_ID = 2; |
|
16
|
|
|
public const GENRE_CRIMINAL_ID = 3; |
|
17
|
|
|
|
|
18
|
|
|
public function load(ObjectManager $manager): void |
|
19
|
|
|
{ |
|
20
|
|
|
if ($manager instanceof EntityManager === false) { |
|
21
|
|
|
throw new \InvalidArgumentException('MoviesFixtures $manager should be instance of EntityManager'); |
|
22
|
|
|
} |
|
23
|
|
|
/* @var $manager EntityManager */ |
|
24
|
|
|
$manager->getConnection()->exec("ALTER SEQUENCE genres_id_seq RESTART WITH 1; UPDATE genres SET id=nextval('genres_id_seq');"); |
|
25
|
|
|
|
|
26
|
|
|
$drama = new Genre(self::GENRE_DRAMA_TMDB_ID); // https://www.themoviedb.org/genre/18-drama/movie |
|
27
|
|
|
$drama |
|
28
|
|
|
->addTranslation(new GenreTranslations($drama, 'en', 'Drama')) |
|
29
|
|
|
->addTranslation(new GenreTranslations($drama, 'uk', 'Драма')) |
|
30
|
|
|
->addTranslation(new GenreTranslations($drama, 'ru', 'Драма')); |
|
31
|
|
|
|
|
32
|
|
|
$comedy = new Genre(); |
|
33
|
|
|
$comedy |
|
34
|
|
|
->addTranslation(new GenreTranslations($comedy, 'en', 'Comedy')) |
|
35
|
|
|
->addTranslation(new GenreTranslations($comedy, 'uk', 'Комедия')) |
|
36
|
|
|
->addTranslation(new GenreTranslations($comedy, 'ru', 'Комедія')); |
|
37
|
|
|
|
|
38
|
|
|
$criminal = new Genre(); |
|
39
|
|
|
$criminal |
|
40
|
|
|
->addTranslation(new GenreTranslations($criminal, 'en', 'Criminal')) |
|
41
|
|
|
->addTranslation(new GenreTranslations($criminal, 'uk', 'Криминал')) |
|
42
|
|
|
->addTranslation(new GenreTranslations($criminal, 'ru', 'Кримінал')); |
|
43
|
|
|
|
|
44
|
|
|
$manager->persist($drama); |
|
45
|
|
|
$manager->persist($comedy); |
|
46
|
|
|
$manager->persist($criminal); |
|
47
|
|
|
$manager->flush(); |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|