replace comment by commentEmbeddable

This commit is contained in:
Julien Fastré 2021-06-15 10:17:53 +02:00
parent f827e50431
commit efdfd10e49
6 changed files with 132 additions and 30 deletions

View File

@ -4,6 +4,7 @@ namespace Chill\PersonBundle\Controller;
use Chill\PersonBundle\Form\HouseholdType;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
@ -77,10 +78,17 @@ class HouseholdController extends AbstractController
// some queries
$household->getMembers()->initialize();
if ($request->query->has('edit')) {
$form = $this->createMetadataForm($household);
} else {
$form = null;
}
return $this->render('@ChillPerson/Household/members.html.twig',
[
'household' => $household,
'positions' => $positions
'positions' => $positions,
'form' => NULL !== $form ? $form->createView(): $form
]
);
}
@ -132,10 +140,7 @@ class HouseholdController extends AbstractController
public function editHouseholdMetadata(Request $request, Household $household)
{
// TODO ACL
$form = $this->createForm(
HouseholdType::class,
$household
);
$form = $this->createMetadataForm($household);
$form->handleRequest($request);
@ -154,4 +159,22 @@ class HouseholdController extends AbstractController
'form' => $form->createView()
]);
}
private function createMetadataForm(Household $household): FormInterface
{
$form = $this->createForm(
HouseholdType::class,
$household,
[
'action' => $this->generateUrl(
'chill_person_household_members_metadata_edit',
[
'household_id' => $household->getId()
]
)
]
);
return $form;
}
}

View File

@ -10,6 +10,7 @@ use Symfony\Component\Serializer\Annotation as Serializer;
use Chill\MainBundle\Entity\Address;
use Chill\PersonBundle\Entity\Household\HouseholdMember;
use Chill\PersonBundle\Validator\Constraints\Household\MaxHolder;
use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable;
/**
* @ORM\Entity
@ -52,9 +53,9 @@ class Household
private Collection $members;
/**
* @ORM\Column(type="text", name="comment_members", options={"default": ""})
* @ORM\Embedded(class=CommentEmbeddable::class, columnPrefix="comment_members_")
*/
private string $commentMembers = "";
private CommentEmbeddable $commentMembers;
/**
* @ORM\Column(type="boolean", name="waiting_for_birth", options={"default": false})
@ -70,6 +71,7 @@ class Household
{
$this->addresses = new ArrayCollection();
$this->members = new ArrayCollection();
$this->commentMembers = new CommentEmbeddable();
}
public function getId(): ?int
@ -221,12 +223,12 @@ class Household
return $this;
}
public function getCommentMembers(): ?string
public function getCommentMembers(): CommentEmbeddable
{
return $this->commentMembers;
}
public function setCommentMembers(string $commentMembers): self
public function setCommentMembers(CommentEmbeddable $commentMembers): self
{
$this->commentMembers = $commentMembers;

View File

@ -3,7 +3,7 @@
namespace Chill\PersonBundle\Form;
use Chill\MainBundle\Form\Type\ChillDateType;
use Chill\MainBundle\Form\Type\ChillTextareaType;
use Chill\MainBundle\Form\Type\CommentType;
use Chill\PersonBundle\Entity\Household\Household;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\AbstractType;
@ -15,7 +15,7 @@ class HouseholdType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('commentMembers', ChillTextareaType::class, [
->add('commentMembers', CommentType::class, [
'label' => 'household.comment_membership',
'required' => false
])

View File

@ -5,18 +5,58 @@
{% block content %}
<h1>{{ block('title') }}</h1>
{% if household.commentMembers is not empty %}
<blockquote class="chill-user-quote">
{{ household.commentMembers|chill_markdown_to_html }}
</blockquote>
{% endif %}
{% if form is not null %}
{{ form_start(form) }}
{% if household.waitingForBirth %}
{{ form_row(form.commentMembers) }}
<div id="waitingForBirthContainer">
{{ form_row(form.waitingForBirth) }}
</div>
<div id="waitingForBirthDateContainer">
{{ form_row(form.waitingForBirthDate) }}
</div>
<ul class="record_actions">
<li>
<button type="submit" class="sc-button bt-save">
{{ 'Save'|trans }}
</button>
</li>
</ul>
{{ form_end(form) }}
{% else %}
{% if not household.commentMembers.isEmpty() %}
{{ household.commentMembers|chill_entity_render_box }}
{% endif %}
{% if household.waitingForBirth %}
{% if household.waitingForBirthDate is not null %}
{{ 'household.Expecting for birth on date'|trans({ 'date': household.waitingForBirthDate|format_date('long') }) }}
{% else %}
{{ 'household.Expecting for birth'|trans }}
{% endif %}
{% else %}
<p class="chill-no-data-statement">
{{ 'household.Any expecting birth'|trans }}
</p>
{% endif %}
<ul class="record_actions">
<li>
<a
href="{{ chill_path_add_return_path('chill_person_household_members', { 'household_id': household.id, 'edit': 1 }) }}"
class="sc-button bt-edit"
>
{{ 'household.Comment and expecting birth'|trans }}
</a>
</li>
</ul>
{% endif %}
{% for p in positions %}
@ -153,14 +193,6 @@
{% endfor %}
<ul class="record_actions sticky-form-buttons">
<li>
<a
href="{{ chill_path_add_return_path('chill_person_household_members_metadata_edit', { 'household_id': household.id }) }}"
class="sc-button bt-edit"
>
{{ 'household.Edit member metadata'|trans }}
</a>
</li>
<li>
<a
href="{{ chill_path_add_return_path('chill_person_household_members_editor', {'household': household.id }) }}"
@ -171,3 +203,7 @@
</ul>
{% endblock %}
{% block js %}
{{ encore_entry_script_tags('household_edit_metadata') }}
{% endblock %}

View File

@ -0,0 +1,39 @@
<?php
declare(strict_types=1);
namespace Chill\Migrations\Person;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Set comment in household as Embedded Comment
*/
final class Version20210615074857 extends AbstractMigration
{
public function getDescription(): string
{
return 'replace comment in household as embedded comment';
}
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE chill_person_household RENAME comment_members TO comment_members_comment');
$this->addSql('ALTER TABLE chill_person_household ALTER COLUMN comment_members_comment DROP NOT NULL');
$this->addSql('ALTER TABLE chill_person_household ALTER COLUMN comment_members_comment SET DEFAULT NULL');
$this->addSql('ALTER TABLE chill_person_household ADD comment_members_userId INT DEFAULT NULL');
$this->addSql('ALTER TABLE chill_person_household ADD comment_members_date TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL');
$this->addSql('ALTER TABLE chill_person_household ADD CONSTRAINT fk_household_comment_embeddable_user FOREIGN KEY (comment_members_userId) REFERENCES users (id)');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE chill_person_household RENAME comment_members_comment TO comment_members');
$this->addSql('ALTER TABLE chill_person_household ALTER comment_members SET DEFAULT \'\'');
$this->addSql('ALTER TABLE chill_person_household ALTER comment_members SET NOT NULL');
$this->addSql('ALTER TABLE chill_person_household DROP comment_members_comment');
$this->addSql('ALTER TABLE chill_person_household DROP comment_members_userId');
$this->addSql('ALTER TABLE chill_person_household DROP comment_members_date');
}
}

View File

@ -42,6 +42,8 @@ household:
}
Expecting for birth on date: Naissance attendue pour le {date}
Expecting for birth: Naissance attendue (date inconnue)
Any expecting birth: Aucune naissance proche n'a été renseignée.
Comment and expecting birth: Commentaire et naissance attendue
Edit member metadata: Données supplémentaires
comment_membership: Commentaire général sur les membres
expecting_birth: Naissance attendue ?