1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of Sulu. |
5
|
|
|
* |
6
|
|
|
* (c) MASSIVE ART WebServices GmbH |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the MIT license that is bundled |
9
|
|
|
* with this source code in the file LICENSE. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Sulu\Bundle\ActivityLogBundle\Controller; |
13
|
|
|
|
14
|
|
|
use FOS\RestBundle\Controller\Annotations\Get; |
15
|
|
|
use FOS\RestBundle\Controller\FOSRestController; |
16
|
|
|
use FOS\RestBundle\Routing\ClassResourceInterface; |
17
|
|
|
use Sulu\Bundle\ActivityLogBundle\Compatibility\FieldDescriptor; |
18
|
|
|
use Sulu\Component\ActivityLog\ActivityLoggerInterface; |
19
|
|
|
use Sulu\Component\Rest\ListBuilder\ListRepresentation; |
20
|
|
|
use Sulu\Component\Rest\ListBuilder\ListRestHelper; |
21
|
|
|
use Symfony\Component\HttpFoundation\Request; |
22
|
|
|
|
23
|
|
|
class ActivityLogController extends FOSRestController implements ClassResourceInterface |
24
|
|
|
{ |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Returns all fields that can be used by list. |
28
|
|
|
* |
29
|
|
|
* @Get("activity-log/fields") |
30
|
|
|
* |
31
|
|
|
* @param Request $request |
32
|
|
|
* |
33
|
|
|
* @return mixed |
34
|
|
|
*/ |
35
|
|
|
public function getFieldsAction(Request $request) |
|
|
|
|
36
|
|
|
{ |
37
|
|
|
// default contacts list |
38
|
|
|
return $this->handleView( |
39
|
|
|
$this->view( |
|
|
|
|
40
|
|
|
array_values( |
41
|
|
|
$this->getFieldDescriptors() |
42
|
|
|
), |
43
|
|
|
200 |
44
|
|
|
) |
45
|
|
|
); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Create field-descriptor array. |
50
|
|
|
* |
51
|
|
|
* @return FieldDescriptor[] |
52
|
|
|
*/ |
53
|
|
|
private function getFieldDescriptors() |
54
|
|
|
{ |
55
|
|
|
return [ |
56
|
|
|
'uuid' => new FieldDescriptor('id', 'public.id', true, false), |
57
|
|
|
'source' => new FieldDescriptor('source', 'public.source', false, true), |
58
|
|
|
'action' => new FieldDescriptor('action', 'public.action', false, true), |
59
|
|
|
'value' => new FieldDescriptor('value', 'public.value', false, true), |
60
|
|
|
'timestamp' => new FieldDescriptor('timestamp', 'public.timestamp', false, true), |
61
|
|
|
'userId' => new FieldDescriptor('userId', 'public.userId', false, true), |
62
|
|
|
'userIP' => new FieldDescriptor('userIP', 'public.userIP', false, true), |
63
|
|
|
]; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Shows all activity-log-items |
68
|
|
|
* |
69
|
|
|
* @param Request $request |
70
|
|
|
* |
71
|
|
|
* @Get("activity-log") |
72
|
|
|
* |
73
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
74
|
|
|
*/ |
75
|
|
|
public function cgetAction(Request $request) |
76
|
|
|
{ |
77
|
|
|
$restHelper = new ListRestHelper($request); |
|
|
|
|
78
|
|
|
|
79
|
|
|
/** @var ActivityLoggerInterface $activityLogger */ |
80
|
|
|
$activityLogger = $this->get('sulu_activity_log.activity_logger'); |
81
|
|
|
|
82
|
|
|
$page = (int)$restHelper->getPage(); |
83
|
|
|
$limit = (int)$restHelper->getLimit(); |
84
|
|
|
|
85
|
|
|
$results = $activityLogger->findAll($page, $limit); |
86
|
|
|
|
87
|
|
|
$list = []; |
88
|
|
|
foreach ($results as $result) { |
89
|
|
|
$list[] = [ |
90
|
|
|
'id' => $result['uuid'], |
91
|
|
|
'source' => $result['src'], |
92
|
|
|
'action' => $result['action'], |
93
|
|
|
'value' => $result['value'], |
94
|
|
|
'timestamp' => $result['ts'], |
95
|
|
|
'userId' => $result['uid'], |
96
|
|
|
'userIP' => $result['uip'] |
97
|
|
|
]; |
98
|
|
|
} |
99
|
|
|
$list = array_values($list); |
100
|
|
|
|
101
|
|
|
$list = new ListRepresentation( |
102
|
|
|
$list, |
103
|
|
|
'activity-log-items', |
104
|
|
|
'get_activity_logs', |
105
|
|
|
$request->query->all(), |
106
|
|
|
$page, |
107
|
|
|
$limit, |
108
|
|
|
count($list) |
109
|
|
|
); |
110
|
|
|
|
111
|
|
|
$view = $this->view($list, 200); |
112
|
|
|
|
113
|
|
|
return $this->handleView($view); |
|
|
|
|
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
} |
117
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.