mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-22 23:53:50 +00:00
Fix filtres and scopes to take into account job and scope when the refferrer is add to the accompanying period work
This commit is contained in:
@@ -292,9 +292,7 @@ class User implements UserInterface, \Stringable
|
||||
|
||||
$sortedScopeHistories = $scopeHistories->toArray();
|
||||
|
||||
usort($sortedScopeHistories, function ($a, $b) {
|
||||
return $a->getStartDate() < $b->getStartDate() ? 1 : -1;
|
||||
});
|
||||
usort($sortedScopeHistories, fn ($a, $b) => $a->getStartDate() < $b->getStartDate() ? 1 : -1);
|
||||
|
||||
return new ArrayCollection($sortedScopeHistories);
|
||||
}
|
||||
@@ -346,9 +344,7 @@ class User implements UserInterface, \Stringable
|
||||
|
||||
$sortedJobHistories = $jobHistories->toArray();
|
||||
|
||||
usort($sortedJobHistories, function ($a, $b) {
|
||||
return $a->getStartDate() < $b->getStartDate() ? 1 : -1;
|
||||
});
|
||||
usort($sortedJobHistories, fn ($a, $b) => $a->getStartDate() < $b->getStartDate() ? 1 : -1);
|
||||
|
||||
return new ArrayCollection($sortedJobHistories);
|
||||
}
|
||||
|
@@ -281,9 +281,9 @@ class ExportAddressHelper
|
||||
};
|
||||
|
||||
case 'country':
|
||||
return function ($value) use ($key) {
|
||||
return function ($value) use ($sanitizedKey, $translationPrefix) {
|
||||
if ('_header' === $value) {
|
||||
return 'export.list.acp' . $key;
|
||||
return $translationPrefix . $sanitizedKey;
|
||||
}
|
||||
|
||||
if (null === $value) {
|
||||
|
@@ -20,21 +20,64 @@ class UserHelper
|
||||
{
|
||||
public function __construct(private readonly UserRender $userRender, private readonly UserRepositoryInterface $userRepository) {}
|
||||
|
||||
/**
|
||||
* Return a callable that will transform a value into a string representing a user
|
||||
*
|
||||
* The callable may receive as argument:
|
||||
*
|
||||
* - an int or a string, the id of the user;
|
||||
* - a string containing a json which will be decoded, and will have this structure: array{uid: int, d: string}. The job and scopes will be shown at this date
|
||||
*
|
||||
* @param string $key the key of the content
|
||||
* @param array $values the list of values
|
||||
* @param string $header the header's content
|
||||
*/
|
||||
public function getLabel($key, array $values, string $header): callable
|
||||
{
|
||||
return function ($value) use ($header) {
|
||||
return function (null|int|string $value) use ($header) {
|
||||
if ('_header' === $value) {
|
||||
return $header;
|
||||
}
|
||||
|
||||
if (null === $value || null === $user = $this->userRepository->find($value)) {
|
||||
if (null === $value) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $this->userRender->renderString($user, []);
|
||||
if (is_numeric($value)) {
|
||||
$uid = $value;
|
||||
$date = null;
|
||||
} else {
|
||||
$decode = json_decode($value, true, 512, JSON_THROW_ON_ERROR);
|
||||
$uid = $decode['uid'];
|
||||
|
||||
if (null === $uid) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$date = new \DateTimeImmutable($decode['d']);
|
||||
}
|
||||
|
||||
if (null === $user = $this->userRepository->find($uid)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $this->userRender->renderString($user, ['at' => $date]);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a callable that will transform a value into a string representing a user
|
||||
*
|
||||
* The callable may receive as argument:
|
||||
*
|
||||
* - an int or a string, the id of the user;
|
||||
* - a string containing a json which will be decoded, and will have this structure: array{uid: int, d: string}. The job and scopes will be shown at this date * @param $key
|
||||
*
|
||||
* @param string $key the key of the element
|
||||
* @param array $values a list of values
|
||||
* @param string $header the header's content
|
||||
* @return callable
|
||||
*/
|
||||
public function getLabelMulti($key, array $values, string $header): callable
|
||||
{
|
||||
return function ($value) use ($header) {
|
||||
@@ -46,31 +89,36 @@ class UserHelper
|
||||
return '';
|
||||
}
|
||||
|
||||
$decoded = json_decode((string) $value, null, 512, JSON_THROW_ON_ERROR);
|
||||
$decoded = json_decode((string) $value, true, 512, JSON_THROW_ON_ERROR);
|
||||
|
||||
if (0 === count($decoded)) {
|
||||
return '';
|
||||
}
|
||||
$asStrings = [];
|
||||
|
||||
return
|
||||
implode(
|
||||
'|',
|
||||
array_map(
|
||||
function (int $userId) {
|
||||
$user = $this->userRepository->find($userId);
|
||||
foreach ($decoded as $userId) {
|
||||
if (is_array($userId)) {
|
||||
$uid = $userId['uid'];
|
||||
$date = new \DateTimeImmutable($userId['d']);
|
||||
} else {
|
||||
$uid = $userId;
|
||||
$date = null;
|
||||
}
|
||||
|
||||
if (null === $user) {
|
||||
return '';
|
||||
}
|
||||
if (null === $uid) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return $this->userRender->renderString($user, []);
|
||||
},
|
||||
array_unique(
|
||||
array_filter($decoded, static fn (?int $userId) => null !== $userId),
|
||||
SORT_NUMERIC
|
||||
)
|
||||
)
|
||||
);
|
||||
$user = $this->userRepository->find($uid);
|
||||
|
||||
if (null === $user) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$asStrings[$uid] = $this->userRender->renderString($user, ['absence' => false, 'at' => $date]);
|
||||
}
|
||||
|
||||
return implode('|', $asStrings);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@@ -1,10 +1,10 @@
|
||||
<span class="chill-entity entity-user">
|
||||
{{- user.label }}
|
||||
{%- if opts['user_job'] and user.userJob is not null %}
|
||||
<span class="user-job">({{ user.userJob.label|localize_translatable_string }})</span>
|
||||
{%- if opts['user_job'] and user.userJob(opts['at']) is not null %}
|
||||
<span class="user-job">({{ user.userJob(opts['at']).label|localize_translatable_string }})</span>
|
||||
{%- endif -%}
|
||||
{%- if opts['main_scope'] and user.mainScope is not null %}
|
||||
<span class="main-scope">({{ user.mainScope.name|localize_translatable_string }})</span>
|
||||
{%- if opts['main_scope'] and user.mainScope(opts['at']) is not null %}
|
||||
<span class="main-scope">({{ user.mainScope(opts['at']).name|localize_translatable_string }})</span>
|
||||
{%- endif -%}
|
||||
{%- if opts['absence'] and user.isAbsent %}
|
||||
<span class="badge bg-danger rounded-pill" title="{{ 'absence.Absent'|trans|escape('html_attr') }}">{{ 'absence.A'|trans }}</span>
|
||||
|
@@ -28,10 +28,14 @@ class UserRender implements ChillEntityRenderInterface
|
||||
'main_scope' => true,
|
||||
'user_job' => true,
|
||||
'absence' => true,
|
||||
'at' => null,
|
||||
];
|
||||
|
||||
public function __construct(private readonly TranslatableStringHelper $translatableStringHelper, private readonly \Twig\Environment $engine, private readonly TranslatorInterface $translator) {}
|
||||
|
||||
/**
|
||||
* @param mixed $entity
|
||||
*/
|
||||
public function renderBox($entity, array $options): string
|
||||
{
|
||||
$opts = array_merge(self::DEFAULT_OPTIONS, $options);
|
||||
@@ -42,20 +46,23 @@ class UserRender implements ChillEntityRenderInterface
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $entity
|
||||
*/
|
||||
public function renderString($entity, array $options): string
|
||||
{
|
||||
$opts = array_merge(self::DEFAULT_OPTIONS, $options);
|
||||
|
||||
$str = $entity->getLabel();
|
||||
|
||||
if (null !== $entity->getUserJob() && $opts['user_job']) {
|
||||
if (null !== $entity->getUserJob($opts['at']) && $opts['user_job']) {
|
||||
$str .= ' (' . $this->translatableStringHelper
|
||||
->localize($entity->getUserJob()->getLabel()) . ')';
|
||||
->localize($entity->getUserJob($opts['at'])->getLabel()) . ')';
|
||||
}
|
||||
|
||||
if (null !== $entity->getMainScope() && $opts['main_scope']) {
|
||||
if (null !== $entity->getMainScope($opts['at']) && $opts['main_scope']) {
|
||||
$str .= ' (' . $this->translatableStringHelper
|
||||
->localize($entity->getMainScope()->getName()) . ')';
|
||||
->localize($entity->getMainScope($opts['at'])->getName()) . ')';
|
||||
}
|
||||
|
||||
if ($entity->isAbsent() && $opts['absence']) {
|
||||
|
Reference in New Issue
Block a user