mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
add a render template for entity ThirdParty
This commit is contained in:
parent
5bc1a1a7b2
commit
b761c8a21d
@ -3,4 +3,4 @@ branch master
|
||||
=============
|
||||
|
||||
* initial commit
|
||||
|
||||
* add a render template for entity ThirdParty ;
|
||||
|
@ -72,7 +72,7 @@ class ThirdParty
|
||||
* @var string|null
|
||||
*
|
||||
* @ORM\Column(name="email", type="string", length=255, nullable=true)
|
||||
* @Assert\Email(checkMX=true)
|
||||
* @Assert\Email(checkMX=false)
|
||||
*/
|
||||
private $email;
|
||||
|
||||
|
@ -4,4 +4,5 @@ imports:
|
||||
- { resource: './services/security.yml' }
|
||||
- { resource: './services/3partytype.yml' }
|
||||
- { resource: './services/search.yml' }
|
||||
- { resource: './services/templating.yml' }
|
||||
- { resource: './services/menu.yml' }
|
||||
|
6
Resources/config/services/templating.yml
Normal file
6
Resources/config/services/templating.yml
Normal file
@ -0,0 +1,6 @@
|
||||
services:
|
||||
Chill\ThirdPartyBundle\Templating\Entity\ThirdPartyRender:
|
||||
arguments:
|
||||
$templating: '@templating.engine.twig'
|
||||
tags:
|
||||
- 'chill.render_entity'
|
@ -1,49 +1,5 @@
|
||||
{%- macro _render(contact, options) -%}
|
||||
{%- set options = { 'with_valid_from' : true }|merge(options|default({})) -%}
|
||||
<div class="chill_contact">
|
||||
|
||||
<div class="chill_contact_name">
|
||||
{{ contact.name }}
|
||||
</div>
|
||||
<div class="chill_contact_category">
|
||||
{% for type in contact.type %}
|
||||
<span class="category">
|
||||
{{ ('chill_3party.key_label.'~type)|trans }}
|
||||
</span>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% if contact.comment is not empty %}
|
||||
<div class="chill_contact_comment">
|
||||
{{ contact.comment }}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if contact.address %}
|
||||
<div class="chill_address">
|
||||
<div class="chill_address_address">
|
||||
|
||||
{% if contact.address.streetAddress1 %}<p class="street street1">{{ contact.address.streetAddress1 }}</p>{% endif %}
|
||||
{% if contact.address.streetAddress2 is not empty %}<p class="street street2">{{ contact.address.streetAddress2 }}</p>{% endif %}
|
||||
{% if contact.address.postCode is not empty %}
|
||||
<p class="postalCode"><span class="code">{{ contact.address.postCode.code }}</span> <span class="name">{{ contact.address.postCode.name }}</span></p>
|
||||
<p class="country">{{ contact.address.postCode.country.name|localize_translatable_string }}</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
{%- if options['with_valid_from'] == true -%}
|
||||
<span class="address_since">{{ 'Since %date%'|trans( { '%date%' : contact.address.validFrom|localizeddate('long', 'none') } ) }}</span>
|
||||
{%- endif -%}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if contact.email or contact.telephone is not empty %}
|
||||
<div class="chill_contact_contact">
|
||||
<span class="email">
|
||||
{{ contact.email }}
|
||||
</span>
|
||||
<span class="telephone">
|
||||
{{ contact.telephone }}
|
||||
</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{{ contact|chill_entity_render_box(options|default({})) }}
|
||||
{%- endmacro -%}
|
||||
|
||||
|
||||
|
45
Resources/views/ThirdParty/_render.html.twig
vendored
Normal file
45
Resources/views/ThirdParty/_render.html.twig
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
{# template to render a person #}
|
||||
<div class="chill_contact">
|
||||
|
||||
<div class="chill_contact_name">
|
||||
{{ contact.name }}
|
||||
</div>
|
||||
<div class="chill_contact_category">
|
||||
{% for type in contact.type %}
|
||||
<span class="category">
|
||||
{{ ('chill_3party.key_label.'~type)|trans }}
|
||||
</span>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% if contact.comment is not empty %}
|
||||
<div class="chill_contact_comment">
|
||||
{{ contact.comment }}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if contact.address %}
|
||||
<div class="chill_address">
|
||||
<div class="chill_address_address">
|
||||
|
||||
{% if contact.address.streetAddress1 %}<p class="street street1">{{ contact.address.streetAddress1 }}</p>{% endif %}
|
||||
{% if contact.address.streetAddress2 is not empty %}<p class="street street2">{{ contact.address.streetAddress2 }}</p>{% endif %}
|
||||
{% if contact.address.postCode is not empty %}
|
||||
<p class="postalCode"><span class="code">{{ contact.address.postCode.code }}</span> <span class="name">{{ contact.address.postCode.name }}</span></p>
|
||||
<p class="country">{{ contact.address.postCode.country.name|localize_translatable_string }}</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
{%- if options['with_valid_from'] == true -%}
|
||||
<span class="address_since">{{ 'Since %date%'|trans( { '%date%' : contact.address.validFrom|localizeddate('long', 'none') } ) }}</span>
|
||||
{%- endif -%}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if contact.email or contact.telephone is not empty %}
|
||||
<div class="chill_contact_contact">
|
||||
<span class="email">
|
||||
<a href="mailto:{{ contact.email }}">{{ contact.email }}</>
|
||||
</span>
|
||||
<span class="telephone">
|
||||
<a href="tel:{{ contact.telephone }}">{{ contact.telephone|chill_format_phonenumber }}</a>
|
||||
</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
82
Templating/Entity/ThirdPartyRender.php
Normal file
82
Templating/Entity/ThirdPartyRender.php
Normal file
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* Copyright (C) 2014-2020 , Champs Libres Cooperative SCRLFS,
|
||||
* <http://www.champs-libres.coop>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
namespace Chill\ThirdPartyBundle\Templating\Entity;
|
||||
|
||||
use Chill\MainBundle\Templating\Entity\AbstractChillEntityRender;
|
||||
use Chill\ThirdPartyBundle\Entity\ThirdParty;
|
||||
use Symfony\Bridge\Twig\TwigEngine;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
class ThirdPartyRender extends AbstractChillEntityRender
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var TwigEngine
|
||||
*/
|
||||
protected $templating;
|
||||
|
||||
public function __construct(TwigEngine $templating)
|
||||
{
|
||||
$this->templating = $templating;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param ThirdParty $entity
|
||||
* @param array $options
|
||||
* @return string
|
||||
*/
|
||||
public function renderBox($entity, array $options): string
|
||||
{
|
||||
$params = \array_merge(
|
||||
[ 'with_valid_from' => true ],
|
||||
$options
|
||||
);
|
||||
|
||||
return
|
||||
$this->getDefaultOpeningBox('_3party').
|
||||
$this->templating->render('@ChillThirdParty/ThirdParty/_render.html.twig', [
|
||||
'contact' => $entity,
|
||||
'options' => $params
|
||||
]).
|
||||
$this->getDefaultClosingBox();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param ThirdParty $entity
|
||||
* @param array $options
|
||||
* @return string
|
||||
*/
|
||||
public function renderString($entity, array $options): string
|
||||
{
|
||||
return $entity->getName();
|
||||
}
|
||||
|
||||
public function supports($entity, array $options): bool
|
||||
{
|
||||
return $entity instanceof ThirdParty;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user