1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Skobkin\Bundle\PointToolsBundle\Entity; |
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\Mapping as ORM; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @ORM\Table(name="log", schema="subscriptions", indexes={ |
9
|
|
|
* @ORM\Index(name="idx_subscription_author", columns={"author_id"}), |
10
|
|
|
* @ORM\Index(name="idx_subscription_subscriber", columns={"subscriber_id"}), |
11
|
|
|
* @ORM\Index(name="idx_subscription_date", columns={"date"}) |
12
|
|
|
* }) |
13
|
|
|
* @ORM\Entity(repositoryClass="Skobkin\Bundle\PointToolsBundle\Repository\SubscriptionEventRepository", readOnly=true) |
14
|
|
|
*/ |
15
|
|
|
class SubscriptionEvent |
16
|
|
|
{ |
17
|
|
|
public const ACTION_SUBSCRIBE = 'subscribe'; |
18
|
|
|
public const ACTION_UNSUBSCRIBE = 'unsubscribe'; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var int |
22
|
|
|
* |
23
|
|
|
* @ORM\Column(name="id", type="integer") |
24
|
|
|
* @ORM\Id |
25
|
|
|
* @ORM\GeneratedValue(strategy="AUTO") |
26
|
|
|
*/ |
27
|
|
|
private $id; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var User Blog author |
31
|
|
|
* |
32
|
|
|
* @ORM\ManyToOne(targetEntity="User", inversedBy="newSubscriberEvents") |
33
|
|
|
* @ORM\JoinColumn(name="author_id", nullable=false) |
34
|
|
|
*/ |
35
|
|
|
private $author; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var User Blog subscriber |
39
|
|
|
* |
40
|
|
|
* @ORM\ManyToOne(targetEntity="User") |
41
|
|
|
* @ORM\JoinColumn(name="subscriber_id", nullable=false) |
42
|
|
|
*/ |
43
|
|
|
private $subscriber; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var \DateTime |
47
|
|
|
* |
48
|
|
|
* @ORM\Column(name="date", type="datetime", nullable=false) |
49
|
|
|
*/ |
50
|
|
|
private $date; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var string |
54
|
|
|
* |
55
|
|
|
* @ORM\Column(name="action", type="string", length=12, nullable=false) |
56
|
|
|
*/ |
57
|
|
|
private $action; |
58
|
|
|
|
59
|
|
|
|
60
|
|
|
public function __construct(User $author, User $subscriber, string $action = self::ACTION_SUBSCRIBE) |
61
|
|
|
{ |
62
|
|
|
$this->author = $author; |
63
|
|
|
$this->subscriber = $subscriber; |
64
|
|
|
$this->action = $action; |
65
|
|
|
$this->date = new \DateTime(); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function getId(): int |
69
|
|
|
{ |
70
|
|
|
return $this->id; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function getDate(): \DateTime |
74
|
|
|
{ |
75
|
|
|
return $this->date; |
76
|
|
|
} |
77
|
|
|
|
78
|
5 |
|
public function getSubscriber(): User |
79
|
|
|
{ |
80
|
5 |
|
return $this->subscriber; |
81
|
|
|
} |
82
|
|
|
|
83
|
5 |
|
public function getAuthor(): User |
84
|
|
|
{ |
85
|
5 |
|
return $this->author; |
86
|
|
|
} |
87
|
|
|
|
88
|
2 |
|
public function getAction(): string |
89
|
|
|
{ |
90
|
2 |
|
return $this->action; |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|