Completed
Push — master ( 0ac209...7b7af5 )
by
unknown
13:18
created

LoadRFMMetricCategoryData::getDependencies()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
dl 0
loc 4
rs 10
c 1
b 1
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace OroCRM\Bundle\AnalyticsBundle\Tests\Functional\DataFixtures;
4
5
use Doctrine\Common\DataFixtures\AbstractFixture;
6
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
7
use Doctrine\Common\Persistence\ObjectManager;
8
9
use OroCRM\Bundle\AnalyticsBundle\Entity\RFMMetricCategory;
10
use OroCRM\Bundle\ChannelBundle\Entity\Channel;
11
12
class LoadRFMMetricCategoryData extends AbstractFixture implements DependentFixtureInterface
13
{
14
    /**
15
     * @var array
16
     */
17
    protected $data = [
18
        'CustomerChannel.MonetaryCategory' => [
19
            'categoryType' => RFMMetricCategory::TYPE_MONETARY,
20
            'channel' => 'Channel.CustomerChannel',
21
            'categoryIndex' => 8,
22
            'maxValue' => 15,
23
            'minValue' => 5,
24
        ],
25
        'CustomerChannel.FrequencyCategory' => [
26
            'categoryType' => RFMMetricCategory::TYPE_FREQUENCY,
27
            'channel' => 'Channel.CustomerChannel',
28
            'categoryIndex' => 9,
29
            'maxValue' => 17,
30
            'minValue' => 1,
31
        ],
32
        'CustomerChannel.RecencyCategory' => [
33
            'categoryType' => RFMMetricCategory::TYPE_RECENCY,
34
            'channel' => 'Channel.CustomerChannel',
35
            'categoryIndex' => 10,
36
            'maxValue' => 16,
37
            'minValue' => 4,
38
        ],
39
    ];
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function getDependencies()
45
    {
46
        return [__NAMESPACE__ . '\LoadChannelData'];
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function load(ObjectManager $manager)
53
    {
54
        foreach ($this->data as $categoryReference => $data) {
55
            /** @var Channel $channel */
56
            $channel = $this->getReference($data['channel']);
57
58
            $entity = new RFMMetricCategory();
59
            $entity->setChannel($channel)
60
                ->setCategoryType($data['categoryType'])
61
                ->setCategoryIndex($data['categoryIndex'])
62
                ->setMaxValue($data['maxValue'])
63
                ->setMinValue($data['minValue'])
64
            ;
65
66
            $this->setReference($categoryReference, $entity);
67
            $manager->persist($entity);
68
        }
69
        $manager->flush();
70
    }
71
}
72