2015-03-23 15:39:00 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Skobkin\Bundle\PointToolsBundle\Entity;
|
|
|
|
|
|
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SubscriptionEvent
|
|
|
|
*
|
2016-12-11 03:03:59 +00:00
|
|
|
* @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"})
|
|
|
|
* })
|
2016-03-23 16:59:06 +00:00
|
|
|
* @ORM\Entity(repositoryClass="Skobkin\Bundle\PointToolsBundle\Repository\SubscriptionEventRepository")
|
2015-05-28 22:47:06 +00:00
|
|
|
* @ORM\HasLifecycleCallbacks
|
2015-03-23 15:39:00 +00:00
|
|
|
*/
|
|
|
|
class SubscriptionEvent
|
|
|
|
{
|
|
|
|
const ACTION_SUBSCRIBE = 'subscribe';
|
|
|
|
const ACTION_UNSUBSCRIBE = 'unsubscribe';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var integer
|
|
|
|
*
|
|
|
|
* @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", inversedBy="newSubscriptionEvents")
|
|
|
|
* @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;
|
|
|
|
|
2015-05-28 22:47:06 +00:00
|
|
|
|
2016-12-11 23:21:05 +00:00
|
|
|
/**
|
|
|
|
* @param User $author
|
|
|
|
* @param User $subscriber
|
|
|
|
* @param string $action
|
|
|
|
*/
|
|
|
|
public function __construct(User $author = null, User $subscriber = null, $action = self::ACTION_SUBSCRIBE)
|
|
|
|
{
|
|
|
|
$this->author = $author;
|
|
|
|
$this->subscriber = $subscriber;
|
|
|
|
$this->action = $action;
|
|
|
|
}
|
|
|
|
|
2015-05-28 22:47:06 +00:00
|
|
|
/**
|
|
|
|
* @ORM\PrePersist
|
|
|
|
*/
|
|
|
|
public function onCreate()
|
|
|
|
{
|
|
|
|
if (!$this->date) {
|
|
|
|
$this->date = new \DateTime();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-23 15:39:00 +00:00
|
|
|
/**
|
|
|
|
* Get id
|
|
|
|
*
|
2015-05-28 17:36:52 +00:00
|
|
|
* @return integer
|
2015-03-23 15:39:00 +00:00
|
|
|
*/
|
|
|
|
public function getId()
|
|
|
|
{
|
|
|
|
return $this->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-05-28 17:36:52 +00:00
|
|
|
* Get date
|
2015-03-23 15:39:00 +00:00
|
|
|
*
|
|
|
|
* @return \DateTime
|
|
|
|
*/
|
2015-05-28 17:36:52 +00:00
|
|
|
public function getDate()
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get subscriber
|
|
|
|
*
|
|
|
|
* @return User
|
|
|
|
*/
|
|
|
|
public function getSubscriber()
|
|
|
|
{
|
|
|
|
return $this->subscriber;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get author
|
|
|
|
*
|
|
|
|
* @return User
|
|
|
|
*/
|
|
|
|
public function getAuthor()
|
|
|
|
{
|
|
|
|
return $this->author;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get action
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getAction()
|
|
|
|
{
|
|
|
|
return $this->action;
|
|
|
|
}
|
|
|
|
}
|