1 | <?php |
||
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() |
||
94 | |||
95 | /** |
||
96 | * Get date |
||
97 | * |
||
98 | * @return \DateTime |
||
99 | */ |
||
100 | 5 | public function getDate() |
|
104 | |||
105 | /** |
||
106 | * Get subscriber |
||
107 | * |
||
108 | * @return User |
||
109 | */ |
||
110 | 5 | public function getSubscriber() |
|
114 | |||
115 | /** |
||
116 | * Get author |
||
117 | * |
||
118 | * @return User |
||
119 | */ |
||
120 | 2 | public function getAuthor() |
|
124 | |||
125 | /** |
||
126 | * Get action |
||
127 | * |
||
128 | * @return string |
||
129 | */ |
||
130 | 5 | public function getAction() |
|
134 | } |
||
135 |