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\Component\ActivityLog\ActivityLogger; |
18
|
|
|
use Sulu\Component\Rest\Exception\EntityNotFoundException; |
19
|
|
|
use Sulu\Component\Rest\ListBuilder\FieldDescriptor; |
20
|
|
|
use Sulu\Component\Rest\ListBuilder\ListRepresentation; |
21
|
|
|
use Symfony\Component\HttpFoundation\Request; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Makes activity logs available through a REST API. |
25
|
|
|
*/ |
26
|
|
|
class ActivityLogController extends FOSRestController implements ClassResourceInterface |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* Returns all fields that can be used by list. |
30
|
|
|
* |
31
|
|
|
* @Get("activity-log/fields") |
32
|
|
|
* |
33
|
|
|
* @param Request $request |
34
|
|
|
* |
35
|
|
|
* @return mixed |
36
|
|
|
*/ |
37
|
|
|
public function getFieldsAction(Request $request) |
|
|
|
|
38
|
|
|
{ |
39
|
|
|
// default contacts list |
40
|
|
|
return $this->handleView( |
41
|
|
|
$this->view( |
|
|
|
|
42
|
|
|
array_values( |
43
|
|
|
$this->getFieldDescriptors() |
44
|
|
|
), |
45
|
|
|
200 |
46
|
|
|
) |
47
|
|
|
); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Shows all activity-log-items. |
52
|
|
|
* |
53
|
|
|
* @param Request $request |
54
|
|
|
* |
55
|
|
|
* @Get("activity-log") |
56
|
|
|
* |
57
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
58
|
|
|
*/ |
59
|
5 |
|
public function cgetAction(Request $request) |
60
|
|
|
{ |
61
|
5 |
|
$list = $this->getActivityLogs($request); |
62
|
|
|
|
63
|
5 |
|
$view = $this->view($list, 200); |
64
|
|
|
|
65
|
5 |
|
return $this->handleView($view); |
|
|
|
|
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Create field-descriptor array. |
70
|
|
|
* |
71
|
|
|
* @return FieldDescriptor[] |
72
|
|
|
*/ |
73
|
|
|
protected function getFieldDescriptors() |
74
|
|
|
{ |
75
|
|
|
return [ |
76
|
|
|
'uuid' => new FieldDescriptor('uuid', 'public.id', true, false), |
77
|
|
|
'type' => new FieldDescriptor('type', 'sulu_activity_log.type', false, true), |
78
|
|
|
'title' => new FieldDescriptor('title', 'public.title', false, true), |
79
|
|
|
'message' => new FieldDescriptor('message', 'sulu_activity_log.message', false, true), |
80
|
|
|
'created' => new FieldDescriptor('created', 'public.created', false, true, 'datetime'), |
81
|
|
|
]; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* returns view of files. |
86
|
|
|
* |
87
|
|
|
* @param Request $request |
88
|
|
|
* |
89
|
|
|
* @throws EntityNotFoundException |
90
|
|
|
* |
91
|
|
|
* @return ListRepresentation |
92
|
|
|
*/ |
93
|
5 |
|
protected function getActivityLogs(Request $request) |
94
|
|
|
{ |
95
|
5 |
|
$restHelper = $this->get('sulu_core.list_rest_helper'); |
96
|
|
|
|
97
|
|
|
/** @var ActivityLogger $activityLogger */ |
98
|
5 |
|
$activityLogger = $this->get('sulu_activity_log.activity_logger'); |
99
|
|
|
|
100
|
5 |
|
$page = (int) $restHelper->getPage(); |
101
|
5 |
|
$limit = (int) $restHelper->getLimit(); |
102
|
5 |
|
$sortColumn = $restHelper->getSortColumn(); |
103
|
5 |
|
$sortOrder = $restHelper->getSortOrder(); |
104
|
5 |
|
$searchPattern = $restHelper->getSearchPattern(); |
105
|
5 |
|
$searchFields = $restHelper->getSearchFields(); |
106
|
|
|
|
107
|
5 |
|
$list = $activityLogger->findAllWithSearch( |
108
|
|
|
$searchPattern, |
109
|
|
|
$searchFields, |
110
|
|
|
$page, |
111
|
|
|
$limit, |
112
|
|
|
$sortColumn, |
113
|
5 |
|
$sortOrder |
114
|
|
|
); |
115
|
|
|
|
116
|
5 |
|
$total = $activityLogger->getCountForAllWithSearch($searchPattern, $searchFields); |
117
|
|
|
|
118
|
5 |
|
$list = array_values($list); |
119
|
|
|
|
120
|
5 |
|
$list = new ListRepresentation( |
121
|
|
|
$list, |
122
|
5 |
|
'activity-log-items', |
123
|
5 |
|
'get_activity_logs', |
124
|
5 |
|
$request->query->all(), |
125
|
|
|
$page, |
126
|
|
|
$limit, |
127
|
5 |
|
$total |
128
|
|
|
); |
129
|
|
|
|
130
|
5 |
|
return $list; |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.