-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master'
- Loading branch information
Showing
2 changed files
with
89 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
|
||
namespace Icap\WikiBundle\Listener; | ||
|
||
use Claroline\CoreBundle\Event\Badge\BadgeCreateValidationLinkEvent; | ||
use Icap\BlogBundle\Event\Log\LogCommentCreateEvent; | ||
use Icap\BlogBundle\Event\Log\LogCommentDeleteEvent; | ||
use Icap\BlogBundle\Event\Log\LogPostCreateEvent; | ||
use Icap\BlogBundle\Event\Log\LogPostDeleteEvent; | ||
use Icap\BlogBundle\Event\Log\LogPostReadEvent; | ||
use Icap\BlogBundle\Event\Log\LogPostUpdateEvent; | ||
use Icap\WikiBundle\Event\Log\LogContributionCreateEvent; | ||
use Icap\WikiBundle\Event\Log\LogSectionCreateEvent; | ||
use Icap\WikiBundle\Event\Log\LogSectionDeleteEvent; | ||
use Icap\WikiBundle\Event\Log\LogSectionMoveEvent; | ||
use Icap\WikiBundle\Event\Log\LogSectionRemoveEvent; | ||
use Icap\WikiBundle\Event\Log\LogSectionRestoreEvent; | ||
use Icap\WikiBundle\Event\Log\LogSectionUpdateEvent; | ||
use Symfony\Bundle\FrameworkBundle\Routing\Router; | ||
use Symfony\Bundle\FrameworkBundle\Translation\Translator; | ||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | ||
use JMS\DiExtraBundle\Annotation as DI; | ||
|
||
/** | ||
* @DI\Service("icap.listener.wiki.badge_listener") | ||
*/ | ||
class BadgeListener | ||
{ | ||
/** @var \Symfony\Bundle\FrameworkBundle\Routing\Router */ | ||
private $router; | ||
|
||
/** | ||
* @DI\InjectParams({ | ||
* "router" = @DI\Inject("router") | ||
* }) | ||
*/ | ||
public function __construct(Router $router) | ||
{ | ||
$this->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('<a href="%s%s" title="%s">%s</a>', $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('<a href="%s%s" title="%s">%s</a>', $url, $sectionAnchor, $title, $title); | ||
break; | ||
} | ||
|
||
$event->setContent($content); | ||
$event->stopPropagation(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters