PHP code example of jeffersonsimaogoncalves / cakephp-notifier

1. Go to this page and download the library: Download jeffersonsimaogoncalves/cakephp-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/ */

    

jeffersonsimaogoncalves / cakephp-notifier example snippets


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

    $notificationManager->notify([
        'users' => ['7be18ce3-94e6-476a-870d-a0108d1697b7', 'c72da51b-16c8-4741-8646-2e45721b3277'],
        'recipientLists' => ['administrators'],
        'template' => 'newBlog',
        'vars' => [
            'username' => 'Bob Mulder',
            'name' => 'My great new blogpost'
        ]
    ]);

    $notificationManager->addRecipientList('administrators', ['7be18ce3-94e6-476a-870d-a0108d1697b7', 'c72da51b-16c8-4741-8646-2e45721b3277','7be18ce3-94e6-476a-870d-a0108d1697b4', 'c72da51b-16c8-4741-8646-2e45721b3272']);

    $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 c72da51b-16c8-4741-8646-2e45721b3272
    $this->Notifier->getNotifications('c72da51b-16c8-4741-8646-2e45721b3272');
    
    // getting a list of all unread notifications
    $this->Notifier->allNotificationList('c72da51b-16c8-4741-8646-2e45721b3272', true);

    // getting a list of all read notifications
    $this->Notifier->allNotificationList('c72da51b-16c8-4741-8646-2e45721b3272', 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 c72da51b-16c8-4741-8646-2e45721b3272
    $this->Notifier->countNotifications('c72da51b-16c8-4741-8646-2e45721b3272');
    
    // getting a number of all unread notifications
    $this->Notifier->countNotificationList('c72da51b-16c8-4741-8646-2e45721b3272', true);

    // getting a number of all read notifications
    $this->Notifier->countNotificationList('c72da51b-16c8-4741-8646-2e45721b3272', false);

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

    // mark all notifications of the given user as read
    $this->Notifier->markAsRead(null, 'c72da51b-16c8-4741-8646-2e45721b3272');

    // 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('JeffersonSimaoGoncalves/Notifier.Notifier');
    }