mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
cs: Fix code style (safe rules only).
This commit is contained in:
@@ -1,75 +1,80 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\PersonBundle\Templating\Entity;
|
||||
|
||||
use Chill\MainBundle\Templating\Entity\AbstractChillEntityRender;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\ClosingMotive;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\ClosingMotive;
|
||||
|
||||
/**
|
||||
* Render closing motive
|
||||
*
|
||||
* Render closing motive.
|
||||
*/
|
||||
class ClosingMotiveRender extends AbstractChillEntityRender
|
||||
{
|
||||
private CONST SEPARATOR = ' > ';
|
||||
|
||||
private const SEPARATOR = ' > ';
|
||||
|
||||
/**
|
||||
*
|
||||
* @var TranslatableStringHelper
|
||||
*/
|
||||
private $translatableStringHelper;
|
||||
|
||||
|
||||
public function __construct(TranslatableStringHelper $translatableStringHelper)
|
||||
{
|
||||
$this->translatableStringHelper = $translatableStringHelper;
|
||||
}
|
||||
|
||||
|
||||
public function renderBox($entity, array $options): string
|
||||
{
|
||||
return
|
||||
$this->getDefaultOpeningBox('closing-motive').
|
||||
$this->renderString($entity, $options).
|
||||
$this->getDefaultClosingBox()
|
||||
;
|
||||
return
|
||||
$this->getDefaultOpeningBox('closing-motive') .
|
||||
$this->renderString($entity, $options) .
|
||||
$this->getDefaultClosingBox();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param ClosingMotive $entity
|
||||
* @param array $options
|
||||
* @return string
|
||||
*/
|
||||
public function renderString($entity, array $options): string
|
||||
{
|
||||
return $this->renderStringRecursive($entity,
|
||||
'', //$this->translatableStringHelper->localize($entity->getName()),
|
||||
$options);
|
||||
}
|
||||
|
||||
protected function renderStringRecursive(ClosingMotive $motive, $existing, array $options)
|
||||
{
|
||||
$newExisting = $this->translatableStringHelper->localize($motive->getName());
|
||||
|
||||
if ($motive->hasParent()) {
|
||||
|
||||
if (!empty($existing)) {
|
||||
$newExisting = $newExisting.self::SEPARATOR.$existing;
|
||||
}
|
||||
|
||||
return $this->renderStringRecursive($motive->getParent(), $newExisting,
|
||||
$options);
|
||||
} else {
|
||||
if (!empty($existing)) {
|
||||
return $newExisting.self::SEPARATOR.$existing;
|
||||
} else {
|
||||
return $newExisting;
|
||||
}
|
||||
}
|
||||
return $this->renderStringRecursive(
|
||||
$entity,
|
||||
'', //$this->translatableStringHelper->localize($entity->getName()),
|
||||
$options
|
||||
);
|
||||
}
|
||||
|
||||
public function supports($entity, array $options): bool
|
||||
{
|
||||
return $entity instanceof ClosingMotive;
|
||||
}
|
||||
|
||||
protected function renderStringRecursive(ClosingMotive $motive, $existing, array $options)
|
||||
{
|
||||
$newExisting = $this->translatableStringHelper->localize($motive->getName());
|
||||
|
||||
if ($motive->hasParent()) {
|
||||
if (!empty($existing)) {
|
||||
$newExisting = $newExisting . self::SEPARATOR . $existing;
|
||||
}
|
||||
|
||||
return $this->renderStringRecursive(
|
||||
$motive->getParent(),
|
||||
$newExisting,
|
||||
$options
|
||||
);
|
||||
}
|
||||
|
||||
if (!empty($existing)) {
|
||||
return $newExisting . self::SEPARATOR . $existing;
|
||||
}
|
||||
|
||||
return $newExisting;
|
||||
}
|
||||
}
|
||||
|
@@ -1,33 +1,22 @@
|
||||
<?php
|
||||
/*
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* Copyright (C) 2014-2019, 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/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\PersonBundle\Templating\Entity;
|
||||
|
||||
use Chill\MainBundle\Templating\Entity\AbstractChillEntityRender;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Config\ConfigPersonAltNamesHelper;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Symfony\Component\Templating\EngineInterface;
|
||||
use function array_key_exists;
|
||||
|
||||
/**
|
||||
* Render a Person
|
||||
*
|
||||
* Render a Person.
|
||||
*/
|
||||
class PersonRender extends AbstractChillEntityRender
|
||||
{
|
||||
@@ -44,10 +33,7 @@ class PersonRender extends AbstractChillEntityRender
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Person $person
|
||||
* @param array $options
|
||||
* @return string
|
||||
*/
|
||||
public function renderBox($person, array $options): string
|
||||
{
|
||||
@@ -70,21 +56,23 @@ class PersonRender extends AbstractChillEntityRender
|
||||
$this->engine->render('@ChillPerson/Entity/person.html.twig', [
|
||||
'person' => $person,
|
||||
'render' => $options['render'] ?? 'raw',
|
||||
'options' => $params
|
||||
'options' => $params,
|
||||
]) .
|
||||
$this->getDefaultClosingBox();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Person $person
|
||||
* @param array $options
|
||||
* @return string
|
||||
*/
|
||||
public function renderString($person, array $options): string
|
||||
{
|
||||
return $person->getFirstName().' '.$person->getLastName()
|
||||
.$this->addAltNames($person, false);
|
||||
return $person->getFirstName() . ' ' . $person->getLastName()
|
||||
. $this->addAltNames($person, false);
|
||||
}
|
||||
|
||||
public function supports($entity, array $options): bool
|
||||
{
|
||||
return $entity instanceof Person;
|
||||
}
|
||||
|
||||
protected function addAltNames(Person $person, bool $addSpan): string
|
||||
@@ -97,34 +85,30 @@ class PersonRender extends AbstractChillEntityRender
|
||||
|
||||
foreach ($person->getAltNames()->getIterator() as $altName) {
|
||||
/** @var \Chill\PersonBundle\Entity\PersonAltName $altName */
|
||||
if (\array_key_exists($altName->getKey(), $altNames)) {
|
||||
if (array_key_exists($altName->getKey(), $altNames)) {
|
||||
if ($isFirst) {
|
||||
$str .= " (";
|
||||
$str .= ' (';
|
||||
$isFirst = false;
|
||||
} else {
|
||||
$str.= " ";
|
||||
$str .= ' ';
|
||||
}
|
||||
|
||||
if ($addSpan) {
|
||||
$str .= '<span class="altname altname-'.$altName->getKey().'">';
|
||||
$str .= '<span class="altname altname-' . $altName->getKey() . '">';
|
||||
}
|
||||
$str .= $altName->getLabel();
|
||||
|
||||
if ($addSpan) {
|
||||
$str .= "</span>";
|
||||
$str .= '</span>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$isFirst) {
|
||||
$str .= ")";
|
||||
$str .= ')';
|
||||
}
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
public function supports($entity, array $options): bool
|
||||
{
|
||||
return $entity instanceof Person;
|
||||
}
|
||||
}
|
||||
|
@@ -1,27 +1,39 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\PersonBundle\Templating\Entity;
|
||||
|
||||
use Chill\MainBundle\Templating\Entity\ChillEntityRenderInterface;
|
||||
use Chill\PersonBundle\Entity\SocialWork\SocialAction;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Chill\PersonBundle\Entity\SocialWork\SocialAction;
|
||||
use Symfony\Component\Templating\EngineInterface;
|
||||
use function array_merge;
|
||||
use function array_reverse;
|
||||
use function implode;
|
||||
|
||||
class SocialActionRender implements ChillEntityRenderInterface
|
||||
{
|
||||
private TranslatableStringHelper $translatableStringHelper;
|
||||
private EngineInterface $engine;
|
||||
|
||||
public const SEPARATOR_KEY = 'default.separator';
|
||||
/**
|
||||
* if true, the action will not be encapsulated into a "badge"
|
||||
*/
|
||||
public const NO_BADGE = 'no-badge';
|
||||
|
||||
public const DEFAULT_ARGS = [
|
||||
self::SEPARATOR_KEY => ' > ',
|
||||
self::NO_BADGE => false,
|
||||
];
|
||||
];
|
||||
|
||||
/**
|
||||
* if true, the action will not be encapsulated into a "badge".
|
||||
*/
|
||||
public const NO_BADGE = 'no-badge';
|
||||
|
||||
public const SEPARATOR_KEY = 'default.separator';
|
||||
|
||||
private EngineInterface $engine;
|
||||
|
||||
private TranslatableStringHelper $translatableStringHelper;
|
||||
|
||||
public function __construct(TranslatableStringHelper $translatableStringHelper, EngineInterface $engine)
|
||||
{
|
||||
@@ -29,15 +41,23 @@ class SocialActionRender implements ChillEntityRenderInterface
|
||||
$this->engine = $engine;
|
||||
}
|
||||
|
||||
public function supports($entity, array $options): bool
|
||||
public function renderBox($socialAction, array $options): string
|
||||
{
|
||||
return $entity instanceof SocialAction;
|
||||
$options = array_merge(self::DEFAULT_ARGS, $options);
|
||||
// give some help to twig: an array of parents
|
||||
$parents = $this->buildParents($socialAction);
|
||||
|
||||
return $this->engine->render('@ChillPerson/Entity/social_action.html.twig', [
|
||||
'socialAction' => $socialAction,
|
||||
'parents' => $parents,
|
||||
'options' => $options,
|
||||
]);
|
||||
}
|
||||
|
||||
public function renderString($socialAction, array $options): string
|
||||
{
|
||||
/** @var $socialAction SocialAction */
|
||||
$options = \array_merge(self::DEFAULT_ARGS, $options);
|
||||
/** @var SocialAction $socialAction */
|
||||
$options = array_merge(self::DEFAULT_ARGS, $options);
|
||||
$titles = [$this->translatableStringHelper->localize($socialAction->getTitle())];
|
||||
|
||||
while ($socialAction->hasParent()) {
|
||||
@@ -47,31 +67,24 @@ class SocialActionRender implements ChillEntityRenderInterface
|
||||
);
|
||||
}
|
||||
|
||||
$titles = \array_reverse($titles);
|
||||
$titles = array_reverse($titles);
|
||||
|
||||
return \implode($options[self::SEPARATOR_KEY], $titles);
|
||||
return implode($options[self::SEPARATOR_KEY], $titles);
|
||||
}
|
||||
|
||||
public function supports($entity, array $options): bool
|
||||
{
|
||||
return $entity instanceof SocialAction;
|
||||
}
|
||||
|
||||
protected function buildParents($socialAction): array
|
||||
{
|
||||
$parents = [];
|
||||
|
||||
while ($socialAction->hasParent()) {
|
||||
$socialAction = $parents[] = $socialAction->getParent();
|
||||
}
|
||||
|
||||
return $parents;
|
||||
}
|
||||
|
||||
public function renderBox($socialAction, array $options): string
|
||||
{
|
||||
$options = \array_merge(self::DEFAULT_ARGS, $options);
|
||||
// give some help to twig: an array of parents
|
||||
$parents = $this->buildParents($socialAction);
|
||||
|
||||
return $this->engine->render('@ChillPerson/Entity/social_action.html.twig', [
|
||||
'socialAction' => $socialAction,
|
||||
'parents' => $parents,
|
||||
'options' => $options
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@@ -1,23 +1,32 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\PersonBundle\Templating\Entity;
|
||||
|
||||
use Chill\MainBundle\Templating\Entity\ChillEntityRenderInterface;
|
||||
use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use RuntimeException;
|
||||
use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
|
||||
use Symfony\Component\Templating\EngineInterface;
|
||||
use function array_reverse;
|
||||
use function implode;
|
||||
|
||||
final class SocialIssueRender implements ChillEntityRenderInterface
|
||||
{
|
||||
private TranslatableStringHelper $translatableStringHelper;
|
||||
private EngineInterface $engine;
|
||||
public const DEFAULT_ARGS = [
|
||||
self::SEPARATOR_KEY => ' > ',
|
||||
];
|
||||
|
||||
public const SEPARATOR_KEY = 'default.separator';
|
||||
|
||||
public const DEFAULT_ARGS = [
|
||||
self::SEPARATOR_KEY => ' > ',
|
||||
];
|
||||
private EngineInterface $engine;
|
||||
|
||||
private TranslatableStringHelper $translatableStringHelper;
|
||||
|
||||
public function __construct(TranslatableStringHelper $translatableStringHelper, EngineInterface $engine)
|
||||
{
|
||||
@@ -25,49 +34,9 @@ final class SocialIssueRender implements ChillEntityRenderInterface
|
||||
$this->engine = $engine;
|
||||
}
|
||||
|
||||
public function supports($entity, array $options): bool
|
||||
{
|
||||
return $entity instanceof SocialIssue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SocialIssue $socialIssue
|
||||
*/
|
||||
public function renderString($socialIssue, array $options): string
|
||||
{
|
||||
/** @var $socialIssue SocialIssue */
|
||||
$options = array_merge(self::DEFAULT_ARGS, $options);
|
||||
|
||||
$titles = [$this->translatableStringHelper->localize($socialIssue->getTitle())];
|
||||
|
||||
// loop to parent, until root
|
||||
while ($socialIssue->hasParent()) {
|
||||
$socialIssue = $socialIssue->getParent();
|
||||
$titles[] = $this->translatableStringHelper->localize(
|
||||
$socialIssue->getTitle()
|
||||
);
|
||||
}
|
||||
|
||||
$titles = \array_reverse($titles);
|
||||
|
||||
return \implode($options[self::SEPARATOR_KEY], $titles);
|
||||
}
|
||||
|
||||
protected function buildParents(SocialIssue $socialIssue): array
|
||||
{
|
||||
$parents = [];
|
||||
|
||||
while ($socialIssue->hasParent()) {
|
||||
$socialIssue = $parents[] = $socialIssue->getParent();
|
||||
}
|
||||
|
||||
return $parents;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param SocialIssue $socialIssue
|
||||
*/
|
||||
public function renderBox($socialIssue, array $options): string
|
||||
{
|
||||
$options = array_merge(self::DEFAULT_ARGS, $options);
|
||||
@@ -81,8 +50,47 @@ final class SocialIssueRender implements ChillEntityRenderInterface
|
||||
[
|
||||
'socialIssue' => $socialIssue,
|
||||
'parents' => $parents,
|
||||
'options' => $options
|
||||
'options' => $options,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SocialIssue $socialIssue
|
||||
*/
|
||||
public function renderString($socialIssue, array $options): string
|
||||
{
|
||||
/** @var SocialIssue $socialIssue */
|
||||
$options = array_merge(self::DEFAULT_ARGS, $options);
|
||||
|
||||
$titles = [$this->translatableStringHelper->localize($socialIssue->getTitle())];
|
||||
|
||||
// loop to parent, until root
|
||||
while ($socialIssue->hasParent()) {
|
||||
$socialIssue = $socialIssue->getParent();
|
||||
$titles[] = $this->translatableStringHelper->localize(
|
||||
$socialIssue->getTitle()
|
||||
);
|
||||
}
|
||||
|
||||
$titles = array_reverse($titles);
|
||||
|
||||
return implode($options[self::SEPARATOR_KEY], $titles);
|
||||
}
|
||||
|
||||
public function supports($entity, array $options): bool
|
||||
{
|
||||
return $entity instanceof SocialIssue;
|
||||
}
|
||||
|
||||
private function buildParents(SocialIssue $socialIssue): array
|
||||
{
|
||||
$parents = [];
|
||||
|
||||
while ($socialIssue->hasParent()) {
|
||||
$socialIssue = $parents[] = $socialIssue->getParent();
|
||||
}
|
||||
|
||||
return $parents;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user