Completed
Push — 1.9 ( d8eb28...5c3e2e )
by
unknown
61:52 queued 29s
created

LoadECommerceDashboard::getDependencies()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace OroCRM\Bundle\DemoDataBundle\Migrations\Data\Demo\ORM;
4
5
use Doctrine\Common\Persistence\ObjectManager;
6
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
7
8
use Oro\Bundle\DashboardBundle\Migrations\Data\ORM\AbstractDashboardFixture;
9
use Oro\Bundle\DashboardBundle\Model\WidgetModel;
10
11
class LoadECommerceDashboard extends AbstractDashboardFixture implements DependentFixtureInterface
12
{
13
    /** @var array */
14
    protected $widgets = [
15
        [
16
            'name'     => 'average_order_amount_chart',
17
            'position' => [0, 0],
18
        ],
19
        [
20
            'name'     => 'new_magento_customers_chart',
21
            'position' => [1, 0],
22
        ],
23
        [
24
            'name'     => 'average_lifetime_sales_chart',
25
            'position' => [0, 1]
26
        ],
27
        [
28
            'name'     => 'revenue_over_time_chart',
29
            'position' => [0, 1],
30
        ],
31
        [
32
            'name'     => 'orders_over_time_chart',
33
            'position' => [0, 1],
34
        ],
35
        [
36
            'name'     => 'purchase_chart',
37
            'position' => [0, 1],
38
        ],
39
    ];
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function getDependencies()
45
    {
46
        return ['Oro\Bundle\DashboardBundle\Migrations\Data\ORM\LoadDashboardData'];
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function load(ObjectManager $manager)
53
    {
54
        $dashboard = $this->findAdminDashboardModel($manager, 'e_commerce');
55
        if (!$dashboard) {
56
            $dashboard = $this->createAdminDashboardModel($manager, 'e_commerce');
57
            $dashboard->setLabel($this->container->get('translator')->trans('orocrm.magento.dashboard.e_commerce'));
58
        }
59
60
        foreach ($this->widgets as $widgetData) {
61
            $widgets = $dashboard->getWidgets()->filter(function (WidgetModel $widget) use ($widgetData) {
62
                return $widget->getName() === $widgetData['name'];
63
            });
64
65
            if (count($widgets)) {
66
                continue;
67
            }
68
69
            $dashboard->addWidget($this->createWidgetModel($widgetData['name'], $widgetData['position']));
70
        }
71
72
        $manager->flush();
73
    }
74
}
75