GithubHelp home page GithubHelp logo

qzminski / contao-notification_center Goto Github PK

View Code? Open in Web Editor NEW

This project forked from terminal42/contao-notification_center

0.0 0.0 0.0 919 KB

The most popular notification configuration extension for the Contao Open Source CMS!

JavaScript 7.11% PHP 92.38% CSS 0.51%

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
    }
}

Queue

It is possible to save the messages in a queue before sending them. The queue is available as a gateway. The queue can be processed via a "Poor man cron" or via a console call - see https://github.com/terminal42/contao-notification_center/blob/main/bin/queue

$ queue -s <queue_gateway_id> -n <number of messages to be sent>

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;
    }
}

Community Extensions

Note to self

Managing translations files.

  1. Install transifex client.

  2. tx pull -a to fetch updated translations.

contao-notification_center's People

Contributors

toflar avatar aschempp avatar qzminski avatar richardhj avatar dmolineus avatar davidmaack avatar fritzmg avatar rabauss avatar zonky2 avatar loilo avatar tristanlins avatar bennyborn avatar cliffparnitzky avatar bytehead avatar defcon0 avatar philvdb avatar patrickjde avatar ameotoko avatar bezin 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.