Added post note retrieval in backend
This commit is contained in:
parent
e03ed35862
commit
f3a4c9ee67
5 changed files with 58 additions and 2 deletions
|
@ -158,6 +158,7 @@ final class PostController extends AbstractController
|
||||||
PostViewProxy::FETCH_HISTORY => true,
|
PostViewProxy::FETCH_HISTORY => true,
|
||||||
PostViewProxy::FETCH_OWN_SCORE => true,
|
PostViewProxy::FETCH_OWN_SCORE => true,
|
||||||
PostViewProxy::FETCH_FAVORITES => true,
|
PostViewProxy::FETCH_FAVORITES => true,
|
||||||
|
PostViewProxy::FETCH_NOTES => true,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
21
src/Controllers/ViewProxies/PostNoteViewProxy.php
Normal file
21
src/Controllers/ViewProxies/PostNoteViewProxy.php
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,14 +1,15 @@
|
||||||
<?php
|
<?php
|
||||||
namespace Szurubooru\Controllers\ViewProxies;
|
namespace Szurubooru\Controllers\ViewProxies;
|
||||||
|
use Szurubooru\Entities\Post;
|
||||||
use Szurubooru\Helpers\EnumHelper;
|
use Szurubooru\Helpers\EnumHelper;
|
||||||
use Szurubooru\Helpers\MimeHelper;
|
use Szurubooru\Helpers\MimeHelper;
|
||||||
use Szurubooru\Privilege;
|
use Szurubooru\Privilege;
|
||||||
use Szurubooru\Services\AuthService;
|
use Szurubooru\Services\AuthService;
|
||||||
use Szurubooru\Services\FavoritesService;
|
use Szurubooru\Services\FavoritesService;
|
||||||
use Szurubooru\Services\HistoryService;
|
use Szurubooru\Services\HistoryService;
|
||||||
|
use Szurubooru\Services\PostNotesService;
|
||||||
use Szurubooru\Services\PrivilegeService;
|
use Szurubooru\Services\PrivilegeService;
|
||||||
use Szurubooru\Services\ScoreService;
|
use Szurubooru\Services\ScoreService;
|
||||||
use Szurubooru\Entities\Post;
|
|
||||||
|
|
||||||
class PostViewProxy extends AbstractViewProxy
|
class PostViewProxy extends AbstractViewProxy
|
||||||
{
|
{
|
||||||
|
@ -18,15 +19,18 @@ class PostViewProxy extends AbstractViewProxy
|
||||||
const FETCH_HISTORY = 'fetchHistory';
|
const FETCH_HISTORY = 'fetchHistory';
|
||||||
const FETCH_OWN_SCORE = 'fetchOwnScore';
|
const FETCH_OWN_SCORE = 'fetchOwnScore';
|
||||||
const FETCH_FAVORITES = 'fetchFavorites';
|
const FETCH_FAVORITES = 'fetchFavorites';
|
||||||
|
const FETCH_NOTES = 'fetchNotes';
|
||||||
|
|
||||||
private $privilegeService;
|
private $privilegeService;
|
||||||
private $authService;
|
private $authService;
|
||||||
private $historyService;
|
private $historyService;
|
||||||
private $favoritesService;
|
private $favoritesService;
|
||||||
private $scoreService;
|
private $scoreService;
|
||||||
|
private $postNotesService;
|
||||||
private $tagViewProxy;
|
private $tagViewProxy;
|
||||||
private $userViewProxy;
|
private $userViewProxy;
|
||||||
private $snapshotViewProxy;
|
private $snapshotViewProxy;
|
||||||
|
private $postNoteViewProxy;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
PrivilegeService $privilegeService,
|
PrivilegeService $privilegeService,
|
||||||
|
@ -34,18 +38,22 @@ class PostViewProxy extends AbstractViewProxy
|
||||||
HistoryService $historyService,
|
HistoryService $historyService,
|
||||||
FavoritesService $favoritesService,
|
FavoritesService $favoritesService,
|
||||||
ScoreService $scoreService,
|
ScoreService $scoreService,
|
||||||
|
PostNotesService $postNotesService,
|
||||||
TagViewProxy $tagViewProxy,
|
TagViewProxy $tagViewProxy,
|
||||||
UserViewProxy $userViewProxy,
|
UserViewProxy $userViewProxy,
|
||||||
SnapshotViewProxy $snapshotViewProxy)
|
SnapshotViewProxy $snapshotViewProxy,
|
||||||
|
PostNoteViewProxy $postNoteViewProxy)
|
||||||
{
|
{
|
||||||
$this->privilegeService = $privilegeService;
|
$this->privilegeService = $privilegeService;
|
||||||
$this->authService = $authService;
|
$this->authService = $authService;
|
||||||
$this->historyService = $historyService;
|
$this->historyService = $historyService;
|
||||||
$this->favoritesService = $favoritesService;
|
$this->favoritesService = $favoritesService;
|
||||||
$this->scoreService = $scoreService;
|
$this->scoreService = $scoreService;
|
||||||
|
$this->postNotesService = $postNotesService;
|
||||||
$this->tagViewProxy = $tagViewProxy;
|
$this->tagViewProxy = $tagViewProxy;
|
||||||
$this->userViewProxy = $userViewProxy;
|
$this->userViewProxy = $userViewProxy;
|
||||||
$this->snapshotViewProxy = $snapshotViewProxy;
|
$this->snapshotViewProxy = $snapshotViewProxy;
|
||||||
|
$this->postNoteViewProxy = $postNoteViewProxy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function fromEntity($post, $config = [])
|
public function fromEntity($post, $config = [])
|
||||||
|
@ -105,6 +113,8 @@ class PostViewProxy extends AbstractViewProxy
|
||||||
if (!empty($config[self::FETCH_FAVORITES]))
|
if (!empty($config[self::FETCH_FAVORITES]))
|
||||||
$result->favorites = $this->userViewProxy->fromArray($this->favoritesService->getFavoriteUsers($post));
|
$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;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,4 +12,9 @@ class PostNoteDao extends AbstractDao implements ICrudDao
|
||||||
'postNotes',
|
'postNotes',
|
||||||
new PostNoteEntityConverter());
|
new PostNoteEntityConverter());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function findByPostId($postId)
|
||||||
|
{
|
||||||
|
return $this->findBy('postId', $postId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
19
src/Services/PostNotesService.php
Normal file
19
src/Services/PostNotesService.php
Normal 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());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue