From 9d8e49f39b4a9c6b650885de8b8aa4455089655e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 5 Dec 2019 22:57:33 +0100 Subject: [PATCH] create render entity for person --- DependencyInjection/ChillPersonExtension.php | 1 + Resources/config/services/templating.yml | 4 ++ Templating/Entity/PersonRender.php | 63 ++++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 Resources/config/services/templating.yml create mode 100644 Templating/Entity/PersonRender.php diff --git a/DependencyInjection/ChillPersonExtension.php b/DependencyInjection/ChillPersonExtension.php index cdf707f1d..ab87fe4ae 100644 --- a/DependencyInjection/ChillPersonExtension.php +++ b/DependencyInjection/ChillPersonExtension.php @@ -64,6 +64,7 @@ class ChillPersonExtension extends Extension implements PrependExtensionInterfac $loader->load('services/actions.yml'); $loader->load('services/form.yml'); $loader->load('services/repository.yml'); + $loader->load('services/templating.yml'); // load service advanced search only if configure if ($config['search']['search_by_phone'] != 'never') { diff --git a/Resources/config/services/templating.yml b/Resources/config/services/templating.yml new file mode 100644 index 000000000..395c3e9f3 --- /dev/null +++ b/Resources/config/services/templating.yml @@ -0,0 +1,4 @@ +services: + Chill\PersonBundle\Templating\Entity\PersonRender: + tags: + - 'chill.render_entity' diff --git a/Templating/Entity/PersonRender.php b/Templating/Entity/PersonRender.php new file mode 100644 index 000000000..42bdfb6a9 --- /dev/null +++ b/Templating/Entity/PersonRender.php @@ -0,0 +1,63 @@ + + * + * 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\PersonBundle\Templating\Entity; + +use Chill\MainBundle\Templating\Entity\AbstractChillEntityRender; +use Chill\PersonBundle\Entity\Person; + +/** + * Render a Person + * + */ +class PersonRender extends AbstractChillEntityRender +{ + /** + * + * @param Person $person + * @param array $options + * @return string + */ + public function renderBox($person, array $options): string + { + return + $this->getDefaultOpeningBox('person'). + ''.$person->getFirstName().''. + ''.$person->getLastName().''. + $this->getDefaultClosingBox() + ; + } + + /** + * + * @param Person $person + * @param array $options + * @return string + */ + public function renderString($person, array $options): string + { + return $person->getFirstName().' '.$person->getLastName(); + } + + public function supports($entity, array $options): bool + { + return $entity instanceof Person; + } +}