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:
2023-10-16 10:58:41 +02:00
parent 63e9d1a96f
commit 68d28f3e28
24 changed files with 352 additions and 173 deletions

View File

@@ -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) {

View File

@@ -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);
};
}
}