Skip to content

dmolineus/contao-notification_center

This branch is 486 commits behind terminal42/contao-notification_center:main.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Aug 18, 2015
9ae0c47 · Aug 18, 2015
Aug 4, 2014
Jun 19, 2015
Jul 7, 2015
Jul 7, 2015
Jul 7, 2015
Jul 6, 2015
Aug 12, 2015
Jun 16, 2014
Oct 17, 2013
Jul 7, 2015
Aug 18, 2015
Jul 8, 2015

Repository files navigation

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 93.8%
  • JavaScript 5.7%
  • Other 0.5%