PHP code example of antoine37120 / notifier

1. Go to this page and download the library: Download antoine37120/notifier library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

antoine37120 / notifier example snippets


    $notificationManager->addTemplate('newBlog', [
        'title' => 'New blog by :username',
        'body' => ':username has posted a new blog named :name'
    ]);

    $notificationManager->notify([
        'users' => [1, 2],
        'recipientLists' => ['administrators'],
        'template' => 'newBlog',
        'vars' => [
            'username' => 'Bob Mulder',
            'name' => 'My great new blogpost'
        ]
    ]);

    $notificationManager->addRecipientList('administrators', [1,2,3,4]);

    $notificationManager->notify([
        'recipientLists' => ['administrators'],
    ]);

    // getting a list of all notifications of the current logged in user
    $this->Notifier->getNotifications();

    // getting a list of all notifications of the user with id 2
    $this->Notifier->getNotifications(2);
    
    // getting a list of all unread notifications
    $this->Notifier->allNotificationList(2, true);

    // getting a list of all read notifications
    $this->Notifier->allNotificationList(2, false);

    // getting a number of all notifications of the current logged in user
    $this->Notifier->countNotifications();

    // getting a number of all notifications of the user with id 2
    $this->Notifier->countNotifications(2);
    
    // getting a number of all unread notifications
    $this->Notifier->countNotificationList(2, true);

    // getting a number of all read notifications
    $this->Notifier->countNotificationList(2, false);

    // mark a single notification as read
    $this->Notifier->markAsRead(500;

    // mark all notifications of the given user as read
    $this->Notifier->markAsRead(null, 2);

    // returns true or false
    $entity->get('unread');
    
    // returns the full output like 'Bob Mulder has posted a new blog named My Great New Post'
    $entity->get('body');

    $this->set('notifications', $this->Notifier->getNotifications());

    NotificationManager::instance();

    public function initialize()
    {
        parent::initialize();
        $this->loadComponent('Bakkerij/Notifier.Notifier');
    }