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;
95 public function __construct(User
$user = null)
97 $this->logger
= new NullLogger();
98 $this->timestamp
= new \
DateTime();
99 $this->actions
= new ArrayCollection();
100 $this->parameters
= [];
106 * @param LoggerInterface $logger
108 * @return NotificationInterface
110 public function setLogger(LoggerInterface
$logger)
112 $this->logger
= $logger;
120 public function getId()
128 public function getType()
136 * @return NotificationInterface
138 public function setType($type)
148 public function getUser()
156 * @return NotificationInterface
158 public function setUser(User
$user)
168 public function getTimestamp()
170 return $this->timestamp
;
174 * @param \DateTime $timestamp
176 * @return NotificationInterface
178 public function setTimestamp(\DateTime
$timestamp)
180 $this->timestamp
= $timestamp;
188 public function getTitle()
194 * @param string $title
196 * @return NotificationInterface
198 public function setTitle($title)
200 $this->title
= $title;
208 public function isRead()
216 * @return NotificationInterface
218 public function setRead($read)
226 * @param ActionInterface $action
228 * @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);
242 * @return ArrayCollection<ActionInterface>
244 public function getActions()
246 return $this->actions
;
252 public function getDescription()
254 return $this->description
;
258 * @param string $description
260 * @return Notification
262 public function setDescription($description)
264 $this->description
= $description;
272 public function getParameters()
274 return $this->parameters
;
278 * @param array $parameters
280 * @return Notification
282 public function setParameters($parameters)
284 $this->parameters
= $parameters;
291 * @param string $value
293 * @return Notification
295 * @throws \InvalidArgumentException
297 public function addParameter($key, $value)
299 if (in_array($key, $this->parameters
, true)) {
300 throw new \
InvalidArgumentException('This parameter already is set');
303 $this->parameters
[$key] = $value;