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