Please enable JavaScript to view this site.

The manual for the JobRouter developer

Navigation: SDK > Examples

Create Json Output

Scroll Prev Top Next More

Example

This example just outputs the data as Json, making sure the browser understands by setting the content type to application/json.

index.php

<?php

use JobRouter\Sdk\UserManagerInterface;

use JobRouter\Sdk\PathsInterface;

 

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 (\JobRouterException) {

         echo '<h3 style="color: #f44;">The user is not authenticated!</h3>';

    }

};

Output

SDK_Examples_Json