point-tools/src/Skobkin/Bundle/PointToolsBundle/Entity/SubscriptionEvent.php

108 lines
2.3 KiB
PHP
Raw Normal View History

2015-03-23 15:39:00 +00:00
<?php
namespace Skobkin\Bundle\PointToolsBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Table(name="log", schema="subscriptions", indexes={
2015-05-28 17:36:52 +00:00
* @ORM\Index(name="author_idx", columns={"author_id"}),
* @ORM\Index(name="subscriber_idx", columns={"subscriber_id"}),
* @ORM\Index(name="date_idx", columns={"date"})
* })
* @ORM\Entity(repositoryClass="Skobkin\Bundle\PointToolsBundle\Repository\SubscriptionEventRepository")
* @ORM\HasLifecycleCallbacks
2015-03-23 15:39:00 +00:00
*/
class SubscriptionEvent
{
const ACTION_SUBSCRIBE = 'subscribe';
const ACTION_UNSUBSCRIBE = 'unsubscribe';
/**
* @var int
2015-03-23 15:39:00 +00:00
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
2015-05-28 17:36:52 +00:00
2015-03-23 15:39:00 +00:00
/**
* @var User Blog author
2015-05-28 17:36:52 +00:00
*
2015-03-23 15:39:00 +00:00
* @ORM\ManyToOne(targetEntity="User", inversedBy="newSubscriberEvents")
* @ORM\JoinColumn(name="author_id", nullable=false)
*/
private $author;
2015-05-28 17:36:52 +00:00
/**
* @var User Blog subscriber
*
* @ORM\ManyToOne(targetEntity="User")
2015-05-28 17:36:52 +00:00
* @ORM\JoinColumn(name="subscriber_id", nullable=false)
*/
private $subscriber;
2015-03-23 15:39:00 +00:00
/**
* @var \DateTime
*
* @ORM\Column(name="date", type="datetime", nullable=false)
*/
2015-05-28 17:36:52 +00:00
private $date;
2015-03-23 15:39:00 +00:00
/**
* @var string
*
* @ORM\Column(name="action", type="string", length=12, nullable=false)
*/
private $action;
/**
* @param User $author
* @param User $subscriber
* @param string $action
*/
public function __construct(User $author, User $subscriber, string $action = self::ACTION_SUBSCRIBE)
{
$this->author = $author;
$this->subscriber = $subscriber;
$this->action = $action;
}
/**
* @ORM\PrePersist
*/
public function onCreate()
{
if (!$this->date) {
$this->date = new \DateTime();
}
}
public function getId(): int
2015-03-23 15:39:00 +00:00
{
return $this->id;
}
public function getDate(): \DateTime
2015-03-23 15:39:00 +00:00
{
2015-05-28 17:36:52 +00:00
return $this->date;
2015-03-23 15:39:00 +00:00
}
public function getSubscriber(): User
2015-03-23 15:39:00 +00:00
{
return $this->subscriber;
}
public function getAuthor(): User
2015-03-23 15:39:00 +00:00
{
return $this->author;
}
public function getAction(): string
2015-03-23 15:39:00 +00:00
{
return $this->action;
}
}