/
UserLogsessions.php
96 lines (90 loc) · 3.38 KB
/
UserLogsessions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
namespace App\Controller\Web\Users;
use App\Form\Listeners\ListenerLogSessions as Form;
use DateTime;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route; // Required for annotations
/**
* Class Listeners
* @package App\Controller\Web
*/
class UserLogsessions extends Base
{
const defaultlimit = 100;
const defaultSorting = 'timestamp';
const defaultOrder = 'd';
/**
* @Route(
* "/{_locale}/{system}/users/{id}/logsessions",
* requirements={
* "_locale": "de|en|es|fr",
* "system": "reu|rna|rww"
* },
* name="user_logsessions"
* )
* @param $_locale
* @param $system
* @param $id
* @param Request $request
* @param Form $form
* @return RedirectResponse|Response
*/
public function logSessions(
$_locale,
$system,
$id,
Request $request,
Form $form
) {
if ((int)$this->parameters['access'] === 0) {
$this->session->set('route', 'user_logsessions?id=' . $id);
return $this->redirectToRoute('logon', ['system' => $system]);
}
if (!$user = $this->getValidUser($id)) {
return $this->redirectToRoute('users', ['system' => $system]);
}
$isAdmin = $this->parameters['isAdmin'];
$options = [
'limit' => static::defaultlimit,
'order' => static::defaultOrder,
'page' => 0,
'sort' => static::defaultSorting,
'total' => $user->getCountLogsession()
];
$form = $form->buildForm($this->createFormBuilder(), $options);
$form->handleRequest($request);
$args = [
'limit' => static::defaultlimit,
'order' => static::defaultOrder,
'page' => 0,
'sort' => static::defaultSorting,
];
if ($form->isSubmitted() && $form->isValid()) {
$args = $form->getData();
}
$args['administratorId'] = $id;
$columns = $this->userRepository->getColumns('logsessions');
$logSessions = $this->logsessionRepository->getLogsessions($args, $columns);
$parameters = [
'args' => $args,
'id' => $id,
'columns' => $columns,
'form' => $form->createView(),
'_locale' => $_locale,
'matched' => 'of '.$options['total']. ' log sessions.',
'mode' => 'Log Sessions | Uploaded by ' . $user->getName(),
'logsessions' => $logSessions,
'results' => [
'limit' => isset($args['limit']) ? $args['limit'] : static::defaultlimit,
'page' => isset($args['page']) ? $args['page'] : 0,
'total' => $options['total']
],
'system' => $system,
'tabs' => $this->userRepository->getTabs($user),
'typeRepository' => $this->typeRepository
];
return $this->render('user/logsessions.html.twig', $this->getMergedParameters($parameters));
}
}