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")
33 * @ORM\Column(name="type", type="integer")
40 * @ORM\ManyToOne(targetEntity="Wallabag\UserBundle\Entity\User", inversedBy="notifications")
47 * @ORM\Column(name="timestamp", type="datetime")
54 * @ORM\Column(name="title", type="string")
61 * @ORM\Column(name="description", type="string", nullable=true)
63 protected $description;
68 * @ORM\Column(name="read", type="boolean")
75 * @ORM\Column(name="parameters", type="array", nullable=true)
77 protected $parameters;
82 * @var ArrayCollection<ActionInterface>
84 * @ORM\Column(name="actions", type="array", nullable=true)
88 protected $actionTypes = [];
92 const TYPE_RELEASE
= 2;
94 public function __construct(User
$user = null)
96 $this->logger
= new NullLogger();
97 $this->timestamp
= new \
DateTime();
98 $this->actions
= new ArrayCollection();
99 $this->parameters
= [];
105 * @param LoggerInterface $logger
107 * @return NotificationInterface
109 public function setLogger(LoggerInterface
$logger)
111 $this->logger
= $logger;
119 public function getId()
127 public function getType()
135 * @return NotificationInterface
137 public function setType($type)
147 public function getUser()
155 * @return NotificationInterface
157 public function setUser(User
$user)
167 public function getTimestamp()
169 return $this->timestamp
;
173 * @param \DateTime $timestamp
175 * @return NotificationInterface
177 public function setTimestamp(\DateTime
$timestamp)
179 $this->timestamp
= $timestamp;
187 public function getTitle()
193 * @param string $title
195 * @return NotificationInterface
197 public function setTitle($title)
199 $this->title
= $title;
207 public function isRead()
215 * @return NotificationInterface
217 public function setRead($read)
225 * @param ActionInterface $action
227 * @return NotificationInterface
229 * @throws \InvalidArgumentException
231 public function addAction(ActionInterface
$action)
233 if (isset($this->actionTypes
[$action->getType()])) {
234 throw new \
InvalidArgumentException('The notification already has a primary action');
236 $this->actionTypes
[$action->getType()] = true;
237 $this->actions
->add($action);
243 * @return ArrayCollection<ActionInterface>
245 public function getActions()
247 return $this->actions
;
253 public function getDescription()
255 return $this->description
;
259 * @param string $description
261 * @return Notification
263 public function setDescription($description)
265 $this->description
= $description;
273 public function getParameters()
275 return $this->parameters
;
279 * @param array $parameters
281 * @return Notification
283 public function setParameters($parameters)
285 $this->parameters
= $parameters;
292 * @param string $value
294 * @return Notification
296 * @throws \InvalidArgumentException
298 public function addParameter($key, $value)
300 if (in_array($key, $this->parameters
, true)) {
301 throw new \
InvalidArgumentException('This parameter already is set');
304 $this->parameters
[$key] = $value;