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;
81 public function __construct(User
$user = null)
83 $this->logger
= new NullLogger();
84 $this->timestamp
= new \
DateTime();
85 $this->actions
= new ArrayCollection();
91 * @param LoggerInterface $logger
92 * @return NotificationInterface
94 public function setLogger(LoggerInterface
$logger)
96 $this->logger
= $logger;
103 public function getId()
111 public function getType()
118 * @return NotificationInterface
120 public function setType($type)
129 public function getUser()
136 * @return NotificationInterface
138 public function setUser(User
$user)
147 public function getTimestamp()
149 return $this->timestamp
;
153 * @param \DateTime $timestamp
154 * @return NotificationInterface
156 public function setTimestamp(\DateTime
$timestamp)
158 $this->timestamp
= $timestamp;
165 public function getTitle()
171 * @param string $title
172 * @return NotificationInterface
174 public function setTitle($title)
176 $this->title
= $title;
183 public function isRead()
190 * @return NotificationInterface
192 public function setRead($read)
199 * @param ActionInterface $action
200 * @return NotificationInterface
201 * @throws \InvalidArgumentException
203 public function addAction(ActionInterface
$action)
205 if (isset($this->actionTypes
[$action->getType()])) {
206 throw new \
InvalidArgumentException('The notification already has a primary action');
208 $this->actionTypes
[$action->getType()] = true;
209 $this->actions
->add($action);
214 * @return ArrayCollection<ActionInterface>
216 public function getActions()
218 return $this->actions
;