|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Skobkin\Bundle\PointToolsBundle\Entity; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* SubscriptionEvent |
|
9
|
|
|
* |
|
10
|
|
|
* @ORM\Table(name="log", schema="subscriptions", indexes={ |
|
11
|
|
|
* @ORM\Index(name="author_idx", columns={"author_id"}), |
|
12
|
|
|
* @ORM\Index(name="subscriber_idx", columns={"subscriber_id"}), |
|
13
|
|
|
* @ORM\Index(name="date_idx", columns={"date"}) |
|
14
|
|
|
* }) |
|
15
|
|
|
* @ORM\Entity(repositoryClass="Skobkin\Bundle\PointToolsBundle\Repository\SubscriptionEventRepository") |
|
16
|
|
|
* @ORM\HasLifecycleCallbacks |
|
17
|
|
|
*/ |
|
18
|
|
|
class SubscriptionEvent |
|
19
|
|
|
{ |
|
20
|
|
|
const ACTION_SUBSCRIBE = 'subscribe'; |
|
21
|
|
|
const ACTION_UNSUBSCRIBE = 'unsubscribe'; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var integer |
|
25
|
|
|
* |
|
26
|
|
|
* @ORM\Column(name="id", type="integer") |
|
27
|
|
|
* @ORM\Id |
|
28
|
|
|
* @ORM\GeneratedValue(strategy="AUTO") |
|
29
|
|
|
*/ |
|
30
|
|
|
private $id; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var User Blog author |
|
34
|
|
|
* |
|
35
|
|
|
* @ORM\ManyToOne(targetEntity="User", inversedBy="newSubscriberEvents") |
|
36
|
|
|
* @ORM\JoinColumn(name="author_id", nullable=false) |
|
37
|
|
|
*/ |
|
38
|
|
|
private $author; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @var User Blog subscriber |
|
42
|
|
|
* |
|
43
|
|
|
* @ORM\ManyToOne(targetEntity="User", inversedBy="newSubscriptionEvents") |
|
44
|
|
|
* @ORM\JoinColumn(name="subscriber_id", nullable=false) |
|
45
|
|
|
*/ |
|
46
|
|
|
private $subscriber; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @var \DateTime |
|
50
|
|
|
* |
|
51
|
|
|
* @ORM\Column(name="date", type="datetime", nullable=false) |
|
52
|
|
|
*/ |
|
53
|
|
|
private $date; |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @var string |
|
57
|
|
|
* |
|
58
|
|
|
* @ORM\Column(name="action", type="string", length=12, nullable=false) |
|
59
|
|
|
*/ |
|
60
|
|
|
private $action; |
|
61
|
|
|
|
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @param User $author |
|
65
|
|
|
* @param User $subscriber |
|
66
|
|
|
* @param string $action |
|
67
|
|
|
*/ |
|
68
|
|
|
public function __construct(User $author = null, User $subscriber = null, $action = self::ACTION_SUBSCRIBE) |
|
69
|
|
|
{ |
|
70
|
|
|
$this->author = $author; |
|
71
|
|
|
$this->subscriber = $subscriber; |
|
72
|
|
|
$this->action = $action; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @ORM\PrePersist |
|
77
|
|
|
*/ |
|
78
|
|
|
public function onCreate() |
|
79
|
|
|
{ |
|
80
|
|
|
if (!$this->date) { |
|
81
|
|
|
$this->date = new \DateTime(); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Get id |
|
87
|
|
|
* |
|
88
|
|
|
* @return integer |
|
89
|
|
|
*/ |
|
90
|
|
|
public function getId() |
|
91
|
|
|
{ |
|
92
|
|
|
return $this->id; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Get date |
|
97
|
|
|
* |
|
98
|
|
|
* @return \DateTime |
|
99
|
|
|
*/ |
|
100
|
5 |
|
public function getDate() |
|
101
|
|
|
{ |
|
102
|
5 |
|
return $this->date; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* Get subscriber |
|
107
|
|
|
* |
|
108
|
|
|
* @return User |
|
109
|
|
|
*/ |
|
110
|
5 |
|
public function getSubscriber() |
|
111
|
|
|
{ |
|
112
|
5 |
|
return $this->subscriber; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* Get author |
|
117
|
|
|
* |
|
118
|
|
|
* @return User |
|
119
|
|
|
*/ |
|
120
|
2 |
|
public function getAuthor() |
|
121
|
|
|
{ |
|
122
|
2 |
|
return $this->author; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Get action |
|
127
|
|
|
* |
|
128
|
|
|
* @return string |
|
129
|
|
|
*/ |
|
130
|
5 |
|
public function getAction() |
|
131
|
|
|
{ |
|
132
|
5 |
|
return $this->action; |
|
133
|
|
|
} |
|
134
|
|
|
} |
|
135
|
|
|
|