-
Notifications
You must be signed in to change notification settings - Fork 0
Create Json Output
Alexander Saal edited this page Aug 7, 2025
·
2 revisions
This example just outputs the data as Json, making sure the browser understands by setting the content type to application/json.
<?php
use JobRouter\Sdk\PathsInterface;
use JobRouter\Sdk\UserManagerInterface;
return function (UserManagerInterface $userInterface, PathsInterface $pathsInterface): void {
try {
$user = $userInterface->getCurrentUser();
$employeeData = [
'fullname' => $user->getFullName(),
'phone' => $user->getPhone(),
'email' => $user->getEmail(),
'language' => $user->getLanguage(),
'region' => $user->getTimezone(),
'avatarImage' => $pathsInterface->getJobRouterUrl() . '/' . $user->getAvatarUrl(),
'department' => $user->getDepartment(),
'groupMemberships' => $user->getJobFunctions(),
'supervisor' => $userInterface->getUserByUsername($user->getSupervisor())->getFullName(),
'active' => $user->isBlocked() ? 'No' : 'Yes',
];
header('Content-Type: application/json');
echo json_encode($employeeData);
} catch (\NoInstanceFoundException) {
echo '<h3 style="color: #f44;">The user is not authenticated!</h3>';
}
};
