3 namespace Wallabag\CoreBundle\Entity
;
5 use Doctrine\Common\Collections\ArrayCollection
;
6 use Doctrine\ORM\Mapping
as ORM
;
7 use Psr\Log\LoggerInterface
;
8 use Psr\Log\NullLogger
;
9 use Wallabag\CoreBundle\Notifications\ActionInterface
;
10 use Wallabag\CoreBundle\Notifications\NotificationInterface
;
11 use Wallabag\UserBundle\Entity\User
;
16 * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\NotificationRepository")
17 * @ORM\Table(name="`notification`")
19 class Notification
implements NotificationInterface
{
24 * @ORM\Column(name="id", type="integer")
26 * @ORM\GeneratedValue(strategy="AUTO")
34 * @ORM\Column(name="type", type="integer")
41 * @ORM\ManyToOne(targetEntity="Wallabag\UserBundle\Entity\User", inversedBy="notifications")
46 * @var \DateTime $timestamp
48 * @ORM\Column(name="timestamp", type="datetime")
55 * @ORM\Column(name="title", type="string")
62 * @ORM\Column(name="read", type="boolean")
69 * @var ArrayCollection<ActionInterface>
71 * @ORM\Column(name="actions", type="array", nullable=true)
75 protected $actionTypes = [];
79 const TYPE_RELEASE
= 2;
82 public function __construct(User
$user = null)
84 $this->logger
= new NullLogger();
85 $this->timestamp
= new \
DateTime();
86 $this->actions
= new ArrayCollection();
92 * @param LoggerInterface $logger
93 * @return NotificationInterface
95 public function setLogger(LoggerInterface
$logger)
97 $this->logger
= $logger;
104 public function getId()
112 public function getType()
119 * @return NotificationInterface
121 public function setType($type)
130 public function getUser()
137 * @return NotificationInterface
139 public function setUser(User
$user)
148 public function getTimestamp()
150 return $this->timestamp
;
154 * @param \DateTime $timestamp
155 * @return NotificationInterface
157 public function setTimestamp(\DateTime
$timestamp)
159 $this->timestamp
= $timestamp;
166 public function getTitle()
172 * @param string $title
173 * @return NotificationInterface
175 public function setTitle($title)
177 $this->title
= $title;
184 public function isRead()
191 * @return NotificationInterface
193 public function setRead($read)
200 * @param ActionInterface $action
201 * @return NotificationInterface
202 * @throws \InvalidArgumentException
204 public function addAction(ActionInterface
$action)
206 if (isset($this->actionTypes
[$action->getType()])) {
207 throw new \
InvalidArgumentException('The notification already has a primary action');
209 $this->actionTypes
[$action->getType()] = true;
210 $this->actions
->add($action);
215 * @return ArrayCollection<ActionInterface>
217 public function getActions()
219 return $this->actions
;