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; * * @param string $key the key of the element * @param array $values a list of values * @param string $header the header's content */ public function getLabelMulti($key, array $values, string $header): callable { return function ($value) use ($header) { if ('_header' === $value) { return $header; } if (null === $value) { return ''; } $decoded = json_decode((string) $value, true, 512, JSON_THROW_ON_ERROR); if (0 === \count($decoded)) { return ''; } $asStrings = []; if (array_key_exists('uid', $decoded) || is_numeric($decoded)) { // this is a single value. We have to wrap it into an array $decoded = [$decoded]; } foreach ($decoded as $userId) { if (is_array($userId)) { $uid = $userId['uid']; $date = new \DateTimeImmutable($userId['d']); } else { $uid = $userId; $date = null; } if (null === $uid) { continue; } $user = $this->userRepository->find($uid); if (null === $user) { continue; } $asStrings[$uid] = $this->userRender->renderString($user, ['absence' => false, 'at' => $date]); } return implode('|', $asStrings); }; } }