From bf6c0346d8d35a719dd1bff1cb4d573d422f99ff Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 31 May 2017 09:31:18 +0200 Subject: WIP Signed-off-by: Thomas Citharel --- .../Actions/Annotation/AnnotationCreatedEvent.php | 8 + .../Actions/Annotation/AnnotationDeletedEvent.php | 8 + .../Actions/Annotation/AnnotationEditedEvent.php | 8 + .../Actions/Annotation/AnnotationEvent.php | 39 ++++ .../Activity/Actions/Entry/EntryDeletedEvent.php | 11 + .../Activity/Actions/Entry/EntryEditedEvent.php | 11 + .../Event/Activity/Actions/Entry/EntryEvent.php | 41 ++++ .../Activity/Actions/Entry/EntryFavouriteEvent.php | 14 ++ .../Activity/Actions/Entry/EntryReadEvent.php | 14 ++ .../Activity/Actions/Entry/EntrySavedEvent.php | 11 + .../Activity/Actions/Entry/EntryTaggedEvent.php | 55 +++++ .../Actions/Federation/FederationEvent.php | 40 ++++ .../Activity/Actions/Federation/FollowEvent.php | 39 ++++ .../Actions/Federation/RecommendedEntryEvent.php | 43 ++++ .../Activity/Actions/Federation/UnfollowEvent.php | 39 ++++ .../Activity/Actions/Share/ShareAcceptedEvent.php | 11 + .../Activity/Actions/Share/ShareCancelledEvent.php | 11 + .../Activity/Actions/Share/ShareCreatedEvent.php | 11 + .../Activity/Actions/Share/ShareDeniedEvent.php | 11 + .../Event/Activity/Actions/Share/ShareEvent.php | 39 ++++ .../Activity/Actions/User/UserDeletedEvent.php | 8 + .../Activity/Actions/User/UserEditedEvent.php | 8 + .../Event/Activity/Actions/User/UserEvent.php | 41 ++++ .../Event/Activity/ActivitySubscriber.php | 224 +++++++++++++++++++++ 24 files changed, 745 insertions(+) create mode 100644 src/Wallabag/CoreBundle/Event/Activity/Actions/Annotation/AnnotationCreatedEvent.php create mode 100644 src/Wallabag/CoreBundle/Event/Activity/Actions/Annotation/AnnotationDeletedEvent.php create mode 100644 src/Wallabag/CoreBundle/Event/Activity/Actions/Annotation/AnnotationEditedEvent.php create mode 100644 src/Wallabag/CoreBundle/Event/Activity/Actions/Annotation/AnnotationEvent.php create mode 100644 src/Wallabag/CoreBundle/Event/Activity/Actions/Entry/EntryDeletedEvent.php create mode 100644 src/Wallabag/CoreBundle/Event/Activity/Actions/Entry/EntryEditedEvent.php create mode 100644 src/Wallabag/CoreBundle/Event/Activity/Actions/Entry/EntryEvent.php create mode 100644 src/Wallabag/CoreBundle/Event/Activity/Actions/Entry/EntryFavouriteEvent.php create mode 100644 src/Wallabag/CoreBundle/Event/Activity/Actions/Entry/EntryReadEvent.php create mode 100644 src/Wallabag/CoreBundle/Event/Activity/Actions/Entry/EntrySavedEvent.php create mode 100644 src/Wallabag/CoreBundle/Event/Activity/Actions/Entry/EntryTaggedEvent.php create mode 100644 src/Wallabag/CoreBundle/Event/Activity/Actions/Federation/FederationEvent.php create mode 100644 src/Wallabag/CoreBundle/Event/Activity/Actions/Federation/FollowEvent.php create mode 100644 src/Wallabag/CoreBundle/Event/Activity/Actions/Federation/RecommendedEntryEvent.php create mode 100644 src/Wallabag/CoreBundle/Event/Activity/Actions/Federation/UnfollowEvent.php create mode 100644 src/Wallabag/CoreBundle/Event/Activity/Actions/Share/ShareAcceptedEvent.php create mode 100644 src/Wallabag/CoreBundle/Event/Activity/Actions/Share/ShareCancelledEvent.php create mode 100644 src/Wallabag/CoreBundle/Event/Activity/Actions/Share/ShareCreatedEvent.php create mode 100644 src/Wallabag/CoreBundle/Event/Activity/Actions/Share/ShareDeniedEvent.php create mode 100644 src/Wallabag/CoreBundle/Event/Activity/Actions/Share/ShareEvent.php create mode 100644 src/Wallabag/CoreBundle/Event/Activity/Actions/User/UserDeletedEvent.php create mode 100644 src/Wallabag/CoreBundle/Event/Activity/Actions/User/UserEditedEvent.php create mode 100644 src/Wallabag/CoreBundle/Event/Activity/Actions/User/UserEvent.php create mode 100644 src/Wallabag/CoreBundle/Event/Activity/ActivitySubscriber.php (limited to 'src/Wallabag/CoreBundle/Event/Activity') 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 @@ +annotation = $annotation; + } + + /** + * @return Annotation + */ + public function getAnnotation() + { + return $this->annotation; + } + + /** + * @param Annotation $annotation + */ + public function setAnnotation(Annotation $annotation) + { + $this->annotation = $annotation; + } +} 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 @@ +entry = $entry; + } + + /** + * @return Entry + */ + public function getEntry() + { + return $this->entry; + } + + /** + * @param Entry $entry + * @return EntryEvent + */ + public function setEntry(Entry $entry) + { + $this->entry = $entry; + return $this; + } +} 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 @@ +tags = $tags; + } + + /** + * @return Tag[] + */ + public function getTags() + { + return $this->tags; + } + + /** + * @return bool + */ + public function isRemove() + { + return $this->remove; + } +} 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 @@ +account = $account; + } + + /** + * @return Account + */ + public function getAccount() + { + return $this->account; + } + + /** + * @param Account $account + * @return FederationEvent + */ + public function setAccount(Account $account) + { + $this->account = $account; + return $this; + } + + +} 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 @@ +follower = $follower; + } + + /** + * @return Account + */ + public function getFollower() + { + return $this->follower; + } + + /** + * @param Account $follower + * @return FollowEvent + */ + public function setFollower(Account $follower) + { + $this->follower = $follower; + return $this; + } +} 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 @@ +entry = $entry; + } + + /** + * @return Entry + */ + public function getEntry() + { + return $this->entry; + } + + /** + * @param Entry $entry + * @return RecommendedEntryEvent + */ + public function setEntry(Entry $entry) + { + $this->entry = $entry; + return $this; + } +} 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 @@ +follower = $follower; + } + + /** + * @return Account + */ + public function getFollower() + { + return $this->follower; + } + + /** + * @param Account $follower + * @return UnfollowEvent + */ + public function setFollower(Account $follower) + { + $this->follower = $follower; + return $this; + } +} 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 @@ +share = $share; + } + + /** + * @return Share + */ + public function getShare() + { + return $this->share; + } + + /** + * @param Share $share + */ + public function setShare(Share $share) + { + $this->share = $share; + } +} 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 @@ +user = $user; + } + + /** + * @return User + */ + public function getUser() + { + return $this->user; + } + + /** + * @param User $user + * @return UserEvent + */ + public function setUser(User $user) + { + $this->user = $user; + return $this; + } +} 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 @@ +em = $em; + $this->logger = $logger; + } + + public static function getSubscribedEvents() + { + return [ + EntrySavedEvent::NAME => 'entryActivity', + EntryDeletedEvent::NAME => 'entryActivity', + EntryEditedEvent::NAME => 'entryActivity', + EntryTaggedEvent::NAME => 'taggedEntry', + EntryFavouriteEvent::NAME => 'entryActivity', + EntryReadEvent::NAME => 'entryActivity', + + AnnotationCreatedEvent::NAME => 'annotationActivity', + AnnotationEditedEvent::NAME => 'annotationActivity', + AnnotationDeletedEvent::NAME => 'annotationActivity', + + FollowEvent::NAME => 'followedAccount', + UnfollowEvent::NAME => 'unfollowedAccount', + RecommendedEntryEvent::NAME => 'recommendedEntry', + + ShareCreatedEvent::NAME => 'shareActivity', + ShareAcceptedEvent::NAME => 'shareActivity', + ShareDeniedEvent::NAME => 'shareActivity', + ShareCancelledEvent::NAME => 'shareActivity', + + // when a user register using the normal form + FOSUserEvents::REGISTRATION_COMPLETED => 'userActivity', + // when we manually create a user using the command line + // OR when we create it from the config UI + FOSUserEvents::USER_CREATED => 'userActivity', + UserEditedEvent::NAME => 'userActivity', + UserDeletedEvent::NAME => 'userActivity', + ]; + } + + public function userActivity(Event $event) + { + $activityType = 0; + if ($event instanceof UserEvent) { + $activityType = Activity::USER_CREATE; + } elseif ($event instanceof UserEditedEvent) { + $activityType = Activity::USER_EDIT; + } elseif ($event instanceof UserDeletedEvent) { + $activityType = Activity::USER_REMOVE; + } + + $user = $event->getUser(); + $activity = new Activity($activityType, Activity::USER_OBJECT, $user->getId()); + $activity->setUser($user->getAccount()); + $this->em->persist($activity); + $this->em->flush(); + } + + public function entryActivity(EntryEvent $event) + { + $entry = $event->getEntry(); + + $activityType = 0; + if ($event instanceof EntrySavedEvent) { + $activityType = Activity::ENTRY_ADD; + } elseif ($event instanceof EntryDeletedEvent) { + $activityType = Activity::ENTRY_DELETE; + } elseif ($event instanceof EntryEditedEvent) { + $activityType = Activity::ENTRY_EDIT; + } elseif ($event instanceof EntryFavouriteEvent) { + if ($entry->isStarred()) { + $activityType = Activity::ENTRY_FAVOURITE; + } else { + $activityType = Activity::ENTRY_UNFAVOURITE; + } + } elseif ($event instanceof EntryReadEvent) { + if ($entry->isArchived()) { + $activityType = Activity::ENTRY_READ; + } else { + $activityType = Activity::ENTRY_UNREAD; + } + } + + $activity = new Activity($activityType, Activity::ENTRY_OBJECT, $entry->getId()); + $activity->setUser($entry->getUser()->getAccount()); + $this->em->persist($activity); + $this->em->flush(); + } + + public function taggedEntry(EntryTaggedEvent $event) + { + $entry = $event->getEntry(); + $activity = new Activity($event->isRemove() ? Activity::ENTRY_REMOVE_TAG : Activity::ENTRY_ADD_TAG, Activity::ENTRY_OBJECT, $entry->getId()); + $activity->setUser($entry->getUser()->getAccount()); + $activity->setSecondaryObjectType(Activity::TAG_OBJECT) + ->setSecondaryObjectId($event->getTags()[0]->getId()); + $this->em->persist($activity); + $this->em->flush(); + } + + public function annotationActivity(AnnotationEvent $event) + { + $annotation = $event->getAnnotation(); + + $activityType = 0; + if ($event instanceof AnnotationCreatedEvent) { + $activityType = Activity::ANNOTATION_ADD; + } elseif ($event instanceof AnnotationEditedEvent) { + $activityType = Activity::ANNOTATION_EDIT; + } elseif ($event instanceof AnnotationDeletedEvent) { + $activityType = Activity::ANNOTATION_REMOVE; + } + + $activity = new Activity($activityType, Activity::ANNOTATION_OBJECT, $annotation->getId()); + $activity->setUser($annotation->getUser()->getAccount()); + $this->em->persist($activity); + $this->em->flush(); + } + + public function followedAccount(FollowEvent $event) + { + $activity = new Activity(Activity::FOLLOW_ACCOUNT, Activity::ACCOUNT_OBJECT, $event->getAccount()->getId()); + $activity->setUser($event->getAccount()); + $activity->setSecondaryObjectType(Activity::ACCOUNT_OBJECT) + ->setSecondaryObjectId($event->getFollower()->getId()); + $this->em->persist($activity); + $this->em->flush(); + } + + public function unfollowedAccount(UnfollowEvent $event) + { + $activity = new Activity(Activity::UNFOLLOW_ACCOUNT, Activity::ACCOUNT_OBJECT, $event->getAccount()->getId()); + $activity->setUser($event->getAccount()); + $activity->setSecondaryObjectType(Activity::ACCOUNT_OBJECT) + ->setSecondaryObjectId($event->getFollower()->getId()); + $this->em->persist($activity); + $this->em->flush(); + } + + public function recommendedEntry(RecommendedEntryEvent $event) + { + $entry = $event->getEntry(); + $account = $entry->getUser()->getAccount(); + $activity = new Activity(Activity::RECOMMEND_ENTRY, Activity::ACCOUNT_OBJECT, $account->getId()); + $activity->setUser($account); + $activity->setSecondaryObjectType(Activity::ENTRY_OBJECT) + ->setSecondaryObjectId($entry->getId()); + $this->em->persist($activity); + $this->em->flush(); + } + + public function shareActivity(ShareEvent $event) + { + $share = $event->getShare(); + + $activityType = 0; + if ($event instanceof ShareCreatedEvent) { + $activityType = Activity::USER_SHARE_CREATED; + } elseif ($event instanceof ShareAcceptedEvent) { + $activityType = Activity::USER_SHARE_ACCEPTED; + } elseif ($event instanceof ShareDeniedEvent) { + $activityType = Activity::USER_SHARE_REFUSED; + } elseif ($event instanceof ShareCancelledEvent) { + $activityType = Activity::USER_SHARE_CANCELLED; + } + + $activity = new Activity($activityType, Activity::SHARE_OBJECT, $share->getId()); + $activity->setUser($share->getUserOrigin()); + $activity->setSecondaryObjectType(Activity::ACCOUNT_OBJECT) + ->setSecondaryObjectId($share->getUserDestination()->getId()); + $this->em->persist($activity); + $this->em->flush(); + } +} -- cgit v1.2.3