Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
95.92% |
47 / 49 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| UseraccountList | |
95.92% |
47 / 49 |
|
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 1 |
| readResponse | |
95.92% |
47 / 49 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * |
| 5 | * @package Zmsadmin |
| 6 | * @copyright BerlinOnline Stadtportal GmbH & Co. KG |
| 7 | * |
| 8 | */ |
| 9 | |
| 10 | namespace BO\Zmsadmin; |
| 11 | |
| 12 | use BO\Slim\Render; |
| 13 | use BO\Zmsentities\Collection\RoleList; |
| 14 | use BO\Zmsentities\Collection\UseraccountList as Collection; |
| 15 | use BO\Zmsentities\Exception\UserAccountMissingRights; |
| 16 | use Psr\Http\Message\RequestInterface; |
| 17 | use Psr\Http\Message\ResponseInterface; |
| 18 | |
| 19 | class UseraccountList extends BaseController |
| 20 | { |
| 21 | /** |
| 22 | * @SuppressWarnings(Param) |
| 23 | * @return ResponseInterface |
| 24 | */ |
| 25 | #[\Override] |
| 26 | public function readResponse( |
| 27 | RequestInterface $request, |
| 28 | ResponseInterface $response, |
| 29 | array $args |
| 30 | ) { |
| 31 | $workstation = \App::$http->readGetResult('/workstation/', ['resolveReferences' => 1])->getEntity(); |
| 32 | if (! $workstation->getUseraccount()->hasPermissions(['useraccount'])) { |
| 33 | throw new UserAccountMissingRights(); |
| 34 | } |
| 35 | |
| 36 | $ownerList = \App::$http->readGetResult('/owner/', array('resolveReferences' => 2))->getCollection(); |
| 37 | $validator = $request->getAttribute('validator'); |
| 38 | $success = $validator->getParameter('success')->isString()->getValue(); |
| 39 | $queryString = $validator->getParameter('query') |
| 40 | ->isString() |
| 41 | ->getValue(); |
| 42 | |
| 43 | $useraccountList = new Collection(); |
| 44 | if ($workstation->getUseraccount()->isSuperUser()) { |
| 45 | $params = ["resolveReferences" => 0]; |
| 46 | if ($queryString !== null && $queryString !== '') { |
| 47 | $params['query'] = $queryString; |
| 48 | } |
| 49 | $useraccountList = \App::$http->readGetResult("/useraccount/", $params)->getCollection(); |
| 50 | } else { |
| 51 | $workstation = \App::$http->readGetResult('/workstation/', ['resolveReferences' => 2])->getEntity(); |
| 52 | $departmentList = $workstation->getUseraccount()->getDepartmentList(); |
| 53 | $departmentListIds = $departmentList->getIds(); |
| 54 | |
| 55 | if (!empty($departmentListIds)) { |
| 56 | $params = ['resolveReferences' => 0]; |
| 57 | if ($queryString !== null && $queryString !== '') { |
| 58 | $params['query'] = $queryString; |
| 59 | } |
| 60 | $useraccountList = \App::$http |
| 61 | ->readGetResult('/department/' . implode(',', $departmentListIds) . '/useraccount/', $params) |
| 62 | ->getCollection(); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | $roleList = new RoleList(); |
| 67 | $roleMap = []; |
| 68 | |
| 69 | $roleResult = \App::$http->readGetResult('/roles/', []); |
| 70 | if ($roleResult) { |
| 71 | $loadedRoleList = $roleResult->getCollection(); |
| 72 | |
| 73 | if ($loadedRoleList !== null) { |
| 74 | $roleList = $loadedRoleList; |
| 75 | |
| 76 | foreach ($roleList as $role) { |
| 77 | $roleMap[$role->name] = $role->description ?: $role->name; |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | return Render::withHtml( |
| 83 | $response, |
| 84 | 'page/useraccountList.twig', |
| 85 | array( |
| 86 | 'title' => 'Nutzer', |
| 87 | 'menuActive' => 'useraccount', |
| 88 | 'workstation' => $workstation, |
| 89 | 'useraccountList' => $useraccountList, |
| 90 | 'searchUserQuery' => $queryString, |
| 91 | 'ownerlist' => $ownerList, |
| 92 | 'success' => $success, |
| 93 | 'roleMap' => $roleMap, |
| 94 | 'roleList' => $roleList |
| 95 | ) |
| 96 | ); |
| 97 | } |
| 98 | } |