Added post note retrieval in backend

This commit is contained in:
Marcin Kurczewski 2014-10-25 14:16:01 +02:00
parent e03ed35862
commit f3a4c9ee67
5 changed files with 58 additions and 2 deletions

View file

@ -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,
];
}

View file

@ -0,0 +1,21 @@
<?php
namespace Szurubooru\Controllers\ViewProxies;
class PostNoteViewProxy extends AbstractViewProxy
{
public function fromEntity($postNote, $config = [])
{
$result = new \StdClass;
if ($postNote)
{
$result->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;
}
}

View file

@ -1,14 +1,15 @@
<?php
namespace Szurubooru\Controllers\ViewProxies;
use Szurubooru\Entities\Post;
use Szurubooru\Helpers\EnumHelper;
use Szurubooru\Helpers\MimeHelper;
use Szurubooru\Privilege;
use Szurubooru\Services\AuthService;
use Szurubooru\Services\FavoritesService;
use Szurubooru\Services\HistoryService;
use Szurubooru\Services\PostNotesService;
use Szurubooru\Services\PrivilegeService;
use Szurubooru\Services\ScoreService;
use Szurubooru\Entities\Post;
class PostViewProxy extends AbstractViewProxy
{
@ -18,15 +19,18 @@ class PostViewProxy extends AbstractViewProxy
const FETCH_HISTORY = 'fetchHistory';
const FETCH_OWN_SCORE = 'fetchOwnScore';
const FETCH_FAVORITES = 'fetchFavorites';
const FETCH_NOTES = 'fetchNotes';
private $privilegeService;
private $authService;
private $historyService;
private $favoritesService;
private $scoreService;
private $postNotesService;
private $tagViewProxy;
private $userViewProxy;
private $snapshotViewProxy;
private $postNoteViewProxy;
public function __construct(
PrivilegeService $privilegeService,
@ -34,18 +38,22 @@ class PostViewProxy extends AbstractViewProxy
HistoryService $historyService,
FavoritesService $favoritesService,
ScoreService $scoreService,
PostNotesService $postNotesService,
TagViewProxy $tagViewProxy,
UserViewProxy $userViewProxy,
SnapshotViewProxy $snapshotViewProxy)
SnapshotViewProxy $snapshotViewProxy,
PostNoteViewProxy $postNoteViewProxy)
{
$this->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;
}

View file

@ -12,4 +12,9 @@ class PostNoteDao extends AbstractDao implements ICrudDao
'postNotes',
new PostNoteEntityConverter());
}
public function findByPostId($postId)
{
return $this->findBy('postId', $postId);
}
}

View file

@ -0,0 +1,19 @@
<?php
namespace Szurubooru\Services;
use Szurubooru\Dao\PostNoteDao;
use Szurubooru\Entities\Post;
class PostNotesService
{
private $postNoteDao;
public function __construct(PostNoteDao $postNoteDao)
{
$this->postNoteDao = $postNoteDao;
}
public function getPostNotes(Post $post)
{
return $this->postNoteDao->findByPostId($post->getId());
}
}