|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Skobkin\Bundle\PointToolsBundle\DataFixtures\ORM; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\Common\DataFixtures\AbstractFixture; |
|
6
|
|
|
use Doctrine\Common\DataFixtures\OrderedFixtureInterface; |
|
7
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
|
8
|
|
|
use Skobkin\Bundle\PointToolsBundle\Entity\Subscription; |
|
9
|
|
|
use Skobkin\Bundle\PointToolsBundle\Entity\SubscriptionEvent; |
|
10
|
|
|
use Skobkin\Bundle\PointToolsBundle\Entity\User; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Load user subscriptions |
|
14
|
|
|
*/ |
|
15
|
|
|
class LoadSubscribersData extends AbstractFixture implements OrderedFixtureInterface |
|
16
|
|
|
{ |
|
17
|
|
|
public function load(ObjectManager $om) |
|
18
|
|
|
{ |
|
19
|
|
|
/** @var User[] $users */ |
|
20
|
|
|
$users = [ |
|
21
|
|
|
99999 => $this->getReference('test_user_99999'), |
|
22
|
|
|
99998 => $this->getReference('test_user_99998'), |
|
23
|
|
|
99997 => $this->getReference('test_user_99997'), |
|
24
|
|
|
99996 => $this->getReference('test_user_99996'), |
|
25
|
|
|
99995 => $this->getReference('test_user_99995'), |
|
26
|
|
|
]; |
|
27
|
|
|
|
|
28
|
|
|
$subscriptions = [ |
|
29
|
|
|
99999 => [99998, 99997, 99996, 99995], |
|
30
|
|
|
99998 => [99999, 99997], |
|
31
|
|
|
99997 => [99999], |
|
32
|
|
|
]; |
|
33
|
|
|
|
|
34
|
|
|
foreach ($users as $key => $user) { |
|
35
|
|
|
foreach ($subscriptions[$key] as $userId) { |
|
36
|
|
|
$subscriber = $users[$userId]; |
|
37
|
|
|
$subscription = new Subscription($user, $subscriber); |
|
38
|
|
|
$subscriptionEvent = new SubscriptionEvent($user, $subscriber, SubscriptionEvent::ACTION_SUBSCRIBE); |
|
39
|
|
|
$om->persist($subscription); |
|
40
|
|
|
$om->persist($subscriptionEvent); |
|
41
|
|
|
$user->addSubscriber($subscription); |
|
42
|
|
|
} |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
$om->flush(); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function getOrder(): int |
|
49
|
|
|
{ |
|
50
|
|
|
return 4; |
|
51
|
|
|
} |
|
52
|
|
|
} |