Completed
Push — master ( bb050e...36e41a )
by Paweł
11:10
created

LoadContainersData::load()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 42

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3.6875

Importance

Changes 0
Metric Value
dl 0
loc 42
ccs 7
cts 28
cp 0.25
rs 9.248
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 3.6875
1
<?php
2
3
/*
4
 * This file is part of the Superdesk Web Publisher Fixtures Bundle.
5
 *
6
 * Copyright 2015 Sourcefabric z.ú. and contributors.
7
 *
8
 * For the full copyright and license information, please see the
9
 * AUTHORS and LICENSE files distributed with this source code.
10
 *
11
 * @copyright 2015 Sourcefabric z.ú
12
 * @license http://www.superdesk.org/license
13
 */
14
15
namespace SWP\Bundle\FixturesBundle\DataFixtures\ORM;
16
17
use Doctrine\Common\DataFixtures\FixtureInterface;
18
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
19
use SWP\Bundle\CoreBundle\Model\Container;
20
use SWP\Bundle\FixturesBundle\AbstractFixture;
21
use Doctrine\Common\Persistence\ObjectManager;
22
23
class LoadContainersData extends AbstractFixture implements FixtureInterface, OrderedFixtureInterface
24
{
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function load(ObjectManager $manager)
29 7
    {
30
        $env = $this->getEnvironment();
31 7
        if ('test' !== $env) {
32 7
            $revision = $manager->merge($this->getReference('defult_tenant_revision'));
33
34
            $container1 = $this->container->get('swp.factory.container')->create();
35
            $container1->setName('mainNav');
36
            $container1->setType(1);
37
            $container1->setVisible(true);
38
            $container1->setTenantCode('123abc');
39
            $container1->setRevision($revision);
40
41
            $containerWidget1 = $this->container->get('swp.factory.container_widget')
42
                ->create($container1, $this->getReference('menu_widget_main'));
43
            $manager->persist($containerWidget1);
44
            $container1->addWidget($containerWidget1);
45
            $manager->persist($container1);
46
47
            $container2 = $this->container->get('swp.factory.container')->create();
48
            $container2->setName('footerNav');
49
            $container2->setType(1);
50
            $container2->setVisible(true);
51
            $container2->setTenantCode('123abc');
52
            $container2->setRevision($revision);
53
54
            $containerWidget2 = $this->container->get('swp.factory.container_widget')
55
                ->create($container2, $this->getReference('menu_widget_footer'));
56
            $manager->persist($containerWidget2);
57
            $container2->addWidget($containerWidget2);
58
            $manager->persist($container2);
59 7
60
            $manager->flush();
61 7
        } else {
62
            $this->loadFixtures(
63
                [
64
                    '@SWPFixturesBundle/Resources/fixtures/ORM/'.$env.'/Container.yml',
65
                ],
66 7
                $manager
67
            );
68 7
        }
69
    }
70 7
71
    public function getOrder()
72
    {
73
        return 2;
74
    }
75
}
76