Add CommentEmbeddable to Activity (Ref #21)

This commit is contained in:
Jean-Francois Monfort 2021-03-11 14:28:14 +01:00
parent 63dedb90f9
commit 354a202d06
2 changed files with 13 additions and 10 deletions

View File

@ -45,7 +45,7 @@ class CommentType extends AbstractType
{
$builder
->add('comment', TextareaType::class, [
'label' => false,
])
;

View File

@ -25,7 +25,6 @@ use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Repository\UserRepository;
use Chill\MainBundle\Templating\Entity\AbstractChillEntityRender;
class CommentRender extends AbstractChillEntityRender
{
/**
@ -48,24 +47,28 @@ class CommentRender extends AbstractChillEntityRender
{
$username = '';
$user = $this->userRepository->find($entity->getUserId());
if ($user instanceof User) {
$username = $user->getUsername();
if ($entity->getUserId()) {
$user = $this->userRepository->find($entity->getUserId());
if ($user instanceof User) {
$username = $user->getUsername();
}
}
$str = $this->getDefaultOpeningBox('comment-embeddable').
'<span class="comment_comment">'.
nl2br($entity->getComment()).
'</span>'.
'<span class="comment_date">'.
$entity->getDate()->format('d/m/Y h:i');
'</span>';
if ($entity->getDate() instanceof \DateTime) {
$str .= '<span class="comment_date">'.
$entity->getDate()->format('d/m/Y H:i');
'</span>';
}
if (strlen($username) > 0) {
$str .= '<span class="comment_user">'.
$username.
'</span>'
;
'</span>';
}
$str .= $this->getDefaultClosingBox();