2014-10-04 12:06:50 +02:00
|
|
|
<?php
|
|
|
|
namespace Szurubooru\Dao;
|
2014-10-08 14:47:47 +02:00
|
|
|
use Szurubooru\Dao\EntityConverters\CommentEntityConverter;
|
|
|
|
use Szurubooru\Dao\PostDao;
|
|
|
|
use Szurubooru\Dao\UserDao;
|
|
|
|
use Szurubooru\DatabaseConnection;
|
|
|
|
use Szurubooru\Entities\Comment;
|
|
|
|
use Szurubooru\Entities\Entity;
|
|
|
|
use Szurubooru\Entities\Post;
|
2014-10-04 12:06:50 +02:00
|
|
|
|
|
|
|
class CommentDao extends AbstractDao implements ICrudDao
|
|
|
|
{
|
|
|
|
private $userDao;
|
|
|
|
private $postDao;
|
|
|
|
|
|
|
|
public function __construct(
|
2014-10-08 14:47:47 +02:00
|
|
|
DatabaseConnection $databaseConnection,
|
|
|
|
UserDao $userDao,
|
|
|
|
PostDao $postDao)
|
2014-10-04 12:06:50 +02:00
|
|
|
{
|
|
|
|
parent::__construct(
|
|
|
|
$databaseConnection,
|
|
|
|
'comments',
|
2014-10-08 14:47:47 +02:00
|
|
|
new CommentEntityConverter());
|
2014-10-04 12:06:50 +02:00
|
|
|
|
|
|
|
$this->userDao = $userDao;
|
|
|
|
$this->postDao = $postDao;
|
|
|
|
}
|
|
|
|
|
2014-10-08 14:47:47 +02:00
|
|
|
public function findByPost(Post $post)
|
2014-10-04 12:06:50 +02:00
|
|
|
{
|
|
|
|
return $this->findBy('postId', $post->getId());
|
|
|
|
}
|
|
|
|
|
2014-10-08 14:47:47 +02:00
|
|
|
protected function afterLoad(Entity $comment)
|
2014-10-04 12:06:50 +02:00
|
|
|
{
|
|
|
|
$comment->setLazyLoader(
|
2014-10-08 14:47:47 +02:00
|
|
|
Comment::LAZY_LOADER_USER,
|
|
|
|
function (Comment $comment)
|
2014-10-04 12:06:50 +02:00
|
|
|
{
|
|
|
|
return $this->userDao->findById($comment->getUserId());
|
|
|
|
});
|
|
|
|
|
|
|
|
$comment->setLazyLoader(
|
2014-10-08 14:47:47 +02:00
|
|
|
Comment::LAZY_LOADER_POST,
|
|
|
|
function (Comment $comment)
|
2014-10-04 12:06:50 +02:00
|
|
|
{
|
|
|
|
return $this->postDao->findById($comment->getPostId());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|