/
ProjectSubscriber.php
88 lines (70 loc) · 3.52 KB
/
ProjectSubscriber.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
<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\EventSubscriber\Actions;
use App\Entity\Project;
use App\Event\PageActionsEvent;
class ProjectSubscriber extends AbstractActionsSubscriber
{
public static function getActionName(): string
{
return 'project';
}
public function onActions(PageActionsEvent $event): void
{
$payload = $event->getPayload();
/** @var Project $project */
$project = $payload['project'];
if ($project->getId() === null) {
return;
}
if (!$event->isView('project_details') && $this->isGranted('view', $project)) {
$event->addAction('details', ['url' => $this->path('project_details', ['id' => $project->getId()])]);
}
if ($this->isGranted('edit', $project)) {
$class = $event->isView('edit') ? '' : 'modal-ajax-form';
$event->addAction('edit', ['url' => $this->path('admin_project_edit', ['id' => $project->getId()]), 'class' => $class]);
}
if ($this->isGranted('permissions', $project)) {
$class = $event->isView('permissions') ? '' : 'modal-ajax-form';
$event->addAction('permissions', ['url' => $this->path('admin_project_permissions', ['id' => $project->getId()]), 'class' => $class]);
}
if ($event->countActions() > 0) {
$event->addDivider();
}
if ($this->isGranted('view_activity')) {
$event->addActionToSubmenu('filter', 'activity', ['title' => 'activity', 'translation_domain' => 'actions', 'url' => $this->path('admin_activity', ['customers[]' => $project->getCustomer()->getId(), 'projects[]' => $project->getId()])]);
}
if ($this->isGranted('view_other_timesheet')) {
$event->addActionToSubmenu('filter', 'timesheet', ['title' => 'timesheet', 'translation_domain' => 'actions', 'url' => $this->path('admin_timesheet', ['customers[]' => $project->getCustomer()->getId(), 'projects[]' => $project->getId()])]);
}
if ($event->hasSubmenu('filter')) {
$event->addDivider();
}
if (!$event->isView('project_details')) {
if ($project->isVisible() && $project->getCustomer()->isVisible() && $this->isGranted('create_activity')) {
$event->addAction('create-activity', [
'icon' => 'create',
'url' => $this->path('admin_activity_create_with_project', ['project' => $project->getId()]),
'class' => 'modal-ajax-form'
]);
}
}
if ($this->isGranted('edit', $project) && $this->isGranted('create_project')) {
$event->addAction(
'copy',
['url' => $this->path('admin_project_duplicate', ['id' => $project->getId(), 'token' => $payload['token']])]
);
}
if (($event->isIndexView() || $event->isView('customer_details')) && $this->isGranted('delete', $project)) {
$event->addDelete($this->path('admin_project_delete', ['id' => $project->getId()]));
}
if ($project->isVisible() && $this->isGranted('view_reporting') && $this->isGranted('details', $project)) {
$event->addAction('report_project_details', ['url' => $this->path('report_project_details', ['project' => $project->getId()]), 'icon' => 'reporting', 'translation_domain' => 'reporting']);
}
}
}