Page tree
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Next »

Notification Service

When a member post a comment, accept invitation requests, like an items, a message/email will be sent to owner to tell about the status changed,
The behind service handle these message is Notification.

The following attachment describe a notification message about friend request acception.

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

  • notification_id: notification identity, auto incrementation.
  • type_id: type if of relevant item
  • item_id: item id of relevant item
  • user_id: who send the notification?
  • owner_user_id: target owner id
  • is_seen: Notification is seen?
  • time_stamp: creation time

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

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

When others post comments, like, share a to do list item, phpFox will use callback mechanist to tell an application would to like
to send the owner a notification.

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

Integration Feed Comment

Update Callback service, edit following 3 methods

    // this callback method is required by comment service
    public function addComment($aVals)
        // update total comment
            ->updateCounter('todolist_task', 'total_comment', 'task_id',

        // send notification
        if ($aVals['user_id'] != $aVals['comment_user_id']) {
                ->add('comment_todolist', $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.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'])

        // 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 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'    => '',

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

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

Next Chapter

  • No labels