Completed
Push — master ( a682ba...4851b3 )
by Paweł
40:50
created

LoadMenusData   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 44
ccs 0
cts 34
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B load() 0 33 3
A getOrder() 0 4 1
1
<?php
2
/*
3
 * This file is part of the Superdesk Web Publisher Fixtures Bundle.
4
 *
5
 * Copyright 2015 Sourcefabric z.ú. and contributors.
6
 *
7
 * For the full copyright and license information, please see the
8
 * AUTHORS and LICENSE files distributed with this source code.
9
 *
10
 * @copyright 2015 Sourcefabric z.ú
11
 * @license http://www.superdesk.org/license
12
 */
13
14
namespace SWP\Bundle\FixturesBundle\DataFixtures\PHPCR;
15
16
use Doctrine\Common\DataFixtures\FixtureInterface;
17
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
18
use SWP\Bundle\FixturesBundle\AbstractFixture;
19
use Doctrine\Common\Persistence\ObjectManager;
20
use Symfony\Cmf\Bundle\MenuBundle\Doctrine\Phpcr\Menu;
21
22
class LoadMenusData extends AbstractFixture implements FixtureInterface, OrderedFixtureInterface
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function load(ObjectManager $manager)
28
    {
29
        $tenantPrefix = $this->getTenantPrefix();
30
31
        $env = $this->getEnvironment();
32
        $menus = [
33
            'dev' => [
34
                [
35
                    'name' => 'default',
36
                    'label' => 'Default',
37
                ],
38
            ],
39
            'test' => [
40
                [
41
                    'name' => 'test',
42
                    'label' => 'Test',
43
                ],
44
            ],
45
        ];
46
47
        if (isset($menus[$env])) {
48
            $parent = $manager->find(null, $tenantPrefix.'/menu');
49
            foreach ($menus[$env] as $menuData) {
50
                $menu = new Menu();
51
                $menu->setParentDocument($parent);
52
                $menu->setName($menuData['name']);
53
                $menu->setLabel($menuData['label']);
54
                $manager->persist($menu);
55
            }
56
        }
57
58
        $manager->flush();
59
    }
60
61
    public function getOrder()
62
    {
63
        return 4;
64
    }
65
}
66