Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
ptsavdar committed Jan 29, 2014
2 parents e5b9d1d + 1130da3 commit 3122a3a
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 5 deletions.
84 changes: 84 additions & 0 deletions Listener/BadgeListener.php
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();
}
}
10 changes: 5 additions & 5 deletions Resources/views/Wiki/wikiSections.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@
<small class="wiki-actions">
{% if section.visible is sameas (false) %}
<span class="invisible-section-text">({{"invisible"|trans({},'icap_wiki')}})</span>
{% endif %}
{% endif %}
[
<a href="{{ path('icap_wiki_new_section', { 'wikiId': wikiId, 'parentSectionId' : section.id }) }}" class="new-section" data-section="{{section.id}}" >
{{ 'add_new_subsection'|trans({}, 'icap_wiki') }}
</a>
|
</a>
|
<a href="{{ path('icap_wiki_edit_section', { 'wikiId': wikiId, 'sectionId' : section.id }) }}" class="edit-section" data-section="{{section.id}}" >
{{ 'edit'|trans({}, 'icap_wiki') }}
</a>
</a>
|
<a href="{{ path('icap_wiki_section_history', { 'wikiId': wikiId, 'sectionId' : section.id }) }}" class="history-section" data-section="{{section.id}}" >
{{ 'history'|trans({}, 'icap_wiki') }}
</a>
</a>
]
</small>
{% endif%}
Expand Down

0 comments on commit 3122a3a

Please sign in to comment.