From 6a62b46decd7d03fa17141888c69434c8451af80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 20 May 2021 17:41:37 +0200 Subject: [PATCH] first impl --- .../Doctrine/Model/TrackCreationInterface.php | 12 + .../Doctrine/Model/TrackUpdateInterface.php | 12 + .../modules/scratch/custom/_address.scss | 6 + .../scratch/custom/_record_actions.scss | 5 + .../views/Address/entity_render.html.twig | 16 ++ .../Templating/Entity/AddressRender.php | 67 ++++++ .../Templating/Entity/AddressRenderTest.php | 55 +++++ .../config/services/templating.yaml | 7 + .../Entity/AccompanyingPeriod.php | 197 +++++++++++++++-- .../ChillPersonBundle/Entity/Person.php | 25 +++ .../Resources/public/index.js | 3 +- .../Resources/public/sass/index.js | 2 +- .../public/sass/person_with_period.scss | 50 +++++ .../Resources/views/Entity/person.html.twig | 15 ++ .../views/Entity/social_issue.html.twig | 3 + .../views/Person/list_with_period.html.twig | 208 ++++++++++++++++++ .../ChillPersonBundle/Search/PersonSearch.php | 2 +- .../Templating/Entity/SocialIssueRender.php | 50 +++++ .../config/services/templating.yaml | 11 +- 19 files changed, 729 insertions(+), 17 deletions(-) create mode 100644 src/Bundle/ChillMainBundle/Doctrine/Model/TrackCreationInterface.php create mode 100644 src/Bundle/ChillMainBundle/Doctrine/Model/TrackUpdateInterface.php create mode 100644 src/Bundle/ChillMainBundle/Resources/views/Address/entity_render.html.twig create mode 100644 src/Bundle/ChillMainBundle/Templating/Entity/AddressRender.php create mode 100644 src/Bundle/ChillMainBundle/Tests/Templating/Entity/AddressRenderTest.php create mode 100644 src/Bundle/ChillPersonBundle/Resources/public/sass/person_with_period.scss create mode 100644 src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig create mode 100644 src/Bundle/ChillPersonBundle/Resources/views/Entity/social_issue.html.twig create mode 100644 src/Bundle/ChillPersonBundle/Resources/views/Person/list_with_period.html.twig create mode 100644 src/Bundle/ChillPersonBundle/Templating/Entity/SocialIssueRender.php diff --git a/src/Bundle/ChillMainBundle/Doctrine/Model/TrackCreationInterface.php b/src/Bundle/ChillMainBundle/Doctrine/Model/TrackCreationInterface.php new file mode 100644 index 000000000..192d4e7a9 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Doctrine/Model/TrackCreationInterface.php @@ -0,0 +1,12 @@ + + {% if options['has_no_address'] == true and address.isNoAddress == true %} +
{{ 'address.consider homeless'|trans }}
+ {% endif %} +
+ {% if address.street is not empty %}

{{ address.street }}

{% endif %} + {% if address.streetNumber is not empty %}

{{ address.streetNumber }}

{% endif %} + {% if address.postCode is not empty %} +

{{ address.postCode.code }} {{ address.postCode.name }}

+

{{ address.postCode.country.name|localize_translatable_string }}

+ {% endif %} +
+{%- if options['with_valid_from'] == true -%} +{{ 'Since %date%'|trans( { '%date%' : address.validFrom|format_date('long') } ) }} +{%- endif -%} + diff --git a/src/Bundle/ChillMainBundle/Templating/Entity/AddressRender.php b/src/Bundle/ChillMainBundle/Templating/Entity/AddressRender.php new file mode 100644 index 000000000..90a707e40 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Templating/Entity/AddressRender.php @@ -0,0 +1,67 @@ + true, + 'has_no_address' => false, + 'multiline' => true, + ]; + + public function __construct(EngineInterface $templating) + { + $this->templating = $templating; + } + + /** + * {@inheritDoc} + */ + public function supports($entity, array $options): bool + { + return $entity instanceof Address; + } + + /** + * @param Address addr + */ + public function renderString($addr, array $options): string + { + $lines = []; + if (!empty($addr->getStreet())) { + $lines[0] = $addr->getStreet(); + } + if (!empty($addr->getStreetNumber())) { + $lines[0] .= ", ".$addr->getStreetNumber(); + } + if (!empty($addr->getPostcode())) { + $lines[1] = \strtr("{postcode} {label}", [ + '{postcode}' => $addr->getPostcode()->getCode(), + '{label}' => $addr->getPostcode()->getName() + ]); + } + + return implode(" - ", $lines); + } + + /** + * {@inheritDoc} + * @param Address addr + */ + public function renderBox($addr, array $options): string + { + $options = \array_merge(self::DEFAULT_OPTIONS, $options); + + return $this->templating + ->render('@ChillMain/Address/entity_render.html.twig', [ + 'address' => $addr, + 'options' => $options + ]); + } +} diff --git a/src/Bundle/ChillMainBundle/Tests/Templating/Entity/AddressRenderTest.php b/src/Bundle/ChillMainBundle/Tests/Templating/Entity/AddressRenderTest.php new file mode 100644 index 000000000..79551d23c --- /dev/null +++ b/src/Bundle/ChillMainBundle/Tests/Templating/Entity/AddressRenderTest.php @@ -0,0 +1,55 @@ +get(EngineInterface::class); + $renderer = new AddressRender($engine); + + $this->assertEquals($expectedString, $renderer->renderString($addr, [])); + return; + $this->assertIsString($renderer->renderBox($addr, [])); + } + + + public function addressDataProvider(): \Iterator + { + $addr = new Address(); + $country = (new Country()) + ->setName([ "fr" => "Pays" ]) + ->setCountryCode("BE") + ; + $postCode = new PostalCode(); + $postCode->setName("Locality") + ->setCode("012345") + ->setCountry($country) + ; + + $addr->setStreet("Rue ABC") + ->setStreetNumber("5") + ->setPostcode($postCode) + ; + + yield[ $addr, "Rue ABC, 5 - 012345 Locality"]; + } + +} diff --git a/src/Bundle/ChillMainBundle/config/services/templating.yaml b/src/Bundle/ChillMainBundle/config/services/templating.yaml index 29dc676d1..9d103f690 100644 --- a/src/Bundle/ChillMainBundle/config/services/templating.yaml +++ b/src/Bundle/ChillMainBundle/config/services/templating.yaml @@ -41,3 +41,10 @@ services: Chill\MainBundle\Templating\ChillMarkdownRenderExtension: tags: - { name: twig.extension } + + Chill\MainBundle\Templating\Entity\AddressRender: + arguments: + - '@Symfony\Component\Templating\EngineInterface' + tags: + - { name: 'chill.render_entity' } + diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php index 8ec017c07..d5b43446c 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php @@ -22,25 +22,34 @@ namespace Chill\PersonBundle\Entity; +use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface; +use Chill\MainBundle\Doctrine\Model\TrackCreationInterface; use Chill\MainBundle\Entity\Scope; use Chill\PersonBundle\Entity\AccompanyingPeriod\ClosingMotive; use Chill\PersonBundle\Entity\AccompanyingPeriod\Comment; use Chill\PersonBundle\Entity\AccompanyingPeriod\Origin; use Chill\PersonBundle\Entity\AccompanyingPeriod\Resource; +use Chill\PersonBundle\Entity\SocialWork\SocialIssue; use Chill\ThirdPartyBundle\Entity\ThirdParty; +use DateTimeInterface; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Validator\Context\ExecutionContextInterface; use Chill\MainBundle\Entity\User; +use Symfony\Component\Serializer\Annotation\Groups; +use Symfony\Component\Serializer\Annotation\DiscriminatorMap; /** * AccompanyingPeriod Class * * @ORM\Entity * @ORM\Table(name="chill_person_accompanying_period") + * @DiscriminatorMap(typeProperty="type", mapping={ + * "accompanying_period"=AccompanyingPeriod::class + * }) */ -class AccompanyingPeriod +class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface { /** * Mark an accompanying period as "occasional" @@ -80,6 +89,7 @@ class AccompanyingPeriod * @ORM\Id * @ORM\Column(name="id", type="integer") * @ORM\GeneratedValue(strategy="AUTO") + * @Groups({"read"}) */ private $id; @@ -87,6 +97,7 @@ class AccompanyingPeriod * @var \DateTime * * @ORM\Column(type="date") + * @Groups({"read", "write"}) */ private $openingDate; @@ -94,6 +105,7 @@ class AccompanyingPeriod * @var \DateTime * * @ORM\Column(type="date", nullable=true) + * @Groups({"read", "write"}) */ private $closingDate = null; @@ -101,6 +113,7 @@ class AccompanyingPeriod * @var string * * @ORM\Column(type="text") + * @Groups({"read", "write"}) */ private $remark = ''; @@ -108,17 +121,28 @@ class AccompanyingPeriod * @var Collection * * @ORM\OneToMany(targetEntity="Chill\PersonBundle\Entity\AccompanyingPeriod\Comment", - * mappedBy="accompanyingPeriod" + * mappedBy="accompanyingPeriod", + * cascade={"persist", "remove"}, + * orphanRemoval=true * ) */ private $comments; + /** + * @ORM\ManyToOne( + * targetEntity=Comment::class + * ) + * @Groups({"read"}) + */ + private ?Comment $initialComment = null; + /** * @var Collection * * @ORM\OneToMany(targetEntity=AccompanyingPeriodParticipation::class, * mappedBy="accompanyingPeriod", * cascade={"persist", "refresh", "remove", "merge", "detach"}) + * @Groups({"read"}) */ private $participations; @@ -128,36 +152,42 @@ class AccompanyingPeriod * @ORM\ManyToOne( * targetEntity="Chill\PersonBundle\Entity\AccompanyingPeriod\ClosingMotive") * @ORM\JoinColumn(nullable=true) + * @Groups({"read", "write"}) */ private $closingMotive = null; /** * @ORM\ManyToOne(targetEntity=User::class) * @ORM\JoinColumn(nullable=true) + * @Groups({"read", "write"}) */ private $user; /** * @ORM\ManyToOne(targetEntity=User::class) * @ORM\JoinColumn(nullable=true) + * @Groups({"read"}) */ private $createdBy; /** * @var string * @ORM\Column(type="string", length=32, nullable=true) + * @Groups({"read"}) */ private $step = self::STEP_DRAFT; /** * @ORM\ManyToOne(targetEntity=Origin::class) * @ORM\JoinColumn(nullable=true) + * @Groups({"read", "write"}) */ private $origin; /** * @var string * @ORM\Column(type="string", nullable=true) + * @Groups({"read", "write"}) */ private $intensity; @@ -172,6 +202,7 @@ class AccompanyingPeriod * joinColumns={@ORM\JoinColumn(name="accompanying_period_id", referencedColumnName="id")}, * inverseJoinColumns={@ORM\JoinColumn(name="scope_id", referencedColumnName="id")} * ) + * @Groups({"read"}) */ private $scopes; @@ -189,19 +220,22 @@ class AccompanyingPeriod /** * @var bool - * @ORM\Column(type="boolean") + * @ORM\Column(type="boolean", options={"default": false} ) + * @Groups({"read", "write"}) */ private $requestorAnonymous = false; /** * @var bool - * @ORM\Column(type="boolean") + * @ORM\Column(type="boolean", options={"default": false} ) + * @Groups({"read", "write"}) */ private $emergency = false; /** * @var bool - * @ORM\Column(type="boolean") + * @ORM\Column(type="boolean", options={"default": false} ) + * @Groups({"read", "write"}) */ private $confidential = false; @@ -210,21 +244,54 @@ class AccompanyingPeriod * * @ORM\OneToMany( * targetEntity="Chill\PersonBundle\Entity\AccompanyingPeriod\Resource", - * mappedBy="accompanyingPeriod" + * mappedBy="accompanyingPeriod", + * cascade={"persist", "remove"}, + * orphanRemoval=true * ) + * @Groups({"read"}) */ private $resources; + /** + * @ORM\ManyToMany( + * targetEntity=SocialIssue::class + * ) + * @ORM\JoinTable( + * name="chill_person_accompanying_period_social_issues" + * ) + * @Groups({"read"}) + */ + private Collection $socialIssues; + + /** + * @ORM\Column(type="datetime", nullable=true, options={"default": NULL}) + */ + private \DateTimeInterface $createdAt; + + /** + * @ORM\ManyToOne( + * targetEntity=User::class + * ) + */ + private User $updatedBy; + + /** + * @ORM\Column(type="datetime", nullable=true, options={"default": NULL}) + */ + private \DateTimeInterface $updatedAt; + /** * AccompanyingPeriod constructor. * * @param \DateTime $dateOpening * @uses AccompanyingPeriod::setClosingDate() */ - public function __construct(\DateTime $dateOpening) { - $this->setOpeningDate($dateOpening); + public function __construct(\DateTime $dateOpening = null) { + $this->setOpeningDate($dateOpening ?? new \DateTime('now')); $this->participations = new ArrayCollection(); $this->scopes = new ArrayCollection(); + $this->socialIssues = new ArrayCollection(); + $this->comments = new ArrayCollection(); } /** @@ -318,23 +385,55 @@ class AccompanyingPeriod return $this->remark; } + /** + * @Groups({"read"}) + */ public function getComments(): Collection { - return $this->comments; + return $this->comments->filter(function (Comment $c) { + return $c !== $this->initialComment; + }); } public function addComment(Comment $comment): self { $this->comments[] = $comment; + $comment->setAccompanyingPeriod($this); return $this; } public function removeComment(Comment $comment): void { + $comment->setAccompanyingPeriod(null); $this->comments->removeElement($comment); } + /** + * @Groups({"write"}) + */ + public function setInitialComment(?Comment $comment = null): self + { + if (NULL !== $this->initialComment) { + $this->removeComment($this->initialComment); + } + if ($comment instanceof Comment) { + $this->addComment($comment); + } + + $this->initialComment = $comment; + + return $this; + } + + /** + * @Groups({"read"}) + */ + public function getInitialComment(): ?Comment + { + return $this->initialComment; + } + /** * Get Participations Collection */ @@ -515,9 +614,9 @@ class AccompanyingPeriod return $this->requestorPerson; } - public function setRequestorPerson(Person $requestorPerson): self + private function setRequestorPerson(Person $requestorPerson = null): self { - $this->requestorPerson = ($this->requestorThirdParty === null) ? $requestorPerson : null; + $this->requestorPerson = $requestorPerson; return $this; } @@ -527,21 +626,53 @@ class AccompanyingPeriod return $this->requestorThirdParty; } - public function setRequestorThirdParty(ThirdParty $requestorThirdParty): self + private function setRequestorThirdParty(ThirdParty $requestorThirdParty = null): self { - $this->requestorThirdParty = ($this->requestorPerson === null) ? $requestorThirdParty : null; + $this->requestorThirdParty = $requestorThirdParty; return $this; } /** * @return Person|ThirdParty + * @Groups({"read"}) */ public function getRequestor() { return $this->requestorPerson ?? $this->requestorThirdParty; } + + /** + * Set a requestor + * + * The requestor is either an instance of ThirdParty, or an + * instance of Person + * + * @param $requestor Person|ThirdParty + * @return self + * @throw UnexpectedValueException if the requestor is not a Person or ThirdParty + * @Groups({"write"}) + */ + public function setRequestor($requestor): self + { + if ($requestor instanceof Person) { + $this->setRequestorThirdParty(NULL); + $this->setRequestorPerson($requestor); + } elseif ($requestor instanceof ThirdParty) { + $this->setRequestorThirdParty($requestor); + $this->setRequestorPerson(NULL); + } elseif (NULL === $requestor) { + $this->setRequestorPerson(NULL); + $this->setRequestorThirdParty(NULL); + } else { + throw new \UnexpectedValueException("requestor is not an instance of Person or ThirdParty"); + } + + return $this; + } + + public function isRequestorAnonymous(): bool { return $this->requestorAnonymous; @@ -638,6 +769,7 @@ class AccompanyingPeriod public function addResource(Resource $resource): self { + $resource->setAccompanyingPeriod($this); $this->resources[] = $resource; return $this; @@ -645,9 +777,27 @@ class AccompanyingPeriod public function removeResource(Resource $resource): void { + $resource->setAccompanyingPeriod(null); $this->resources->removeElement($resource); } + public function getSocialIssues(): Collection + { + return $this->socialIssues; + } + + public function addSocialIssue(SocialIssue $socialIssue): self + { + $this->socialIssues[] = $socialIssue; + + return $this; + } + + public function removeSocialIssue(SocialIssue $socialIssue): void + { + $this->socialIssues->removeElement($socialIssue); + } + /** * Get a list of all persons which are participating to this course */ @@ -659,4 +809,25 @@ class AccompanyingPeriod } ); } + + public function setCreatedAt(\DateTimeInterface $datetime): self + { + $this->createdAt = $datetime; + + return $this; + } + + public function setUpdatedBy(User $user): self + { + $this->updatedBy = $user; + + return $this; + } + + public function setUpdatedAt(\DateTimeInterface $datetime): self + { + $this->updatedAt = $datetime; + + return $this; + } } diff --git a/src/Bundle/ChillPersonBundle/Entity/Person.php b/src/Bundle/ChillPersonBundle/Entity/Person.php index e88998205..a469c65d2 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Person.php +++ b/src/Bundle/ChillPersonBundle/Entity/Person.php @@ -417,6 +417,31 @@ class Person implements HasCenterInterface return $this->accompanyingPeriodParticipations; } + /** + * Return a collection of participation, where the participation + * is still opened, not a draft, and the period is still opened + */ + public function getOpenedParticipations(): Collection + { + // create a criteria for filtering easily + $criteria = Criteria::create(); + $criteria + ->andWhere(Criteria::expr()->eq('endDate', NULL)) + ->orWhere(Criteria::expr()->gt('endDate', new \DateTime('now'))) + ; + + return $this->getAccompanyingPeriodParticipations() + ->matching($criteria) + ->filter(function (AccompanyingPeriodParticipation $app) { + $period = $app->getAccompanyingPeriod(); + return ( + NULL === $period->getClosingDate() + || new \DateTime('now') < $period->getClosingDate() + ) + && AccompanyingPeriod::STEP_DRAFT !== $period->getStep(); + }); + } + /** * Get the accompanying periods of a give person with the chronological order. */ diff --git a/src/Bundle/ChillPersonBundle/Resources/public/index.js b/src/Bundle/ChillPersonBundle/Resources/public/index.js index f4bcba7fb..e3563b4ff 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/index.js +++ b/src/Bundle/ChillPersonBundle/Resources/public/index.js @@ -1 +1,2 @@ -require('./sass/person.scss'); \ No newline at end of file +require('./sass/person.scss'); +require('./sass/person_with_period.scss'); diff --git a/src/Bundle/ChillPersonBundle/Resources/public/sass/index.js b/src/Bundle/ChillPersonBundle/Resources/public/sass/index.js index 35945c7ff..89e749e5c 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/sass/index.js +++ b/src/Bundle/ChillPersonBundle/Resources/public/sass/index.js @@ -1,5 +1,5 @@ require('./phone-alt-solid.svg'); require('./mobile-alt-solid.svg'); require('./person_by_phonenumber.scss'); - +require('./person_with_period.scss'); diff --git a/src/Bundle/ChillPersonBundle/Resources/public/sass/person_with_period.scss b/src/Bundle/ChillPersonBundle/Resources/public/sass/person_with_period.scss new file mode 100644 index 000000000..46422d994 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Resources/public/sass/person_with_period.scss @@ -0,0 +1,50 @@ +.person-list--with-period { + .person-list--with-period__item { + margin-bottom: 0; + padding: 1em 1em 2em 1em; + &:nth-last-of-type { + padding-bottom: 1em; + } + + &:nth-of-type(odd) { + //background-color: var(--chill-light-gray); + } + &:nth-of-type(even) { + //background-color: var(--chill-dark-gray); + } + + .chill-entity__person { + .chill-entity__person__first-name, + .chill-entity__person__last-name { + font-size: 1.3em; + font-weight: 700; + } + } + + & > div { + display: flex; + flex-direction: row; + + .person-list--with-period__item__box-where { + align-self: flex-end; + margin-left: auto; + width: 33%; + + text-align: right; + } + } + + ul.person-list--with-period__item__periods { + list-style-type: none; + padding: 0; + margin: 0; + + li { + + } + } + } + .person-list--with-period__item:hover { + background-color: var(--chill-llight-gray); + } +} diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig new file mode 100644 index 000000000..afcd2799c --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig @@ -0,0 +1,15 @@ + + {%- if addLink and is_granted('CHILL_PERSON_SEE', person) -%} + {%- set showLink = true -%}{%- endif -%} + {{ person.firstName }} + {{ person.lastName }} + {%- if addAltNames -%} + {%- for n in person.altNames -%} + {%- if loop.first -%}({% else %} {%- endif -%} + + {{ n.label }} + + {%- if loop.last %}) {% endif -%} + {%- endfor -%} + {%- endif -%} + {%- if showLink is defined -%}{%- endif -%} diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Entity/social_issue.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Entity/social_issue.html.twig new file mode 100644 index 000000000..eeb3c4712 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Resources/views/Entity/social_issue.html.twig @@ -0,0 +1,3 @@ + + + diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Person/list_with_period.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Person/list_with_period.html.twig new file mode 100644 index 000000000..ce5ee2beb --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Resources/views/Person/list_with_period.html.twig @@ -0,0 +1,208 @@ +

{{ title|default('Person search results')|trans }}

+ +

+ {{ '%total% persons matching the search pattern:'|transchoice( total, { '%total%' : total}) }} + + {{ pattern }} + +

+ +

{{ 'Results %start%-%end% of %total%'|trans({ '%start%' : start, '%end%': start + persons|length, '%total%' : total } ) }}

+ + + + +{% if persons|length > 0 %} + +
+ {% for person in persons %} +
+
+
+
+ {{ person|chill_entity_render_box({'addLink': true}) }} + {{ person.birthdate|format_date("medium") }} +
+ +
+
+ {{ person.center }} + {% if person.getLastAddress is not null %} + {{ person.getLastAddress|chill_entity_render_box({'with_valid_from': false}) }} + {% else %} + {{ 'No address'|trans }} + {% endif %} + {% if person.mobilenumber is not empty %} + {{ person.mobilenumber }} + {% endif %} + {% if person.phonenumber is not empty %} + {{ person.phonenumber }} + {% endif %} + +
+
+ + {#- 'apps' is for AccompanyingPeriodParticipationS #} + {#- filter using acl -#} + {%- set apps = [] %} + {%- for app in person.openedParticipations %} + {%- if is_granted('CHILL_PERSON_ACCOMPANYING_PERIOD_SEE', app.accompanyingPeriod) %} + {%- set apps = apps|merge([app]) %} + {%- endif %} + {%- endfor %} + {% if apps|length > 0 %} + + {% endif %} + +
+ {% endfor %} +
+ + {# + + + + + + + + + + + {% for person in persons %} + + + + + + + {% endfor %} + +
{% trans %}Name{% endtrans %}{% trans %}Date of birth{% endtrans %}{% trans %}Nationality{% endtrans %} 
+ {% set is_open = person.isOpen() %} + + {{ person|chill_entity_render_box }} + {% apply spaceless %} + {% if chill_person.fields.accompanying_period == 'visible' %} + {% if is_open == false %} + + {% else %} + + {% endif %} + {% endif %} + {% endapply %} + + + {% if person.birthdate is not null %} + {{ person.birthdate|format_date('long') }} + {% else %}{{ 'Unknown date of birth'|trans }}{% endif %} + + {% if person.nationality is not null %} + {{person.nationality.name | localize_translatable_string }} + {% else %} + {{ 'Without nationality'|trans }} + {% endif %} + +
    +
  • + {% if is_granted('CHILL_PERSON_UPDATE', person) %} +
  • + {% endif %} +
+
+ + #} + + +{% else %} + +{% endif %} + +{% if preview == false %} +{{ chill_pagination(paginator) }} +{% endif %} + diff --git a/src/Bundle/ChillPersonBundle/Search/PersonSearch.php b/src/Bundle/ChillPersonBundle/Search/PersonSearch.php index 34f79bb87..fe938999a 100644 --- a/src/Bundle/ChillPersonBundle/Search/PersonSearch.php +++ b/src/Bundle/ChillPersonBundle/Search/PersonSearch.php @@ -120,7 +120,7 @@ class PersonSearch extends AbstractSearch implements ContainerAwareInterface, $paginator = $this->paginatorFactory->create($total); if ($format === 'html') { - return $this->container->get('templating')->render('ChillPersonBundle:Person:list.html.twig', + return $this->container->get('templating')->render('@ChillPerson/Person/list_with_period.html.twig', array( 'persons' => $this->search($terms, $start, $limit, $options), 'pattern' => $this->recomposePattern($terms, array('nationality', diff --git a/src/Bundle/ChillPersonBundle/Templating/Entity/SocialIssueRender.php b/src/Bundle/ChillPersonBundle/Templating/Entity/SocialIssueRender.php new file mode 100644 index 000000000..f7b0da53c --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Templating/Entity/SocialIssueRender.php @@ -0,0 +1,50 @@ + ' > ', + ]; + + public function __construct(TranslatableStringHelper $translatableStringHelper) + { + $this->translatableStringHelper = $translatableStringHelper; + } + + public function supports($entity, array $options): bool + { + return $entity instanceof SocialIssue; + } + + public function renderString($socialIssue, array $options): string + { + /** @var $socialIssue SocialIssue */ + $options = \array_merge(self::DEFAULT_ARGS, $options); + + $str = $this->translatableStringHelper->localize($socialIssue->getTitle()); + + while ($socialIssue->hasParent()) { + $socialIssue = $socialIssue->getParent(); + $str .= $options[self::SEPARATOR_KEY].$this->translatableStringHelper->localize( + $socialIssue->getTitle() + ); + } + + return $str; + } + + public function renderBox($entity, array $options): string + { + return "renderBox not implemented for social issue"; + } +} diff --git a/src/Bundle/ChillPersonBundle/config/services/templating.yaml b/src/Bundle/ChillPersonBundle/config/services/templating.yaml index 3456c96de..5715f344c 100644 --- a/src/Bundle/ChillPersonBundle/config/services/templating.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/templating.yaml @@ -1,12 +1,21 @@ services: + Chill\PersonBundle\Templating\Entity\: + resource: '../../Templating/Entity' + tags: + - 'chill.render_entity' + Chill\PersonBundle\Templating\Entity\PersonRender: arguments: $configAltNamesHelper: '@Chill\PersonBundle\Config\ConfigPersonAltNamesHelper' tags: - 'chill.render_entity' - + Chill\PersonBundle\Templating\Entity\ClosingMotiveRender: arguments: $translatableStringHelper: '@Chill\MainBundle\Templating\TranslatableStringHelper' + + Chill\PersonBundle\Templating\Entity\SocialIssueRender: + arguments: + $translatableStringHelper: '@Chill\MainBundle\Templating\TranslatableStringHelper' tags: - 'chill.render_entity'