privacyEvent, add event to show and list Actions

This commit is contained in:
Mat 2018-10-16 15:28:59 +02:00
parent e25621ef79
commit 32d5d448e0
2 changed files with 41 additions and 8 deletions

View File

@ -2,6 +2,7 @@
namespace Chill\TaskBundle\Controller;
use Chill\PersonBundle\Privacy\PrivacyEvent;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Doctrine\ORM\EntityManager;
@ -29,7 +30,23 @@ use Chill\TaskBundle\Event\UI\UIEvent;
class SingleTaskController extends Controller
{
/**
* @var EventDispatcherInterface
*/
protected $eventDispatcher;
/**
* SingleTaskController constructor.
*
* @param EventDispatcherInterface $eventDispatcher
*/
public function __construct(EventDispatcherInterface $eventDispatcher)
{
$this->eventDispatcher = $eventDispatcher;
}
/**
* @Route(
* "/{_locale}/task/single-task/new",
@ -38,7 +55,6 @@ class SingleTaskController extends Controller
*/
public function newAction(
Request $request,
EventDispatcherInterface $dispatcher,
TranslatorInterface $translator
) {
@ -77,7 +93,7 @@ class SingleTaskController extends Controller
$em = $this->getDoctrine()->getManager();
$em->persist($task);
$dispatcher->dispatch(TaskEvent::PERSIST, new TaskEvent($task));
$this->eventDispatcher->dispatch(TaskEvent::PERSIST, new TaskEvent($task));
$em->flush();
@ -136,7 +152,14 @@ class SingleTaskController extends Controller
$timeline = $this->get('chill.main.timeline_builder')
->getTimelineHTML('task', array('task' => $task));
$event = new PrivacyEvent($person, array(
'element_class' => SingleTask::class,
'element_id' => intval($id),
'action' => 'show'
));
$this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event);
return $this->render('ChillTaskBundle:SingleTask:show.html.twig', array(
'task' => $task,
'timeline' => $timeline
@ -153,8 +176,7 @@ class SingleTaskController extends Controller
public function editAction(
Request $request,
$id,
TranslatorInterface $translator,
EventDispatcherInterface $dispatcher
TranslatorInterface $translator
) {
/* @var $taskRepository SingleTaskRepository */
$taskRepository = $this->get('chill_task.single_task_repository');
@ -186,7 +208,7 @@ class SingleTaskController extends Controller
->setForm($this->setCreateForm($task, new Role(TaskVoter::UPDATE)))
;
$dispatcher->dispatch(UIEvent::EDIT_FORM, $event);
$this->eventDispatcher->dispatch(UIEvent::EDIT_FORM, $event);
$form = $event->getForm();
@ -212,7 +234,7 @@ class SingleTaskController extends Controller
}
}
$dispatcher->dispatch(UIEvent::EDIT_PAGE, $event);
$this->eventDispatcher->dispatch(UIEvent::EDIT_PAGE, $event);
if ($event->hasResponse()) {
return $event->getResponse();
@ -494,6 +516,12 @@ class SingleTaskController extends Controller
]);
$form->handleRequest($request);
$event = new PrivacyEvent($person, array(
'element_class' => SingleTask::class,
'action' => 'list'
));
$this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event);
return $this->render('ChillTaskBundle:SingleTask:index.html.twig',
\array_merge($viewParams, [ 'form' => $form->createView() ]));

View File

@ -2,3 +2,8 @@ services:
Chill\TaskBundle\Controller\:
resource: '../../../Controller'
tags: ['controller.service_arguments']
Chill\TaskBundle\Controller\SingleTaskController:
arguments:
$eventDispatcher: '@Symfony\Component\EventDispatcher\EventDispatcherInterface'
tags: ['controller.service_arguments']