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
;
17 * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\NotificationRepository")
18 * @ORM\Table(name="`notification`")
20 class Notification
implements NotificationInterface
25 * @ORM\Column(name="id", type="integer")
27 * @ORM\GeneratedValue(strategy="AUTO")
35 * @ORM\Column(name="type", type="integer")
42 * @ORM\ManyToOne(targetEntity="Wallabag\UserBundle\Entity\User", inversedBy="notifications")
48 * @ORM\Column(name="timestamp", type="datetime")
55 * @ORM\Column(name="title", type="string")
62 * @ORM\Column(name="description", type="string", nullable=true)
64 protected $description;
69 * @ORM\Column(name="read", type="boolean")
76 * @ORM\Column(name="parameters", type="array", nullable=true)
78 protected $parameters;
83 * @var ArrayCollection<ActionInterface>
85 * @ORM\Column(name="actions", type="array", nullable=true)
89 protected $actionTypes = [];
93 const TYPE_RELEASE
= 2;
96 public function __construct(User
$user = null)
98 $this->logger
= new NullLogger();
99 $this->timestamp
= new \
DateTime();
100 $this->actions
= new ArrayCollection();
101 $this->parameters
= [];
107 * @param LoggerInterface $logger
109 * @return NotificationInterface
111 public function setLogger(LoggerInterface
$logger)
113 $this->logger
= $logger;
121 public function getId()
129 public function getType()
137 * @return NotificationInterface
139 public function setType($type)
149 public function getUser()
157 * @return NotificationInterface
159 public function setUser(User
$user)
169 public function getTimestamp()
171 return $this->timestamp
;
175 * @param \DateTime $timestamp
177 * @return NotificationInterface
179 public function setTimestamp(\DateTime
$timestamp)
181 $this->timestamp
= $timestamp;
189 public function getTitle()
195 * @param string $title
197 * @return NotificationInterface
199 public function setTitle($title)
201 $this->title
= $title;
209 public function isRead()
217 * @return NotificationInterface
219 public function setRead($read)
227 * @param ActionInterface $action
229 * @return NotificationInterface
230 * @throws \InvalidArgumentException
232 public function addAction(ActionInterface
$action)
234 if (isset($this->actionTypes
[$action->getType()])) {
235 throw new \
InvalidArgumentException('The notification already has a primary action');
237 $this->actionTypes
[$action->getType()] = true;
238 $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;