aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Event/Activity
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/CoreBundle/Event/Activity')
-rw-r--r--src/Wallabag/CoreBundle/Event/Activity/Actions/Annotation/AnnotationCreatedEvent.php8
-rw-r--r--src/Wallabag/CoreBundle/Event/Activity/Actions/Annotation/AnnotationDeletedEvent.php8
-rw-r--r--src/Wallabag/CoreBundle/Event/Activity/Actions/Annotation/AnnotationEditedEvent.php8
-rw-r--r--src/Wallabag/CoreBundle/Event/Activity/Actions/Annotation/AnnotationEvent.php39
-rw-r--r--src/Wallabag/CoreBundle/Event/Activity/Actions/Entry/EntryDeletedEvent.php11
-rw-r--r--src/Wallabag/CoreBundle/Event/Activity/Actions/Entry/EntryEditedEvent.php11
-rw-r--r--src/Wallabag/CoreBundle/Event/Activity/Actions/Entry/EntryEvent.php41
-rw-r--r--src/Wallabag/CoreBundle/Event/Activity/Actions/Entry/EntryFavouriteEvent.php14
-rw-r--r--src/Wallabag/CoreBundle/Event/Activity/Actions/Entry/EntryReadEvent.php14
-rw-r--r--src/Wallabag/CoreBundle/Event/Activity/Actions/Entry/EntrySavedEvent.php11
-rw-r--r--src/Wallabag/CoreBundle/Event/Activity/Actions/Entry/EntryTaggedEvent.php55
-rw-r--r--src/Wallabag/CoreBundle/Event/Activity/Actions/Federation/FederationEvent.php40
-rw-r--r--src/Wallabag/CoreBundle/Event/Activity/Actions/Federation/FollowEvent.php39
-rw-r--r--src/Wallabag/CoreBundle/Event/Activity/Actions/Federation/RecommendedEntryEvent.php43
-rw-r--r--src/Wallabag/CoreBundle/Event/Activity/Actions/Federation/UnfollowEvent.php39
-rw-r--r--src/Wallabag/CoreBundle/Event/Activity/Actions/Share/ShareAcceptedEvent.php11
-rw-r--r--src/Wallabag/CoreBundle/Event/Activity/Actions/Share/ShareCancelledEvent.php11
-rw-r--r--src/Wallabag/CoreBundle/Event/Activity/Actions/Share/ShareCreatedEvent.php11
-rw-r--r--src/Wallabag/CoreBundle/Event/Activity/Actions/Share/ShareDeniedEvent.php11
-rw-r--r--src/Wallabag/CoreBundle/Event/Activity/Actions/Share/ShareEvent.php39
-rw-r--r--src/Wallabag/CoreBundle/Event/Activity/Actions/User/UserDeletedEvent.php8
-rw-r--r--src/Wallabag/CoreBundle/Event/Activity/Actions/User/UserEditedEvent.php8
-rw-r--r--src/Wallabag/CoreBundle/Event/Activity/Actions/User/UserEvent.php41
-rw-r--r--src/Wallabag/CoreBundle/Event/Activity/ActivitySubscriber.php224
24 files changed, 745 insertions, 0 deletions
diff --git a/src/Wallabag/CoreBundle/Event/Activity/Actions/Annotation/AnnotationCreatedEvent.php b/src/Wallabag/CoreBundle/Event/Activity/Actions/Annotation/AnnotationCreatedEvent.php
new file mode 100644
index 00000000..b3667703
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Event/Activity/Actions/Annotation/AnnotationCreatedEvent.php
@@ -0,0 +1,8 @@
1<?php
2
3namespace Wallabag\CoreBundle\Event\Activity\Actions\Annotation;
4
5class AnnotationCreatedEvent extends AnnotationEvent
6{
7 const NAME = 'annotation.created';
8}
diff --git a/src/Wallabag/CoreBundle/Event/Activity/Actions/Annotation/AnnotationDeletedEvent.php b/src/Wallabag/CoreBundle/Event/Activity/Actions/Annotation/AnnotationDeletedEvent.php
new file mode 100644
index 00000000..60d53849
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Event/Activity/Actions/Annotation/AnnotationDeletedEvent.php
@@ -0,0 +1,8 @@
1<?php
2
3namespace Wallabag\CoreBundle\Event\Activity\Actions\Annotation;
4
5class AnnotationDeletedEvent extends AnnotationEvent
6{
7 const NAME = 'annotation.deleted';
8}
diff --git a/src/Wallabag/CoreBundle/Event/Activity/Actions/Annotation/AnnotationEditedEvent.php b/src/Wallabag/CoreBundle/Event/Activity/Actions/Annotation/AnnotationEditedEvent.php
new file mode 100644
index 00000000..385b8025
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Event/Activity/Actions/Annotation/AnnotationEditedEvent.php
@@ -0,0 +1,8 @@
1<?php
2
3namespace Wallabag\CoreBundle\Event\Activity\Actions\Annotation;
4
5class AnnotationEditedEvent extends AnnotationEvent
6{
7 const NAME = 'annotation.edited';
8}
diff --git a/src/Wallabag/CoreBundle/Event/Activity/Actions/Annotation/AnnotationEvent.php b/src/Wallabag/CoreBundle/Event/Activity/Actions/Annotation/AnnotationEvent.php
new file mode 100644
index 00000000..b4cb93af
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Event/Activity/Actions/Annotation/AnnotationEvent.php
@@ -0,0 +1,39 @@
1<?php
2
3namespace Wallabag\CoreBundle\Event\Activity\Actions\Annotation;
4
5use Symfony\Component\EventDispatcher\Event;
6use Wallabag\AnnotationBundle\Entity\Annotation;
7
8/**
9 * This event is fired when annotation-relative stuff is made.
10 */
11abstract class AnnotationEvent extends Event
12{
13 protected $annotation;
14
15 /**
16 * AnnotationEvent constructor.
17 * @param Annotation $annotation
18 */
19 public function __construct(Annotation $annotation)
20 {
21 $this->annotation = $annotation;
22 }
23
24 /**
25 * @return Annotation
26 */
27 public function getAnnotation()
28 {
29 return $this->annotation;
30 }
31
32 /**
33 * @param Annotation $annotation
34 */
35 public function setAnnotation(Annotation $annotation)
36 {
37 $this->annotation = $annotation;
38 }
39}
diff --git a/src/Wallabag/CoreBundle/Event/Activity/Actions/Entry/EntryDeletedEvent.php b/src/Wallabag/CoreBundle/Event/Activity/Actions/Entry/EntryDeletedEvent.php
new file mode 100644
index 00000000..1d413d41
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Event/Activity/Actions/Entry/EntryDeletedEvent.php
@@ -0,0 +1,11 @@
1<?php
2
3namespace Wallabag\CoreBundle\Event\Activity\Actions\Entry;
4
5/**
6 * This event is fired as soon as an entry is deleted.
7 */
8class EntryDeletedEvent extends EntryEvent
9{
10 const NAME = 'entry.deleted';
11}
diff --git a/src/Wallabag/CoreBundle/Event/Activity/Actions/Entry/EntryEditedEvent.php b/src/Wallabag/CoreBundle/Event/Activity/Actions/Entry/EntryEditedEvent.php
new file mode 100644
index 00000000..f7528bb4
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Event/Activity/Actions/Entry/EntryEditedEvent.php
@@ -0,0 +1,11 @@
1<?php
2
3namespace Wallabag\CoreBundle\Event\Activity\Actions\Entry;
4
5/**
6 * This event is fired as soon as an entry was edited.
7 */
8class EntryEditedEvent extends EntryEvent
9{
10 const NAME = 'entry.edited';
11}
diff --git a/src/Wallabag/CoreBundle/Event/Activity/Actions/Entry/EntryEvent.php b/src/Wallabag/CoreBundle/Event/Activity/Actions/Entry/EntryEvent.php
new file mode 100644
index 00000000..0e0c90d0
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Event/Activity/Actions/Entry/EntryEvent.php
@@ -0,0 +1,41 @@
1<?php
2
3namespace Wallabag\CoreBundle\Event\Activity\Actions\Entry;
4
5use Symfony\Component\EventDispatcher\Event;
6use Wallabag\CoreBundle\Entity\Entry;
7
8/**
9 * This event is fired when entry-related stuff is made.
10 */
11abstract class EntryEvent extends Event
12{
13 protected $entry;
14
15 /**
16 * EntryEvent constructor.
17 * @param Entry $entry
18 */
19 public function __construct(Entry $entry)
20 {
21 $this->entry = $entry;
22 }
23
24 /**
25 * @return Entry
26 */
27 public function getEntry()
28 {
29 return $this->entry;
30 }
31
32 /**
33 * @param Entry $entry
34 * @return EntryEvent
35 */
36 public function setEntry(Entry $entry)
37 {
38 $this->entry = $entry;
39 return $this;
40 }
41}
diff --git a/src/Wallabag/CoreBundle/Event/Activity/Actions/Entry/EntryFavouriteEvent.php b/src/Wallabag/CoreBundle/Event/Activity/Actions/Entry/EntryFavouriteEvent.php
new file mode 100644
index 00000000..98edb00d
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Event/Activity/Actions/Entry/EntryFavouriteEvent.php
@@ -0,0 +1,14 @@
1<?php
2
3namespace Wallabag\CoreBundle\Event\Activity\Actions\Entry;
4
5use Symfony\Component\EventDispatcher\Event;
6use Wallabag\CoreBundle\Entity\Entry;
7
8/**
9 * This event is fired as soon as an entry was favourited.
10 */
11class EntryFavouriteEvent extends EntryEvent
12{
13 const NAME = 'entry.favourite';
14}
diff --git a/src/Wallabag/CoreBundle/Event/Activity/Actions/Entry/EntryReadEvent.php b/src/Wallabag/CoreBundle/Event/Activity/Actions/Entry/EntryReadEvent.php
new file mode 100644
index 00000000..be6e6b40
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Event/Activity/Actions/Entry/EntryReadEvent.php
@@ -0,0 +1,14 @@
1<?php
2
3namespace Wallabag\CoreBundle\Event\Activity\Actions\Entry;
4
5use Symfony\Component\EventDispatcher\Event;
6use Wallabag\CoreBundle\Entity\Entry;
7
8/**
9 * This event is fired as soon as an entry was favourited.
10 */
11class EntryReadEvent extends EntryEvent
12{
13 const NAME = 'entry.read';
14}
diff --git a/src/Wallabag/CoreBundle/Event/Activity/Actions/Entry/EntrySavedEvent.php b/src/Wallabag/CoreBundle/Event/Activity/Actions/Entry/EntrySavedEvent.php
new file mode 100644
index 00000000..20c623c5
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Event/Activity/Actions/Entry/EntrySavedEvent.php
@@ -0,0 +1,11 @@
1<?php
2
3namespace Wallabag\CoreBundle\Event\Activity\Actions\Entry;
4
5/**
6 * This event is fired as soon as an entry was saved.
7 */
8class EntrySavedEvent extends EntryEvent
9{
10 const NAME = 'entry.saved';
11}
diff --git a/src/Wallabag/CoreBundle/Event/Activity/Actions/Entry/EntryTaggedEvent.php b/src/Wallabag/CoreBundle/Event/Activity/Actions/Entry/EntryTaggedEvent.php
new file mode 100644
index 00000000..1ea8a7f1
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Event/Activity/Actions/Entry/EntryTaggedEvent.php
@@ -0,0 +1,55 @@
1<?php
2
3namespace Wallabag\CoreBundle\Event\Activity\Actions\Entry;
4
5use Wallabag\CoreBundle\Entity\Entry;
6use Wallabag\CoreBundle\Entity\Tag;
7
8/**
9 * This event is fired as soon as a tag is added on an entry.
10 */
11class EntryTaggedEvent extends EntryEvent
12{
13 const NAME = 'entry.tagged';
14
15 /** @var Tag[] */
16 protected $tags;
17
18 /**
19 * @var boolean
20 */
21 protected $remove;
22
23 /**
24 * EntryTaggedEvent constructor.
25 * @param Entry $entry
26 * @param $tags
27 * @param bool $remove
28 */
29 public function __construct(Entry $entry, $tags, $remove = false)
30 {
31 parent::__construct($entry);
32
33 if (false === is_array($tags)) {
34 $tags = [$tags];
35 }
36
37 $this->tags = $tags;
38 }
39
40 /**
41 * @return Tag[]
42 */
43 public function getTags()
44 {
45 return $this->tags;
46 }
47
48 /**
49 * @return bool
50 */
51 public function isRemove()
52 {
53 return $this->remove;
54 }
55}
diff --git a/src/Wallabag/CoreBundle/Event/Activity/Actions/Federation/FederationEvent.php b/src/Wallabag/CoreBundle/Event/Activity/Actions/Federation/FederationEvent.php
new file mode 100644
index 00000000..da18330e
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Event/Activity/Actions/Federation/FederationEvent.php
@@ -0,0 +1,40 @@
1<?php
2
3namespace Wallabag\CoreBundle\Event\Activity\Actions\Federation;
4
5use Symfony\Component\EventDispatcher\Event;
6use Wallabag\FederationBundle\Entity\Account;
7
8abstract class FederationEvent extends Event
9{
10 protected $account;
11
12 /**
13 * FederationEvent constructor.
14 * @param Account $account
15 */
16 public function __construct(Account $account)
17 {
18 $this->account = $account;
19 }
20
21 /**
22 * @return Account
23 */
24 public function getAccount()
25 {
26 return $this->account;
27 }
28
29 /**
30 * @param Account $account
31 * @return FederationEvent
32 */
33 public function setAccount(Account $account)
34 {
35 $this->account = $account;
36 return $this;
37 }
38
39
40}
diff --git a/src/Wallabag/CoreBundle/Event/Activity/Actions/Federation/FollowEvent.php b/src/Wallabag/CoreBundle/Event/Activity/Actions/Federation/FollowEvent.php
new file mode 100644
index 00000000..4004932e
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Event/Activity/Actions/Federation/FollowEvent.php
@@ -0,0 +1,39 @@
1<?php
2
3namespace Wallabag\CoreBundle\Event\Activity\Actions\Federation;
4
5use Wallabag\FederationBundle\Entity\Account;
6
7/**
8 * This event is fired as soon as an account was followed.
9 */
10class FollowEvent extends FederationEvent
11{
12 const NAME = 'federation.follow';
13
14 protected $follower;
15
16 public function __construct(Account $accountFollowed, Account $follower)
17 {
18 parent::__construct($accountFollowed);
19 $this->follower = $follower;
20 }
21
22 /**
23 * @return Account
24 */
25 public function getFollower()
26 {
27 return $this->follower;
28 }
29
30 /**
31 * @param Account $follower
32 * @return FollowEvent
33 */
34 public function setFollower(Account $follower)
35 {
36 $this->follower = $follower;
37 return $this;
38 }
39}
diff --git a/src/Wallabag/CoreBundle/Event/Activity/Actions/Federation/RecommendedEntryEvent.php b/src/Wallabag/CoreBundle/Event/Activity/Actions/Federation/RecommendedEntryEvent.php
new file mode 100644
index 00000000..998b56d5
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Event/Activity/Actions/Federation/RecommendedEntryEvent.php
@@ -0,0 +1,43 @@
1<?php
2
3namespace Wallabag\CoreBundle\Event\Activity\Actions\Federation;
4
5use Symfony\Component\EventDispatcher\Event;
6use Wallabag\CoreBundle\Entity\Entry;
7
8/**
9 * This event is fired as soon as an entry was recommended.
10 */
11class RecommendedEntryEvent extends Event
12{
13 const NAME = 'federation.recommend';
14
15 protected $entry;
16
17 /**
18 * FederationEvent constructor.
19 * @param Entry $entry
20 */
21 public function __construct(Entry $entry)
22 {
23 $this->entry = $entry;
24 }
25
26 /**
27 * @return Entry
28 */
29 public function getEntry()
30 {
31 return $this->entry;
32 }
33
34 /**
35 * @param Entry $entry
36 * @return RecommendedEntryEvent
37 */
38 public function setEntry(Entry $entry)
39 {
40 $this->entry = $entry;
41 return $this;
42 }
43}
diff --git a/src/Wallabag/CoreBundle/Event/Activity/Actions/Federation/UnfollowEvent.php b/src/Wallabag/CoreBundle/Event/Activity/Actions/Federation/UnfollowEvent.php
new file mode 100644
index 00000000..bf9a35f8
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Event/Activity/Actions/Federation/UnfollowEvent.php
@@ -0,0 +1,39 @@
1<?php
2
3namespace Wallabag\CoreBundle\Event\Activity\Actions\Federation;
4
5use Wallabag\FederationBundle\Entity\Account;
6
7/**
8 * This event is fired as soon as an account is being unfollowed
9 */
10class UnfollowEvent extends FederationEvent
11{
12 const NAME = 'federation.unfollow';
13
14 protected $follower;
15
16 public function __construct(Account $accountFollowed, Account $follower)
17 {
18 parent::__construct($accountFollowed);
19 $this->follower = $follower;
20 }
21
22 /**
23 * @return Account
24 */
25 public function getFollower()
26 {
27 return $this->follower;
28 }
29
30 /**
31 * @param Account $follower
32 * @return UnfollowEvent
33 */
34 public function setFollower(Account $follower)
35 {
36 $this->follower = $follower;
37 return $this;
38 }
39}
diff --git a/src/Wallabag/CoreBundle/Event/Activity/Actions/Share/ShareAcceptedEvent.php b/src/Wallabag/CoreBundle/Event/Activity/Actions/Share/ShareAcceptedEvent.php
new file mode 100644
index 00000000..e171ef04
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Event/Activity/Actions/Share/ShareAcceptedEvent.php
@@ -0,0 +1,11 @@
1<?php
2
3namespace Wallabag\CoreBundle\Event\Activity\Actions\Share;
4
5/**
6 * This event is fired as soon as an share is accepted
7 */
8class ShareAcceptedEvent extends ShareEvent
9{
10 const NAME = 'share.accepted';
11}
diff --git a/src/Wallabag/CoreBundle/Event/Activity/Actions/Share/ShareCancelledEvent.php b/src/Wallabag/CoreBundle/Event/Activity/Actions/Share/ShareCancelledEvent.php
new file mode 100644
index 00000000..26bee896
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Event/Activity/Actions/Share/ShareCancelledEvent.php
@@ -0,0 +1,11 @@
1<?php
2
3namespace Wallabag\CoreBundle\Event\Activity\Actions\Share;
4
5/**
6 * This event is fired as soon as an share is cancelled
7 */
8class ShareCancelledEvent extends ShareEvent
9{
10 const NAME = 'share.cancelled';
11}
diff --git a/src/Wallabag/CoreBundle/Event/Activity/Actions/Share/ShareCreatedEvent.php b/src/Wallabag/CoreBundle/Event/Activity/Actions/Share/ShareCreatedEvent.php
new file mode 100644
index 00000000..c2cb72d8
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Event/Activity/Actions/Share/ShareCreatedEvent.php
@@ -0,0 +1,11 @@
1<?php
2
3namespace Wallabag\CoreBundle\Event\Activity\Actions\Share;
4
5/**
6 * This event is fired as soon as a share is created.
7 */
8class ShareCreatedEvent extends ShareEvent
9{
10 const NAME = 'share.created';
11}
diff --git a/src/Wallabag/CoreBundle/Event/Activity/Actions/Share/ShareDeniedEvent.php b/src/Wallabag/CoreBundle/Event/Activity/Actions/Share/ShareDeniedEvent.php
new file mode 100644
index 00000000..fcdfd1ce
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Event/Activity/Actions/Share/ShareDeniedEvent.php
@@ -0,0 +1,11 @@
1<?php
2
3namespace Wallabag\CoreBundle\Event\Activity\Actions\Share;
4
5/**
6 * This event is fired as soon as an share is denied
7 */
8class ShareDeniedEvent extends ShareEvent
9{
10 const NAME = 'share.denied';
11}
diff --git a/src/Wallabag/CoreBundle/Event/Activity/Actions/Share/ShareEvent.php b/src/Wallabag/CoreBundle/Event/Activity/Actions/Share/ShareEvent.php
new file mode 100644
index 00000000..0022a39f
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Event/Activity/Actions/Share/ShareEvent.php
@@ -0,0 +1,39 @@
1<?php
2
3namespace Wallabag\CoreBundle\Event\Activity\Actions\Share;
4
5use Symfony\Component\EventDispatcher\Event;
6use Wallabag\CoreBundle\Entity\Share;
7
8/**
9 * This event is fired when share-related stuff is made.
10 */
11abstract class ShareEvent extends Event
12{
13 protected $share;
14
15 /**
16 * ShareEvent constructor.
17 * @param Share $share
18 */
19 public function __construct(Share $share)
20 {
21 $this->share = $share;
22 }
23
24 /**
25 * @return Share
26 */
27 public function getShare()
28 {
29 return $this->share;
30 }
31
32 /**
33 * @param Share $share
34 */
35 public function setShare(Share $share)
36 {
37 $this->share = $share;
38 }
39}
diff --git a/src/Wallabag/CoreBundle/Event/Activity/Actions/User/UserDeletedEvent.php b/src/Wallabag/CoreBundle/Event/Activity/Actions/User/UserDeletedEvent.php
new file mode 100644
index 00000000..df06db8c
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Event/Activity/Actions/User/UserDeletedEvent.php
@@ -0,0 +1,8 @@
1<?php
2
3namespace Wallabag\CoreBundle\Event\Activity\Actions\User;
4
5class UserDeletedEvent extends UserEvent
6{
7 const NAME = 'user.deleted';
8}
diff --git a/src/Wallabag/CoreBundle/Event/Activity/Actions/User/UserEditedEvent.php b/src/Wallabag/CoreBundle/Event/Activity/Actions/User/UserEditedEvent.php
new file mode 100644
index 00000000..27f8f2d5
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Event/Activity/Actions/User/UserEditedEvent.php
@@ -0,0 +1,8 @@
1<?php
2
3namespace Wallabag\CoreBundle\Event\Activity\Actions\User;
4
5class UserEditedEvent extends UserEvent
6{
7 const NAME = 'user.edited';
8}
diff --git a/src/Wallabag/CoreBundle/Event/Activity/Actions/User/UserEvent.php b/src/Wallabag/CoreBundle/Event/Activity/Actions/User/UserEvent.php
new file mode 100644
index 00000000..e3807abf
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Event/Activity/Actions/User/UserEvent.php
@@ -0,0 +1,41 @@
1<?php
2
3namespace Wallabag\CoreBundle\Event\Activity\Actions\User;
4
5use Symfony\Component\EventDispatcher\Event;
6use Wallabag\UserBundle\Entity\User;
7
8/**
9 * This event is fired when user-related stuff is made.
10 */
11abstract class UserEvent extends Event
12{
13 protected $user;
14
15 /**
16 * UserEvent constructor.
17 * @param User $user
18 */
19 public function __construct(User $user)
20 {
21 $this->user = $user;
22 }
23
24 /**
25 * @return User
26 */
27 public function getUser()
28 {
29 return $this->user;
30 }
31
32 /**
33 * @param User $user
34 * @return UserEvent
35 */
36 public function setUser(User $user)
37 {
38 $this->user = $user;
39 return $this;
40 }
41}
diff --git a/src/Wallabag/CoreBundle/Event/Activity/ActivitySubscriber.php b/src/Wallabag/CoreBundle/Event/Activity/ActivitySubscriber.php
new file mode 100644
index 00000000..81379ff2
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Event/Activity/ActivitySubscriber.php
@@ -0,0 +1,224 @@
1<?php
2
3namespace Wallabag\CoreBundle\Event\Activity;
4
5use Doctrine\ORM\EntityManager;
6use FOS\UserBundle\Event\UserEvent;
7use FOS\UserBundle\FOSUserEvents;
8use Psr\Log\LoggerInterface;
9use Symfony\Component\EventDispatcher\Event;
10use Symfony\Component\EventDispatcher\EventSubscriberInterface;
11use Wallabag\CoreBundle\Entity\Activity;
12use Wallabag\CoreBundle\Event\Activity\Actions\Annotation\AnnotationCreatedEvent;
13use Wallabag\CoreBundle\Event\Activity\Actions\Annotation\AnnotationDeletedEvent;
14use Wallabag\CoreBundle\Event\Activity\Actions\Annotation\AnnotationEditedEvent;
15use Wallabag\CoreBundle\Event\Activity\Actions\Annotation\AnnotationEvent;
16use Wallabag\CoreBundle\Event\Activity\Actions\Entry\EntryDeletedEvent;
17use Wallabag\CoreBundle\Event\Activity\Actions\Entry\EntryEditedEvent;
18use Wallabag\CoreBundle\Event\Activity\Actions\Entry\EntryEvent;
19use Wallabag\CoreBundle\Event\Activity\Actions\Entry\EntryFavouriteEvent;
20use Wallabag\CoreBundle\Event\Activity\Actions\Entry\EntryReadEvent;
21use Wallabag\CoreBundle\Event\Activity\Actions\Entry\EntrySavedEvent;
22use Wallabag\CoreBundle\Event\Activity\Actions\Entry\EntryTaggedEvent;
23use Wallabag\CoreBundle\Event\Activity\Actions\Federation\FollowEvent;
24use Wallabag\CoreBundle\Event\Activity\Actions\Federation\RecommendedEntryEvent;
25use Wallabag\CoreBundle\Event\Activity\Actions\Federation\UnfollowEvent;
26use Wallabag\CoreBundle\Event\Activity\Actions\Share\ShareAcceptedEvent;
27use Wallabag\CoreBundle\Event\Activity\Actions\Share\ShareCancelledEvent;
28use Wallabag\CoreBundle\Event\Activity\Actions\Share\ShareCreatedEvent;
29use Wallabag\CoreBundle\Event\Activity\Actions\Share\ShareDeniedEvent;
30use Wallabag\CoreBundle\Event\Activity\Actions\Share\ShareEvent;
31use Wallabag\CoreBundle\Event\Activity\Actions\User\UserDeletedEvent;
32use Wallabag\CoreBundle\Event\Activity\Actions\User\UserEditedEvent;
33use Wallabag\CoreBundle\Notifications\ActionInterface;
34
35/**
36 * This listener will create the associated configuration when a user register.
37 * This configuration will be created right after the registration (no matter if it needs an email validation).
38 */
39class ActivitySubscriber implements EventSubscriberInterface
40{
41
42 /**
43 * @var EntityManager
44 */
45 private $em;
46
47 /**
48 * @var LoggerInterface $logger
49 */
50 private $logger;
51
52 public function __construct(EntityManager $em, LoggerInterface $logger)
53 {
54 $this->em = $em;
55 $this->logger = $logger;
56 }
57
58 public static function getSubscribedEvents()
59 {
60 return [
61 EntrySavedEvent::NAME => 'entryActivity',
62 EntryDeletedEvent::NAME => 'entryActivity',
63 EntryEditedEvent::NAME => 'entryActivity',
64 EntryTaggedEvent::NAME => 'taggedEntry',
65 EntryFavouriteEvent::NAME => 'entryActivity',
66 EntryReadEvent::NAME => 'entryActivity',
67
68 AnnotationCreatedEvent::NAME => 'annotationActivity',
69 AnnotationEditedEvent::NAME => 'annotationActivity',
70 AnnotationDeletedEvent::NAME => 'annotationActivity',
71
72 FollowEvent::NAME => 'followedAccount',
73 UnfollowEvent::NAME => 'unfollowedAccount',
74 RecommendedEntryEvent::NAME => 'recommendedEntry',
75
76 ShareCreatedEvent::NAME => 'shareActivity',
77 ShareAcceptedEvent::NAME => 'shareActivity',
78 ShareDeniedEvent::NAME => 'shareActivity',
79 ShareCancelledEvent::NAME => 'shareActivity',
80
81 // when a user register using the normal form
82 FOSUserEvents::REGISTRATION_COMPLETED => 'userActivity',
83 // when we manually create a user using the command line
84 // OR when we create it from the config UI
85 FOSUserEvents::USER_CREATED => 'userActivity',
86 UserEditedEvent::NAME => 'userActivity',
87 UserDeletedEvent::NAME => 'userActivity',
88 ];
89 }
90
91 public function userActivity(Event $event)
92 {
93 $activityType = 0;
94 if ($event instanceof UserEvent) {
95 $activityType = Activity::USER_CREATE;
96 } elseif ($event instanceof UserEditedEvent) {
97 $activityType = Activity::USER_EDIT;
98 } elseif ($event instanceof UserDeletedEvent) {
99 $activityType = Activity::USER_REMOVE;
100 }
101
102 $user = $event->getUser();
103 $activity = new Activity($activityType, Activity::USER_OBJECT, $user->getId());
104 $activity->setUser($user->getAccount());
105 $this->em->persist($activity);
106 $this->em->flush();
107 }
108
109 public function entryActivity(EntryEvent $event)
110 {
111 $entry = $event->getEntry();
112
113 $activityType = 0;
114 if ($event instanceof EntrySavedEvent) {
115 $activityType = Activity::ENTRY_ADD;
116 } elseif ($event instanceof EntryDeletedEvent) {
117 $activityType = Activity::ENTRY_DELETE;
118 } elseif ($event instanceof EntryEditedEvent) {
119 $activityType = Activity::ENTRY_EDIT;
120 } elseif ($event instanceof EntryFavouriteEvent) {
121 if ($entry->isStarred()) {
122 $activityType = Activity::ENTRY_FAVOURITE;
123 } else {
124 $activityType = Activity::ENTRY_UNFAVOURITE;
125 }
126 } elseif ($event instanceof EntryReadEvent) {
127 if ($entry->isArchived()) {
128 $activityType = Activity::ENTRY_READ;
129 } else {
130 $activityType = Activity::ENTRY_UNREAD;
131 }
132 }
133
134 $activity = new Activity($activityType, Activity::ENTRY_OBJECT, $entry->getId());
135 $activity->setUser($entry->getUser()->getAccount());
136 $this->em->persist($activity);
137 $this->em->flush();
138 }
139
140 public function taggedEntry(EntryTaggedEvent $event)
141 {
142 $entry = $event->getEntry();
143 $activity = new Activity($event->isRemove() ? Activity::ENTRY_REMOVE_TAG : Activity::ENTRY_ADD_TAG, Activity::ENTRY_OBJECT, $entry->getId());
144 $activity->setUser($entry->getUser()->getAccount());
145 $activity->setSecondaryObjectType(Activity::TAG_OBJECT)
146 ->setSecondaryObjectId($event->getTags()[0]->getId());
147 $this->em->persist($activity);
148 $this->em->flush();
149 }
150
151 public function annotationActivity(AnnotationEvent $event)
152 {
153 $annotation = $event->getAnnotation();
154
155 $activityType = 0;
156 if ($event instanceof AnnotationCreatedEvent) {
157 $activityType = Activity::ANNOTATION_ADD;
158 } elseif ($event instanceof AnnotationEditedEvent) {
159 $activityType = Activity::ANNOTATION_EDIT;
160 } elseif ($event instanceof AnnotationDeletedEvent) {
161 $activityType = Activity::ANNOTATION_REMOVE;
162 }
163
164 $activity = new Activity($activityType, Activity::ANNOTATION_OBJECT, $annotation->getId());
165 $activity->setUser($annotation->getUser()->getAccount());
166 $this->em->persist($activity);
167 $this->em->flush();
168 }
169
170 public function followedAccount(FollowEvent $event)
171 {
172 $activity = new Activity(Activity::FOLLOW_ACCOUNT, Activity::ACCOUNT_OBJECT, $event->getAccount()->getId());
173 $activity->setUser($event->getAccount());
174 $activity->setSecondaryObjectType(Activity::ACCOUNT_OBJECT)
175 ->setSecondaryObjectId($event->getFollower()->getId());
176 $this->em->persist($activity);
177 $this->em->flush();
178 }
179
180 public function unfollowedAccount(UnfollowEvent $event)
181 {
182 $activity = new Activity(Activity::UNFOLLOW_ACCOUNT, Activity::ACCOUNT_OBJECT, $event->getAccount()->getId());
183 $activity->setUser($event->getAccount());
184 $activity->setSecondaryObjectType(Activity::ACCOUNT_OBJECT)
185 ->setSecondaryObjectId($event->getFollower()->getId());
186 $this->em->persist($activity);
187 $this->em->flush();
188 }
189
190 public function recommendedEntry(RecommendedEntryEvent $event)
191 {
192 $entry = $event->getEntry();
193 $account = $entry->getUser()->getAccount();
194 $activity = new Activity(Activity::RECOMMEND_ENTRY, Activity::ACCOUNT_OBJECT, $account->getId());
195 $activity->setUser($account);
196 $activity->setSecondaryObjectType(Activity::ENTRY_OBJECT)
197 ->setSecondaryObjectId($entry->getId());
198 $this->em->persist($activity);
199 $this->em->flush();
200 }
201
202 public function shareActivity(ShareEvent $event)
203 {
204 $share = $event->getShare();
205
206 $activityType = 0;
207 if ($event instanceof ShareCreatedEvent) {
208 $activityType = Activity::USER_SHARE_CREATED;
209 } elseif ($event instanceof ShareAcceptedEvent) {
210 $activityType = Activity::USER_SHARE_ACCEPTED;
211 } elseif ($event instanceof ShareDeniedEvent) {
212 $activityType = Activity::USER_SHARE_REFUSED;
213 } elseif ($event instanceof ShareCancelledEvent) {
214 $activityType = Activity::USER_SHARE_CANCELLED;
215 }
216
217 $activity = new Activity($activityType, Activity::SHARE_OBJECT, $share->getId());
218 $activity->setUser($share->getUserOrigin());
219 $activity->setSecondaryObjectType(Activity::ACCOUNT_OBJECT)
220 ->setSecondaryObjectId($share->getUserDestination()->getId());
221 $this->em->persist($activity);
222 $this->em->flush();
223 }
224}