Add CommentEmbeddable to Activity (Ref #21)

This commit is contained in:
Jean-Francois Monfort 2021-03-11 12:30:11 +01:00
parent f4a76f659e
commit c1c3839c62
5 changed files with 66 additions and 32 deletions

View File

@ -1,25 +1,26 @@
<?php <?php
/* /*
* *
* Copyright (C) 2015, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop> * Copyright (C) 2015, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as * it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the * published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version. * License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
namespace Chill\ActivityBundle\Entity; namespace Chill\ActivityBundle\Entity;
use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Chill\MainBundle\Entity\Scope; use Chill\MainBundle\Entity\Scope;
use Chill\MainBundle\Entity\User; use Chill\MainBundle\Entity\User;
@ -109,16 +110,21 @@ class Activity implements HasCenterInterface, HasScopeInterface
* @ORM\ManyToOne(targetEntity="Chill\PersonBundle\Entity\Person") * @ORM\ManyToOne(targetEntity="Chill\PersonBundle\Entity\Person")
*/ */
private $person; private $person;
/**
* @ORM\Embedded(class="Chill\MainBundle\Entity\Embeddable\CommentEmbeddable", columnPrefix="comment_")
*/
private $comment;
/** /**
* Activity constructor. * Activity constructor.
*/ */
public function __construct() public function __construct()
{ {
$this->reasons = new ArrayCollection(); $this->reasons = new ArrayCollection();
$this->comment = new CommentEmbeddable();
} }
/** /**
* Get id * Get id
* *
@ -256,7 +262,7 @@ class Activity implements HasCenterInterface, HasScopeInterface
return $this; return $this;
} }
/** /**
* @param ActivityReason $reason * @param ActivityReason $reason
*/ */
@ -343,16 +349,32 @@ class Activity implements HasCenterInterface, HasScopeInterface
{ {
return $this->person; return $this->person;
} }
/** /**
* get the center * get the center
* center is extracted from person * center is extracted from person
* *
* @return Center * @return Center
*/ */
public function getCenter() public function getCenter()
{ {
return $this->person->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;
}
} }

View File

@ -2,6 +2,7 @@
namespace Chill\ActivityBundle\Form; namespace Chill\ActivityBundle\Form;
use Chill\MainBundle\Form\Type\CommentType;
use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\OptionsResolver\OptionsResolver;
@ -106,7 +107,7 @@ class ActivityType extends AbstractType
)) ))
->add('user', UserPickerType::class, [ ->add('user', UserPickerType::class, [
'center' => $options['center'], 'center' => $options['center'],
'role' => $options['role'] 'role' => $options['role']
]) ])
->add('scope', ScopePickerType::class, [ ->add('scope', ScopePickerType::class, [
'center' => $options['center'], 'center' => $options['center'],
@ -120,6 +121,9 @@ class ActivityType extends AbstractType
'placeholder' => 'Choose a type', 'placeholder' => 'Choose a type',
'active_only' => true 'active_only' => true
)) ))
->add('comment', CommentType::class, [
'required' => false,
])
; ;
$builder->get('durationTime') $builder->get('durationTime')

View File

@ -1,16 +1,16 @@
{# {#
* Copyright (C) 2014, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop> * Copyright (C) 2014, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as * it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the * published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version. * License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
#} #}
@ -22,9 +22,9 @@
{% block personcontent %} {% block personcontent %}
<h1>{{ "Update activity"|trans }}</h1> <h1>{{ "Update activity"|trans }}</h1>
{{ form_start(edit_form) }} {{ form_start(edit_form) }}
{{ form_row(edit_form.user) }} {{ form_row(edit_form.user) }}
{{ form_row(edit_form.scope) }} {{ form_row(edit_form.scope) }}
@ -35,7 +35,7 @@
{{ form_row(edit_form.remark) }} {{ form_row(edit_form.remark) }}
{{ form_row(edit_form.attendee) }} {{ form_row(edit_form.attendee) }}
{{ form_row(edit_form.reasons) }} {{ form_row(edit_form.reasons) }}
{{ form_row(form.comment) }}
{{ form_widget(edit_form) }} {{ form_widget(edit_form) }}
<ul class="record_actions sticky-form-buttons"> <ul class="record_actions sticky-form-buttons">

View File

@ -1,16 +1,16 @@
{# {#
* Copyright (C) 2014, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop> * Copyright (C) 2014, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as * it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the * published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version. * License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
#} #}
@ -24,27 +24,28 @@
<h2 class="chill-red">{{ "Activity creation"|trans }}</h1> <h2 class="chill-red">{{ "Activity creation"|trans }}</h1>
{{ form_start(form) }} {{ form_start(form) }}
{{ form_row(form.user) }} {{ form_row(form.user) }}
{{ form_row(form.scope) }} {{ form_row(form.scope) }}
<h2 class="chill-red">{{ 'Activity data'|trans }}</h2> <h2 class="chill-red">{{ 'Activity data'|trans }}</h2>
{{ form_row(form.date) }} {{ form_row(form.date) }}
{{ form_row(form.durationTime) }} {{ form_row(form.durationTime) }}
{{ form_row(form.type) }} {{ form_row(form.type) }}
{{ form_row(form.remark) }} {{ form_row(form.remark) }}
{{ form_row(form.attendee) }} {{ form_row(form.attendee) }}
{{ form_row(form.reasons) }} {{ form_row(form.reasons) }}
{{ form_row(form.comment) }}
<div class="grid-12 centered sticky-form-buttons"> <div class="grid-12 centered sticky-form-buttons">
<button class="sc-button green margin-10" type="submit"><i class="fa fa-save"></i> {{ 'Add a new activity'|trans }}</button> <button class="sc-button green margin-10" type="submit"><i class="fa fa-save"></i> {{ 'Add a new activity'|trans }}</button>
</div> </div>
{{ form_end(form) }} {{ form_end(form) }}
{% endblock %} {% endblock %}
{% block js %} {% block js %}
<script type="text/javascript"> <script type="text/javascript">
chill.displayAlertWhenLeavingUnsubmittedForm('form[name="{{ form.vars.form.vars.name }}"]', '{{ "You are going to leave a page with unsubmitted data. Are you sure you want to leave ?"|trans }}'); chill.displayAlertWhenLeavingUnsubmittedForm('form[name="{{ form.vars.form.vars.name }}"]', '{{ "You are going to leave a page with unsubmitted data. Are you sure you want to leave ?"|trans }}');
</script> </script>
{% endblock %} {% endblock %}

View File

@ -8,17 +8,17 @@
{% block personcontent -%} {% block personcontent -%}
<h1 >{{ "Activity"|trans }}</h1> <h1 >{{ "Activity"|trans }}</h1>
<dl class="chill_view_data"> <dl class="chill_view_data">
<dt class="inline">{{ 'User'|trans }}</dt> <dt class="inline">{{ 'User'|trans }}</dt>
<dd>{{ entity.user }}</dd> <dd>{{ entity.user }}</dd>
<dt class="inline">{{ 'Scope'|trans }}</dt> <dt class="inline">{{ 'Scope'|trans }}</dt>
<dd><span class="scope">{{ entity.scope.name|localize_translatable_string }}</span></dd> <dd><span class="scope">{{ entity.scope.name|localize_translatable_string }}</span></dd>
<h2 class="chill-red">{{ 'Activity data'|trans }}</h2> <h2 class="chill-red">{{ 'Activity data'|trans }}</h2>
<dt class="inline">{{ 'Person'|trans }}</dt> <dt class="inline">{{ 'Person'|trans }}</dt>
<dd>{{ entity.person }}</dd> <dd>{{ entity.person }}</dd>
<dt class="inline">{{ 'Date'|trans }}</dt> <dt class="inline">{{ 'Date'|trans }}</dt>
<dd>{{ entity.date|format_date('long') }}</dd> <dd>{{ entity.date|format_date('long') }}</dd>
<dt class="inline">{{ 'Duration Time'|trans }}</dt> <dt class="inline">{{ 'Duration Time'|trans }}</dt>
@ -27,17 +27,24 @@
<dd>{{ entity.type.name | localize_translatable_string }}</dd> <dd>{{ entity.type.name | localize_translatable_string }}</dd>
<dt class="inline">{{ 'Remark'|trans }}</dt> <dt class="inline">{{ 'Remark'|trans }}</dt>
<dd>{% if entity.remark is empty %}<span class="chill-no-data-statement">{{ 'No remarks'|trans }}</span>{% else %}<blockquote class="chill-user-quote">{{ entity.remark|nl2br }}</blockquote>{% endif %}</dd> <dd>{% if entity.remark is empty %}<span class="chill-no-data-statement">{{ 'No remarks'|trans }}</span>{% else %}<blockquote class="chill-user-quote">{{ entity.remark|nl2br }}</blockquote>{% endif %}</dd>
<dt class="inline">{{ 'Attendee'|trans }}</dt> <dt class="inline">{{ 'Attendee'|trans }}</dt>
<dd>{% if entity.attendee is not null %}{% if entity.attendee %}{{ 'present'|trans|capitalize }} {% else %} {{ 'not present'|trans|capitalize }}{% endif %}{% else %}{{ 'None'|trans|capitalize }}{% endif %}</dd> <dd>{% if entity.attendee is not null %}{% if entity.attendee %}{{ 'present'|trans|capitalize }} {% else %} {{ 'not present'|trans|capitalize }}{% endif %}{% else %}{{ 'None'|trans|capitalize }}{% endif %}</dd>
<dt class="inline">{{ 'Reasons'|trans }}</dt> <dt class="inline">{{ 'Reasons'|trans }}</dt>
{%- if entity.reasons is empty -%} {%- if entity.reasons is empty -%}
<dd><span class="chill-no-data-statement">{{ 'No reason associated'|trans }}</span></dd> <dd><span class="chill-no-data-statement">{{ 'No reason associated'|trans }}</span></dd>
{%- else -%} {%- else -%}
<dd>{% for r in entity.reasons %}{{ r|chill_entity_render_box }} {% endfor %}</dd> <dd>{% for r in entity.reasons %}{{ r|chill_entity_render_box }} {% endfor %}</dd>
{%- endif -%} {%- endif -%}
<dt class="inline">{{ 'Comment'|trans }}</dt>
{%- if entity.comment is empty -%}
<dd><span class="chill-no-data-statement">{{ 'No comment associated'|trans }}</span></dd>
{%- else -%}
<dd>{{ entity.comment|chill_entity_render_box }}</dd>
{%- endif -%}
</dl> </dl>
<ul class="record_actions"> <ul class="record_actions">
@ -59,5 +66,5 @@
</li> </li>
{% endif %} {% endif %}
</ul> </ul>
{% endblock personcontent %} {% endblock personcontent %}