jimmytournemaine/notification-bundle

This package is abandoned and no longer maintained. No replacement package was suggested.

Notification system integration

dev-master 2016-09-05 22:39 UTC

This package is not auto-updated.

Last update: 2020-12-25 23:02:21 UTC


README

#Installation

SensioLabsInsight

##Step 1: Download the Bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

$ composer require jimmytournemaine/notification-bundle "master"

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

##Step 2: Enable the Bundle

Then, enable the bundle by adding it to the list of registered bundles in the app/AppKernel.php file of your project:

<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...
            new JT\NotificationBundle\NotificationBundle(),
        );

        // ...
    }

    // ...
}
```

##Step 3: Routing

# app/config/routing.yml

jt_notification:
    resource: "@JTNotificationBundle/Resources/config/routing.yml"

##Step 4: Link your user entity

# app/config/config.yml

doctrine:
    orm:
        resolve_target_entities:
            JT\NotificationBundle\Model\NotifyableInterface: AppBundle\Entity\User

Step 5: Update your database

php bin/console doctrine:schema:update --force

Create your notification type

<?php
namespace AppBundle\Notification\Type;

use JT\NotificationBundle\Builder\NotificationBuilderInterface;
use JT\NotificationBundle\Notification\Type\AbstractType;

class PostType extends AbstractType
{

    public function buildNotification(NotificationBuilderInterface $builder, array $options)
    {
        $builder
            ->addIcon('bell', array(
                'type' => 'icon',
                'prefix' => 'fa',
                'alt' => '+'
            ))
            ->addTitle('notification.post.title', array(
                'trans_parameters' => array('%name%' => 'Jimmy')
            ))
            ->addDescription('notification.post.description', array(
                'trans_domain' => "MyDomain"
            ))
            ->addLink('homepage', array(
                'type' => 'route'
            ))
            ->addUsers($options['users'])
        ;
    }
}

#Send your notification

$this->get('jt_notification.helper')->send(PostType::class, $options, $users);

#Display the user's notifications

{% if is_granted('IS_AUTHENTICATED_REMEMBERED') %}
    {{ jt_notification_render() }}
{% endif %}

#Override the rendering

You can edit the rendering of your notifications by override JTNotification::macros.html.twig like it is described in the Symfony documentation