From 1130da38afc1f9d44d231aec5718edc1ab6cfcc7 Mon Sep 17 00:00:00 2001 From: Maxime AILLOUD Date: Wed, 29 Jan 2014 09:41:45 +0100 Subject: [PATCH] Adding listener for displaying validation link on profile badge page --- Listener/BadgeListener.php | 84 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 Listener/BadgeListener.php diff --git a/Listener/BadgeListener.php b/Listener/BadgeListener.php new file mode 100644 index 0000000..9b0e54d --- /dev/null +++ b/Listener/BadgeListener.php @@ -0,0 +1,84 @@ +router = $router; + } + + /** + * @DI\Observe("badge-resource-icap_wiki-section_create-generate_validation_link") + * @DI\Observe("badge-resource-icap_wiki-section_delete-generate_validation_link") + * @DI\Observe("badge-resource-icap_wiki-section_move-generate_validation_link") + * @DI\Observe("badge-resource-icap_wiki-section_remove-generate_validation_link") + * @DI\Observe("badge-resource-icap_wiki-section_restore-generate_validation_link") + * @DI\Observe("badge-resource-icap_wiki-section_update-generate_validation_link") + * @DI\Observe("badge-resource-icap_wiki-contribution_create-generate_validation_link") + */ + public function onBagdeCreateValidationLink(BadgeCreateValidationLinkEvent $event) + { + $content = null; + $log = $event->getLog(); + + switch($log->getAction()) + { + case LogSectionCreateEvent::ACTION: + case LogSectionDeleteEvent::ACTION: + case LogSectionMoveEvent::ACTION: + case LogSectionRemoveEvent::ACTION: + case LogSectionRestoreEvent::ACTION: + case LogSectionUpdateEvent::ACTION: + $logDetails = $event->getLog()->getDetails(); + $parameters = array('wikiId' => $logDetails['section']['wiki']); + $sectionAnchor = sprintf("#section-%s", $logDetails['section']['id']); + $url = $this->router->generate('icap_wiki_view', $parameters, UrlGeneratorInterface::ABSOLUTE_PATH); + $title = $logDetails['section']['title']; + $content = sprintf('%s', $url, $sectionAnchor, $title, $title); + break; + case LogContributionCreateEvent::ACTION: + $logDetails = $event->getLog()->getDetails(); + $parameters = array('wikiId' => $logDetails['contribution']['wiki']); + $sectionAnchor = sprintf("#section-%s", $logDetails['contribution']['section']); + $url = $this->router->generate('icap_wiki_view', $parameters, UrlGeneratorInterface::ABSOLUTE_PATH); + $title = $logDetails['contribution']['title']; + $content = sprintf('%s', $url, $sectionAnchor, $title, $title); + break; + } + + $event->setContent($content); + $event->stopPropagation(); + } +}