From f3a4c9ee675ffb7b4363bef02fd7e27942425d97 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Sat, 25 Oct 2014 14:16:01 +0200 Subject: [PATCH] Added post note retrieval in backend --- src/Controllers/PostController.php | 1 + .../ViewProxies/PostNoteViewProxy.php | 21 +++++++++++++++++++ src/Controllers/ViewProxies/PostViewProxy.php | 14 +++++++++++-- src/Dao/PostNoteDao.php | 5 +++++ src/Services/PostNotesService.php | 19 +++++++++++++++++ 5 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 src/Controllers/ViewProxies/PostNoteViewProxy.php create mode 100644 src/Services/PostNotesService.php diff --git a/src/Controllers/PostController.php b/src/Controllers/PostController.php index 7275b3c8..ef9cf41e 100644 --- a/src/Controllers/PostController.php +++ b/src/Controllers/PostController.php @@ -158,6 +158,7 @@ final class PostController extends AbstractController PostViewProxy::FETCH_HISTORY => true, PostViewProxy::FETCH_OWN_SCORE => true, PostViewProxy::FETCH_FAVORITES => true, + PostViewProxy::FETCH_NOTES => true, ]; } diff --git a/src/Controllers/ViewProxies/PostNoteViewProxy.php b/src/Controllers/ViewProxies/PostNoteViewProxy.php new file mode 100644 index 00000000..5c5e7398 --- /dev/null +++ b/src/Controllers/ViewProxies/PostNoteViewProxy.php @@ -0,0 +1,21 @@ +id = $postNote->getId(); + $result->postId = $postNote->getPostId(); + $result->text = $postNote->getText(); + $result->left = $postNote->getLeft(); + $result->top = $postNote->getTop(); + $result->width = $postNote->getWidth(); + $result->height = $postNote->getHeight(); + } + return $result; + } +} diff --git a/src/Controllers/ViewProxies/PostViewProxy.php b/src/Controllers/ViewProxies/PostViewProxy.php index 595c83e9..d674b3e2 100644 --- a/src/Controllers/ViewProxies/PostViewProxy.php +++ b/src/Controllers/ViewProxies/PostViewProxy.php @@ -1,14 +1,15 @@ privilegeService = $privilegeService; $this->authService = $authService; $this->historyService = $historyService; $this->favoritesService = $favoritesService; $this->scoreService = $scoreService; + $this->postNotesService = $postNotesService; $this->tagViewProxy = $tagViewProxy; $this->userViewProxy = $userViewProxy; $this->snapshotViewProxy = $snapshotViewProxy; + $this->postNoteViewProxy = $postNoteViewProxy; } public function fromEntity($post, $config = []) @@ -105,6 +113,8 @@ class PostViewProxy extends AbstractViewProxy if (!empty($config[self::FETCH_FAVORITES])) $result->favorites = $this->userViewProxy->fromArray($this->favoritesService->getFavoriteUsers($post)); + if (!empty($config[self::FETCH_NOTES])) + $result->notes = $this->postNoteViewProxy->fromArray($this->postNotesService->getPostNotes($post)); return $result; } diff --git a/src/Dao/PostNoteDao.php b/src/Dao/PostNoteDao.php index 472a8c07..eb199c9c 100644 --- a/src/Dao/PostNoteDao.php +++ b/src/Dao/PostNoteDao.php @@ -12,4 +12,9 @@ class PostNoteDao extends AbstractDao implements ICrudDao 'postNotes', new PostNoteEntityConverter()); } + + public function findByPostId($postId) + { + return $this->findBy('postId', $postId); + } } diff --git a/src/Services/PostNotesService.php b/src/Services/PostNotesService.php new file mode 100644 index 00000000..3ceaacff --- /dev/null +++ b/src/Services/PostNotesService.php @@ -0,0 +1,19 @@ +postNoteDao = $postNoteDao; + } + + public function getPostNotes(Post $post) + { + return $this->postNoteDao->findByPostId($post->getId()); + } +}