Skip to content

Commit

Permalink
Integrated user-picker notification functionnalities
Browse files Browse the repository at this point in the history
  • Loading branch information
ptsavdar committed Mar 26, 2014
1 parent 3122a3a commit 6349f99
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 6 deletions.
2 changes: 2 additions & 0 deletions Controller/SectionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,8 @@ private function persistCreateSection (Request $request, Wiki $wiki, Section $se

$flashBag->add('success', $translator->trans('icap_wiki_section_add_success', array(), 'icap_wiki'));
} catch (\Exception $exception) {
var_dump($exception->getMessage());
die();
$flashBag->add('error', $translator->trans('icap_wiki_section_add_error', array(), 'icap_wiki'));
}

Expand Down
46 changes: 42 additions & 4 deletions Entity/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Claroline\CoreBundle\Entity\User;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Icap\NotificationBundle\Entity\UserPickerContent;
use JMS\DiExtraBundle\Annotation as DI;


/**
* @ORM\Entity(repositoryClass="Icap\WikiBundle\Repository\ContributionRepository")
* @ORM\Table(name="icap__wiki_contribution")
* @ORM\Entity(repositoryClass="Icap\WikiBundle\Repository\ContributionRepository")
* @ORM\EntityListeners({"Icap\WikiBundle\Listener\ContributionListener"})
* @ORM\Table(name="icap__wiki_contribution")
* @ORM\HasLifecycleCallbacks()
*/
class Contribution
{
Expand Down Expand Up @@ -49,6 +55,8 @@ class Contribution
*/
protected $section;

protected $userPicker = null;

/**
* Get id
*
Expand Down Expand Up @@ -115,7 +123,7 @@ public function setCreationDate($creationDate)
* Set contributor
*
* @param User $contributor
* @return Post
* @return Contribution
*/
public function setContributor(User $contributor = null)
{
Expand All @@ -138,7 +146,7 @@ public function getContributor()
* Set section
*
* @param \Icap\WikiBundle\Entity\Section $section
* @return section
* @return contribution
*/
public function setSection(\Icap\WikiBundle\Entity\Section $section)
{
Expand All @@ -156,4 +164,34 @@ public function getSection()
{
return $this->section;
}

/**
* @param UserPickerContent $userPicker
* @return $this
*/
public function setUserPicker(UserPickerContent $userPicker)
{
$this->userPicker = $userPicker;

return $this;
}

/**
* @return \Icap\NotificationBundle\Entity\UserPickerContent
*/
public function getUserPicker()
{
return $this->userPicker;
}

/**
* @ORM\PrePersist
*/
public function createUserPicker(LifecycleEventArgs $event){
if ($this->getText() != null) {
$userPicker = new UserPickerContent($this->getText());
$this->setUserPicker($userPicker);
$this->setText($userPicker->getFinalText());
}
}
}
70 changes: 70 additions & 0 deletions Listener/ContributionListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

/*
* This file is part of the Claroline Connect package.
*
* (c) Claroline Consortium <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Icap\WikiBundle\Listener;

use Doctrine\ORM\Event\LifecycleEventArgs;
use Icap\WikiBundle\Entity\Contribution;
use JMS\DiExtraBundle\Annotation as DI;
use Icap\NotificationBundle\Manager\NotificationManager as NotificationManager;

/**
* @DI\Service("icap.wiki_bundle.entity_listener.contribution")
* @DI\Tag("doctrine.entity_listener")
*/
class ContributionListener
{
/** @var \Icap\NotificationBundle\Manager\NotificationManager */
private $notificationManager;

/**
* @DI\InjectParams({
* "notificationManager" = @DI\Inject("icap.notification.manager"),
* })
*/
public function __construct(NotificationManager $notificationManager)
{
$this->notificationManager = $notificationManager;
}

public function postPersist(Contribution $contribution, LifecycleEventArgs $event)
{
if ($contribution->getUserPicker() != null) {
$section = $contribution->getSection();
$wiki = $section->getWiki();
$details = array(
'contribution' => array(
'wiki' => $wiki->getId(),
'section' => $section->getId(),
'id' => $contribution->getId(),
'title' => $contribution->getTitle(),
'text' => $contribution->getText(),
'contributor' => $contribution->getContributor()->getFirstName() .
' ' .
$contribution->getContributor()->getLastName()
),
'resource' => array(
'id' => $wiki->getId(),
'name' => $wiki->getResourceNode()->getName(),
'type' => $wiki->getResourceNode()->getResourceType()->getName()
)
);
$notification = $this->notificationManager->createNotification(
'resource-icap_wiki-user_tagged',
'wiki',
$wiki->getResourceNode()->getId(),
$details,
$contribution->getContributor()
);
$this->notificationManager->notifyUsers($notification, $contribution->getUserPicker()->getUserIds());
}
}
}
3 changes: 2 additions & 1 deletion Resources/config/services/listeners.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ services:
- [setContainer, ["@service_container"]]
tags:
- { name: kernel.event_listener, event: create_notification_item_resource-icap_wiki-section_create, method: onCreateNotificationItem }
- { name: kernel.event_listener, event: create_notification_item_resource-icap_wiki-contribution_create, method: onCreateNotificationItem }
- { name: kernel.event_listener, event: create_notification_item_resource-icap_wiki-contribution_create, method: onCreateNotificationItem }
- { name: kernel.event_listener, event: create_notification_item_resource-icap_wiki-user_tagged, method: onCreateNotificationItem }
1 change: 1 addition & 0 deletions Resources/translations/notification.en.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
resource-icap_wiki-contribution_create: contributed to '%section%' section of '%wiki%' wiki
resource-icap_wiki-section_create: created a '%section%' to '%wiki%' wiki
resource-icap_wiki-user_tagged: tagged you in '%section%' section of '%wiki%' wiki
3 changes: 2 additions & 1 deletion Resources/translations/notification.fr.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
resource-icap_wiki-contribution_create: a contribué a la section '%section%' du '%wiki%' wiki
resource-icap_wiki-section_create: a creé la section '%section%' dans '%wiki%' wiki
resource-icap_wiki-section_create: a creé la section '%section%' dans '%wiki%' wiki
resource-icap_wiki-user_tagged: vous a cité dans la section '%section%' du '%wiki%' wiki
2 changes: 2 additions & 0 deletions Resources/views/Notification/notification_item.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@
{% include 'IcapWikiBundle:Notification:notification_section_create.html.twig' %}
{% elseif constant('Icap\\WikiBundle\\Event\\Log\\LogContributionCreateEvent::ACTION') == notification.actionKey %}
{% include 'IcapWikiBundle:Notification:notification_contribution_create.html.twig' %}
{% elseif 'resource-icap_wiki-user_tagged' == notification.actionKey %}
{% include 'IcapWikiBundle:Notification:notification_user_tagged.html.twig' %}
{% endif %}
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<a href="{{ path('icap_wiki_view', {'wikiId' : notification.details.resource.id}) ~ '#section-' ~ notification.details.contribution.section }}">{{ notification.actionKey|trans({'%wiki%' : notification.details.resource.name, '%section%' : notification.details.contribution.title}, 'notification') }}</a>

0 comments on commit 6349f99

Please sign in to comment.