Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The following attachment describe a notification message about friend request acceptance.Image Removed

!https://docs.phpfox.com/download/attachments/851993/notification-example.png?api=v2

Notification item is stored at phpfox_notification table, look in to the table, there are following columns

...

As same as Feed service, Developers do not insert data into this table, they use notification service instead.

Code Block
php
php


Phpfox::getService('notification.process')->add($sType, $iItemId, $iOwnerUserId, $iSenderUserId = null, $force = false);

...

Following section show you how to integrate with comment, like, share.

Integration Feed Comment

Update Callback service, edit 2 following 3 methods

Code Block
php
php
     // this callback method is required by comment service
    public function addComment($aVals)
    {
        // update total comment
        $this->database()
            ->updateCounter('todolist_task', 'total_comment', 'task_id',
                $aVals['item_id']);

        // send notification
        if ($aVals['user_id'] != $aVals['comment_user_id']) {
            Phpfox::getService('notification.process')
                ->add('comment_todolisttodo', $aVals['item_id'], $aVals['user_id']);
        }
    }

    // this method is require to retry comment notification item
    public function getCommentNotification($aNotification)
    {
        // fetch item
        $aRow = $this->database()
            ->select('b.task_id, b.name, b.user_id, u.gender, u.full_name')
            ->from(Phpfox::getT('todolist_task'), 'b')
            ->join(Phpfox::getT('user'), 'u', 'u.user_id = b.user_id')
            ->where('b.task_id = ' . (int)$aNotification['item_id'])
            ->execute('getSlaveRow');

        // validate to do list item
        if (!isset($aRow['task_id'])) {
            return false;
        }

        // get user name
        $sUsers = Phpfox::getService('notification')->getUsers($aNotification);

        // to do list title
        $sTitle = $aRow['name'];

        // get translate message
        $sMessage = _p('User user_comment _on _to _do _title', [
            'users'         => $sUsers,
            'row_full_name' => $aRow['full_name'],
            'title'         => $sTitle,
        ]);

        // get link
        $url = Phpfox::getLib('url')
            ->permalink('to-do-list.view', $aRow['task_id'], $aRow['name']);

        return [
            'link'    => $url,
            'message' => $sMessage,
            'icon'    => '',
        ];
    }

In phrase.json, add following phrase:

Code Block
php
php
"user_comment_on_to_do_title": "{users} commented on your todo \"{title}\""

Create another account, use new account to comment on to do list feed.

logged Logged in back to the account which posted to do item.
Click on notification panel, the result is similar to attachment.

Image RemovedImage Added

Next Chapter