Jump to content

Community

Developer Documentation

core/Notifications

What it is

The Notifications extension class allows your application to define new types of notifications that can be sent (and which users can configure how to receive), as well as process those notifications to define the values shown to users who have received such notifications.

How to use

When you create the extension, two methods will be present which you should define.

    /**
     * Get configuration
     *
     * @param    \IPS\Member    $member    The member
     * @return    array
     */
    public function getConfiguration( $member )
    {
        // Basically just return a list of the keys for the types of notification your app will send
        // keys can be anything you want. You can specify what should be the default value and any disabled values (acceptable values are "email" and "inline")
        // For each key, create a language string "notifications__<key>" which is what will display in the user's Notification Options screen
        
        return array(
            'key'    => array( 'default' => array( 'email' ), 'disabled' => array() ),
        );
    }

The comment in the above method outlines what you will need to do in the getConfiguration() method. Your extension should return an array with the keys as the notification keys and the value being an array defining which methods should be disabled and which methods should be enabled by default.

    /**
     * Parse notification: key
     *
     * @param    \IPS\Notification\Inline    $notification    The notification
     * @return    array
     * @code
     return array(
         'title'        => "Mark has replied to A Topic",    // The notification title
         'url'            => \IPS\Http\Url::internal( ... ),    // The URL the notification should link to
         'content'        => "Lorem ipsum dolar sit",            // [Optional] Any appropriate content. Do not format this like an email where the text
                                                             //      explains what the notification is about - just include any appropriate content.
                                                             //      For example, if the notification is about a post, set this as the body of the post.
         'author'        =>  \IPS\Member::load( 1 ),            // [Optional] The user whose photo should be displayed for this notification
     );
     * @endcode
     */
    public function parse_key( \IPS\Notification\Inline $notification )
    {
        return array(
            'title'        => "Mark has replied to A Topic",    // The notification title
            'url'            => \IPS\Http\Url::internal( ... ),    // The URL the notification should link to
            'content'        => "Lorem ipsum dolar sit",            // [Optional] Any appropriate content. Do not format this like an email where the text
                                                                //      explains what the notification is about - just include any appropriate content.
                                                                //      For example, if the notification is about a post, set this as the body of the post.
            'author'        =>  \IPS\Member::load( 1 ),            // [Optional] The user whose photo should be displayed for this notification
        );
    }

For each 'key' defined previously, you will need to create a method "parse_{key}" to process notification data for that notification type. The method will accept an instance of \IPS\Notification\Inline and then return an array with keys 'title', 'url', 'content' and 'author' as appropriate.

To send the notification, in your code you will create a new instance of \IPS\Notification, attach one or more recipients, and then send the notification.

$notification = new \IPS\Notification( \IPS\Application::load('myapp'), 'key', $this->item(), array( $this ) );
$notification->recipients->attach( $member );
$notification->send();


  Report Document


×
×
  • Create New...