mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
comments: form controller
This commit is contained in:
parent
ecbe30ae53
commit
f01b87b348
@ -0,0 +1,86 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Chill\PersonBundle\Controller;
|
||||||
|
|
||||||
|
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||||
|
use Chill\PersonBundle\Form\AccompanyingCourseCommentType;
|
||||||
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
||||||
|
use Symfony\Component\Form\FormInterface;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
|
|
||||||
|
class AccompanyingCourseCommentController extends Controller
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Comments page of Accompanying Course section.
|
||||||
|
*
|
||||||
|
* @Route("/{_locale}/parcours/{accompanying_period_id}/comments", name="chill_person_accompanying_period_comment_list")
|
||||||
|
* @ParamConverter("accompanyingCourse", options={"id": "accompanying_period_id"})
|
||||||
|
*/
|
||||||
|
public function commentAction(AccompanyingPeriod $accompanyingCourse, Request $request): Response
|
||||||
|
{
|
||||||
|
$newComment = new AccompanyingPeriod\Comment();
|
||||||
|
$newComment->setAccompanyingPeriod($accompanyingCourse);
|
||||||
|
|
||||||
|
$form = $this->createCommentForm($newComment, 'new');
|
||||||
|
|
||||||
|
if ($request->query->has('edit')) {
|
||||||
|
foreach ($accompanyingCourse->getComments() as $comment) {
|
||||||
|
if ($comment->getId() === $request->query->getInt('edit')) {
|
||||||
|
$editForm = $this->createCommentForm($comment, 'edit');
|
||||||
|
$commentEditId = $comment->getId();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$pinnedComment = $accompanyingCourse->getPinnedComment();
|
||||||
|
if ($pinnedComment->getId() === $request->query->getInt('edit')) {
|
||||||
|
$editForm = $this->createCommentForm($pinnedComment, 'edit');
|
||||||
|
$commentEditId = $pinnedComment->getId();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($request->getMethod() === Request::METHOD_POST) {
|
||||||
|
if (array_key_exists('edit', $request->request->all()[$editForm->getName()])) {
|
||||||
|
$currentForm = $editForm->handleRequest($request);
|
||||||
|
$isEditingNew = false;
|
||||||
|
} else {
|
||||||
|
$currentForm = $form->handleRequest($request);
|
||||||
|
$isEditingNew = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($currentForm->isSubmitted() && $currentForm->isValid()) {
|
||||||
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
if ($isEditingNew) {
|
||||||
|
$em->persist($newComment);
|
||||||
|
}
|
||||||
|
$em->flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->redirectToRoute('chill_person_accompanying_period_comment_list', [
|
||||||
|
'accompanying_period_id' => $accompanyingCourse->getId()
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->render('@ChillPerson/AccompanyingCourse/comment_list.html.twig', [
|
||||||
|
'accompanyingCourse' => $accompanyingCourse,
|
||||||
|
'form' => $form->createView(),
|
||||||
|
'edit_form' => isset($editForm) ? $editForm->createView() : null,
|
||||||
|
'commentEditId' => $commentEditId ?? null,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createCommentForm(AccompanyingPeriod\Comment $comment, string $step): FormInterface
|
||||||
|
{
|
||||||
|
$form = $this->createForm(AccompanyingCourseCommentType::class, $comment);
|
||||||
|
|
||||||
|
if ('edit' === $step) {
|
||||||
|
$form->add('edit', HiddenType::class, ['mapped' => false ]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $form;
|
||||||
|
}
|
||||||
|
}
|
@ -14,7 +14,6 @@ namespace Chill\PersonBundle\Controller;
|
|||||||
use Chill\ActivityBundle\Entity\Activity;
|
use Chill\ActivityBundle\Entity\Activity;
|
||||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||||
use Chill\PersonBundle\Entity\Person;
|
use Chill\PersonBundle\Entity\Person;
|
||||||
use Chill\PersonBundle\Form\AccompanyingCourseCommentType;
|
|
||||||
use Chill\PersonBundle\Form\AccompanyingCourseType;
|
use Chill\PersonBundle\Form\AccompanyingCourseType;
|
||||||
use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkRepository;
|
use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkRepository;
|
||||||
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
|
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
|
||||||
@ -110,34 +109,6 @@ class AccompanyingCourseController extends Controller
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Comments page of Accompanying Course section.
|
|
||||||
*
|
|
||||||
* @Route("/{_locale}/parcours/{accompanying_period_id}/comments", name="chill_person_accompanying_period_comment_list")
|
|
||||||
* @ParamConverter("accompanyingCourse", options={"id": "accompanying_period_id"})
|
|
||||||
*/
|
|
||||||
public function commentAction(AccompanyingPeriod $accompanyingCourse, Request $request): Response
|
|
||||||
{
|
|
||||||
$comment = new AccompanyingPeriod\Comment();
|
|
||||||
|
|
||||||
$form = $this->createForm(AccompanyingCourseCommentType::class, $comment, []);
|
|
||||||
$form->handleRequest($request);
|
|
||||||
|
|
||||||
if ($form->isSubmitted() && $form->isValid()) {
|
|
||||||
$em = $this->getDoctrine()->getManager();
|
|
||||||
|
|
||||||
$em->persist($comment);
|
|
||||||
$em->flush();
|
|
||||||
|
|
||||||
return $this->redirectToRoute($route);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->render('@ChillPerson/AccompanyingCourse/comment_list.html.twig', [
|
|
||||||
'accompanyingCourse' => $accompanyingCourse,
|
|
||||||
'form' => $form->createView(),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Edit page of Accompanying Course section.
|
* Edit page of Accompanying Course section.
|
||||||
*
|
*
|
||||||
|
@ -73,14 +73,12 @@ class AccompanyingCourseMenuBuilder implements LocalMenuBuilderInterface
|
|||||||
], ])
|
], ])
|
||||||
->setExtras(['order' => 40]);
|
->setExtras(['order' => 40]);
|
||||||
|
|
||||||
/*
|
|
||||||
$menu->addChild($this->translator->trans('Accompanying Course Comment'), [
|
$menu->addChild($this->translator->trans('Accompanying Course Comment'), [
|
||||||
'route' => 'chill_person_accompanying_period_comment_list',
|
'route' => 'chill_person_accompanying_period_comment_list',
|
||||||
'routeParameters' => [
|
'routeParameters' => [
|
||||||
'accompanying_period_id' => $period->getId(),
|
'accompanying_period_id' => $period->getId(),
|
||||||
], ])
|
], ])
|
||||||
->setExtras(['order' => 50]);
|
->setExtras(['order' => 50]);
|
||||||
*/
|
|
||||||
|
|
||||||
$workflow = $this->registry->get($period, 'accompanying_period_lifecycle');
|
$workflow = $this->registry->get($period, 'accompanying_period_lifecycle');
|
||||||
|
|
||||||
|
@ -1,63 +1,92 @@
|
|||||||
{% extends '@ChillPerson/AccompanyingCourse/layout.html.twig' %}
|
{% extends '@ChillPerson/AccompanyingCourse/layout.html.twig' %}
|
||||||
|
|
||||||
|
{% block title %}
|
||||||
|
{{ 'Accompanying Course Comment list'|trans }}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
{% macro show_comment(comment, options) %}
|
{% macro show_comment(comment, options) %}
|
||||||
<div class="item-bloc">
|
<div class="item-bloc">
|
||||||
<div class="item-row">
|
<div class="item-row">
|
||||||
<div>
|
<div>
|
||||||
{% if options.pinned is defined %}
|
{% if options.pinned is defined %}
|
||||||
<i class="fa fa-flag fa-fw" title="{{ 'pinned'|trans }}"></i>
|
<i class="fa fa-flag fa-fw fa-lg" title="{{ 'pinned'|trans }}"></i>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<a id="comment{{ comment.id }}" href="{{ '#comment' ~ comment.id }}" class="fa fa-pencil-square-o fa-fw"></a>
|
<a id="comment{{ comment.id }}" href="{{ '#comment' ~ comment.id }}" class="fa fa-pencil-square-o fa-fw"></a>
|
||||||
{{ 'by'|trans }}<b>{{ comment.creator }}</b>{{ ', ' ~ 'on'|trans ~ ' ' ~ comment.createdAt|format_date('long') }}<br>
|
{{ 'by'|trans }}<b>{{ comment.creator }}</b>{{ ', ' ~ 'on'|trans ~ ' ' ~ comment.createdAt|format_date('long') }}<br>
|
||||||
<i>{{ 'Last updated on'|trans ~ ' ' ~ comment.updatedAt|format_datetime('long', 'short') }}</i>
|
<i>{{ 'Last updated on'|trans ~ ' ' ~ comment.updatedAt|format_datetime('long', 'short') }}</i>
|
||||||
</div>
|
</div>
|
||||||
<ul class="record_actions">
|
<ul class="record_actions">
|
||||||
<li><a class="btn btn-edit" title="{{ 'Edit'|trans }}" href="{{ '?edit=' ~ comment.id ~ '#comment' ~ comment.id }}"></a></li>
|
{% if options.pinned is not defined %}
|
||||||
<li><a class="btn btn-delete" title="{{ 'Delete'|trans }}" href=""></a></li>
|
<li>
|
||||||
|
<button class="btn btn-sm btn-misc" type="button">
|
||||||
|
<i class="fa fa-flag fa-fw"></i>
|
||||||
|
Épingler
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
{% endif %}
|
||||||
|
<li>
|
||||||
|
<a class="btn btn-sm btn-edit" title="{{ 'Edit'|trans }}" href="{{ path('chill_person_accompanying_period_comment_list', {
|
||||||
|
'accompanying_period_id': comment.accompanyingPeriod.id,
|
||||||
|
'edit': comment.id
|
||||||
|
}) ~ '#comment' ~ comment.id }}"></a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a class="btn btn-sm btn-delete" title="{{ 'Delete'|trans }}" href=""></a>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div class="item-row separator">
|
<div class="item-row separator">
|
||||||
<blockquote class="chill-user-quote col">{{ comment.content }}</blockquote>
|
<blockquote class="chill-user-quote col">{{ comment.content|chill_markdown_to_html }}</blockquote>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|
||||||
{% block title %}
|
{% macro form_comment(type, form) %}
|
||||||
{{ 'Accompanying Course Comment list'|trans }}
|
{% if type == 'edit' %}
|
||||||
{% endblock %}
|
<div class="item-bloc">
|
||||||
|
<div class="item-row row">
|
||||||
|
{% endif %}
|
||||||
|
{{ form_start(form) }}
|
||||||
|
{{ form_errors(form) }}
|
||||||
|
{{ form_widget(form.content) }}
|
||||||
|
<ul class="record_actions">
|
||||||
|
<li>
|
||||||
|
{% if type == 'new' %}
|
||||||
|
<button class="btn btn-create" type="submit">{{ 'Post a new comment'|trans }}</button>
|
||||||
|
{% elseif type == 'edit' %}
|
||||||
|
<button class="btn btn-save" type="submit">{{ 'Save'|trans }}</button>
|
||||||
|
{% endif %}
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
{{ form_end(form) }}
|
||||||
|
{% if type == 'edit' %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
{% endmacro %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="accompanyingcourse-comment-list">
|
<div class="accompanyingcourse-comment-list">
|
||||||
<h1>{{ block('title') }}</h1>
|
<h1>{{ block('title') }}</h1>
|
||||||
|
|
||||||
<div class="form my-5">
|
|
||||||
{{ form_start(form) }}
|
|
||||||
{{ form_errors(form) }}
|
|
||||||
|
|
||||||
{{ form_widget(form.content) }}
|
|
||||||
|
|
||||||
<ul class="record_actions">
|
|
||||||
<li>
|
|
||||||
<button class="btn btn-create" type="submit">{{ 'Post a new comment'|trans }}</button>
|
|
||||||
{#
|
|
||||||
<button class="btn btn-update" type="submit">{{ 'Edit a comment'|trans }}</button>
|
|
||||||
#}
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
{{ form_end(form) }}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="flex-table">
|
<div class="flex-table">
|
||||||
|
|
||||||
{% if accompanyingCourse.pinnedComment %}
|
{% if accompanyingCourse.pinnedComment %}
|
||||||
|
{% if commentEditId == accompanyingCourse.pinnedComment.id %}
|
||||||
|
{{ _self.form_comment('edit', edit_form) }}
|
||||||
|
{% else %}
|
||||||
{{ _self.show_comment(accompanyingCourse.pinnedComment, {'pinned': 'true'}) }}
|
{{ _self.show_comment(accompanyingCourse.pinnedComment, {'pinned': 'true'}) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
{% for c in accompanyingCourse.comments %}
|
{% for c in accompanyingCourse.comments %}
|
||||||
|
{% if commentEditId == c.id %}
|
||||||
|
{{ _self.form_comment('edit', edit_form) }}
|
||||||
|
{% else %}
|
||||||
{{ _self.show_comment(c) }}
|
{{ _self.show_comment(c) }}
|
||||||
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
<div class="new-comment my-5">
|
||||||
|
<h2 class="chill-blue">{{ 'Write a new comment'|trans }}</h2>
|
||||||
|
{{ _self.form_comment('new', form) }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -413,6 +413,7 @@ Accompanying Course Comment: Commentaire
|
|||||||
Accompanying Course Comment list: Commentaires du parcours
|
Accompanying Course Comment list: Commentaires du parcours
|
||||||
pinned: épinglé
|
pinned: épinglé
|
||||||
Post a new comment: Poster un nouveau commentaire
|
Post a new comment: Poster un nouveau commentaire
|
||||||
|
Write a new comment: Écrire un nouveau commentaire
|
||||||
Edit a comment: Modifier le commentaire
|
Edit a comment: Modifier le commentaire
|
||||||
|
|
||||||
# Household
|
# Household
|
||||||
|
Loading…
x
Reference in New Issue
Block a user