Coder Social home page Coder Social logo

contao-notification_center's Introduction

Notification Center

The purpose of this extension is to provide a central and flexible way for Contao developers to send notifications via their extensions.

If we can get this extension to be widely used, users will quickly get used to the way one can configure the notification center.

Translating

The notification center can be translated via Transifex: https://www.transifex.com/projects/p/notification_center

Adding your own notification type

// config.php
$GLOBALS['NOTIFICATION_CENTER']['NOTIFICATION_TYPE']['isotope'] = array
(
    // Type
    'iso_order_status_change'   => array
     (
        // Field in tl_nc_language
        'recipients'    => array
        (
            // Valid tokens
            'recipient_email' // The email address of the recipient
        ),
        'attachment_tokens'    => array
        (
            'form_*', // All the order condition form fields
            'document' // The document that should be attached (e.g. an invoice)
        )
    )
);

Sending a notification

Extension developers most likely want to send a single notification identified by ID,:

$objNotification = NotificationCenter\Model\Notification::findByPk($intNotificationId);
if (null !== $objNotification) {
    $objNotification->send($arrTokens, $strLanguage); // Language is optional
}

If you want to send all notifications of a certain type, you can send it like this:

$strType = 'iso_order_status_change';
$objNotificationCollection = NotificationCenter\Model\Notification::findByType($strType);
if (null !== $objNotificationCollection) {
    while ($objNotificationCollection->next()) {
        $objNotification = $objNotificationCollection->current();
        $objNotification->send($arrTokens, $strLanguage); // Language is optional
    }
}

Hooks

If you want to enrich each message being sent by some meta data or want to disable some messages being sent, you can use the sendNotificationMessage hook:

// config.php
$GLOBALS['TL_HOOKS']['sendNotificationMessage'][] = array('MyHook', 'execute');

// The hook
class MyHook
{
    public function execute($objMessage, $arrTokens, $language, $objGatewayModel)
    {
         if (!$objMessage->regardUserSettings || !FE_USER_LOGGED_IN 
            || $objMessage->getRelated('pid')->type !== 'custom_notification') {
            return true;
         }
         
         $user = \MemberModel::findByPK($arrTokens['recipient']);     
         if (!$user || !$user->disableEmailNotifications) {
            return true;
         }
                      
         return false;
    }
}

Note to self

Updating language files:

Generating the en base folder:

$ ./vendor/bin/ctb to-xliff 

Pushing en to transifex:

$ ./vendor/bin/ctb download-transifex en

Downloading translations:

$ ./vendor/bin/ctb download-transifex --mode=translated

Storing the language files:

$ ./vendor/bin/ctb from-xliff

contao-notification_center's People

Contributors

toflar avatar aschempp avatar qzminski avatar dmolineus avatar davidmaack avatar richardhj avatar tristanlins avatar loilo avatar cliffparnitzky avatar defcon0 avatar

Watchers

James Cloos avatar Daniel W avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.