From c1c3839c62c27b27b729adabac8d65fd58fcdcba Mon Sep 17 00:00:00 2001 From: Jean-Francois Monfort Date: Thu, 11 Mar 2021 12:30:11 +0100 Subject: [PATCH] Add CommentEmbeddable to Activity (Ref #21) --- Entity/Activity.php | 40 +++++++++++++++++++------ Form/ActivityType.php | 6 +++- Resources/views/Activity/edit.html.twig | 12 ++++---- Resources/views/Activity/new.html.twig | 19 ++++++------ Resources/views/Activity/show.html.twig | 21 ++++++++----- 5 files changed, 66 insertions(+), 32 deletions(-) diff --git a/Entity/Activity.php b/Entity/Activity.php index a1eeae47b..dfb28301a 100644 --- a/Entity/Activity.php +++ b/Entity/Activity.php @@ -1,25 +1,26 @@ - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. - * + * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ namespace Chill\ActivityBundle\Entity; +use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable; use Doctrine\ORM\Mapping as ORM; use Chill\MainBundle\Entity\Scope; use Chill\MainBundle\Entity\User; @@ -109,16 +110,21 @@ class Activity implements HasCenterInterface, HasScopeInterface * @ORM\ManyToOne(targetEntity="Chill\PersonBundle\Entity\Person") */ private $person; - + + /** + * @ORM\Embedded(class="Chill\MainBundle\Entity\Embeddable\CommentEmbeddable", columnPrefix="comment_") + */ + private $comment; + /** * Activity constructor. */ public function __construct() { $this->reasons = new ArrayCollection(); + $this->comment = new CommentEmbeddable(); } - /** * Get id * @@ -256,7 +262,7 @@ class Activity implements HasCenterInterface, HasScopeInterface return $this; } - + /** * @param ActivityReason $reason */ @@ -343,16 +349,32 @@ class Activity implements HasCenterInterface, HasScopeInterface { return $this->person; } - + /** * get the center * center is extracted from person - * + * * @return Center */ public function getCenter() { return $this->person->getCenter(); } + + /** + * @return \Chill\MainBundle\Entity\Embeddalbe\CommentEmbeddable + */ + public function getComment() + { + return $this->comment; + } + + /** + * @param \Chill\MainBundle\Entity\Embeddalbe\CommentEmbeddable $comment + */ + public function setComment($comment) + { + $this->comment = $comment; + } } diff --git a/Form/ActivityType.php b/Form/ActivityType.php index 86d345c25..e2d660f3f 100644 --- a/Form/ActivityType.php +++ b/Form/ActivityType.php @@ -2,6 +2,7 @@ namespace Chill\ActivityBundle\Form; +use Chill\MainBundle\Form\Type\CommentType; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -106,7 +107,7 @@ class ActivityType extends AbstractType )) ->add('user', UserPickerType::class, [ 'center' => $options['center'], - 'role' => $options['role'] + 'role' => $options['role'] ]) ->add('scope', ScopePickerType::class, [ 'center' => $options['center'], @@ -120,6 +121,9 @@ class ActivityType extends AbstractType 'placeholder' => 'Choose a type', 'active_only' => true )) + ->add('comment', CommentType::class, [ + 'required' => false, + ]) ; $builder->get('durationTime') diff --git a/Resources/views/Activity/edit.html.twig b/Resources/views/Activity/edit.html.twig index 3f7d3d664..5a70d3f81 100644 --- a/Resources/views/Activity/edit.html.twig +++ b/Resources/views/Activity/edit.html.twig @@ -1,16 +1,16 @@ {# * Copyright (C) 2014, Champs Libres Cooperative SCRLFS, - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. - * + * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . #} @@ -22,9 +22,9 @@ {% block personcontent %}

{{ "Update activity"|trans }}

- + {{ form_start(edit_form) }} - + {{ form_row(edit_form.user) }} {{ form_row(edit_form.scope) }} @@ -35,7 +35,7 @@ {{ form_row(edit_form.remark) }} {{ form_row(edit_form.attendee) }} {{ form_row(edit_form.reasons) }} - + {{ form_row(form.comment) }} {{ form_widget(edit_form) }}
    diff --git a/Resources/views/Activity/new.html.twig b/Resources/views/Activity/new.html.twig index b77e352d6..1ec0b0c90 100644 --- a/Resources/views/Activity/new.html.twig +++ b/Resources/views/Activity/new.html.twig @@ -1,16 +1,16 @@ {# * Copyright (C) 2014, Champs Libres Cooperative SCRLFS, - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. - * + * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . #} @@ -24,27 +24,28 @@

    {{ "Activity creation"|trans }}

    {{ form_start(form) }} - + {{ form_row(form.user) }} {{ form_row(form.scope) }} - +

    {{ 'Activity data'|trans }}

    - + {{ form_row(form.date) }} {{ form_row(form.durationTime) }} {{ form_row(form.type) }} {{ form_row(form.remark) }} {{ form_row(form.attendee) }} {{ form_row(form.reasons) }} - + {{ form_row(form.comment) }} +
    {{ form_end(form) }} {% endblock %} - + {% block js %} -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/Resources/views/Activity/show.html.twig b/Resources/views/Activity/show.html.twig index 01237c275..78df904b2 100644 --- a/Resources/views/Activity/show.html.twig +++ b/Resources/views/Activity/show.html.twig @@ -8,17 +8,17 @@ {% block personcontent -%}

    {{ "Activity"|trans }}

    - +
    {{ 'User'|trans }}
    {{ entity.user }}
    {{ 'Scope'|trans }}
    {{ entity.scope.name|localize_translatable_string }}
    - +

    {{ 'Activity data'|trans }}

    {{ 'Person'|trans }}
    {{ entity.person }}
    - +
    {{ 'Date'|trans }}
    {{ entity.date|format_date('long') }}
    {{ 'Duration Time'|trans }}
    @@ -27,17 +27,24 @@
    {{ entity.type.name | localize_translatable_string }}
    {{ 'Remark'|trans }}
    {% if entity.remark is empty %}{{ 'No remarks'|trans }}{% else %}
    {{ entity.remark|nl2br }}
    {% endif %}
    - +
    {{ 'Attendee'|trans }}
    {% if entity.attendee is not null %}{% if entity.attendee %}{{ 'present'|trans|capitalize }} {% else %} {{ 'not present'|trans|capitalize }}{% endif %}{% else %}{{ 'None'|trans|capitalize }}{% endif %}
    - +
    {{ 'Reasons'|trans }}
    {%- if entity.reasons is empty -%}
    {{ 'No reason associated'|trans }}
    {%- else -%}
    {% for r in entity.reasons %}{{ r|chill_entity_render_box }} {% endfor %}
    {%- endif -%} - + +
    {{ 'Comment'|trans }}
    + {%- if entity.comment is empty -%} +
    {{ 'No comment associated'|trans }}
    + {%- else -%} +
    {{ entity.comment|chill_entity_render_box }}
    + {%- endif -%} +
      @@ -59,5 +66,5 @@ {% endif %}
    - + {% endblock personcontent %}