Jump to content

Developer Documentation

Implementing read markers in Content Items

Content read markers allow members to easily see which content items they've viewed through the use of a small icon in the content list view. They are a standard feature of the IPS Community Suite, and you should implement them if your application deals with user-generated content in any way.

 

How to implement read marking

First, your content item model needs to implement the read marking interface, like so:

implements \IPS\Content\ReadMarkers

Next, you should add a key to the $databaseColumnMap property of your model. The key(s) you should use depends on other features you might implement, but in all cases the value should be the name of the database column that stores the timestamp for the associated action.

  • Add an updated key
  • Add a last_comment key if you are using comments
  • Add a last_review key if you are using reviews

Finally, make sure that when a user views the item, the read marking is accounted for. In your controller's manage() method, ensure you call the parent's method:

parent::manage();

Or, manually call $item->markRead() to trigger the marking action.

 

Additional model methods available

Note: in order to use the containerUnread() and markContainerRead() methods shown below, your container node model must have implemented the following methods. See the container nodes guide for more information.

  • get__items()
  • get__comments()
  • setLastComment()
  • getLastCommentTime()

 

boolean static containerUnread\IPS\Node\Model $container [, \IPS\Member $member ] )

Indicates whether the specified container (including children) has any unread content for the member.

  • $container (\IPS\Node\Model, required)
    The container to check.
  • $member (\IPS\Member, optional)
    The member whose read status should be checked. By default, the currently-logged in member will be used.

 

void static markContainerRead\IPS\Node\Model $container [, \IPS\Member $member [, boolean $children ] ] )

Marks the container (and optionally, children) as read.

  • $container (\IPS\Node\Model, required)
    The container to mark read.
  • $member (\IPS\Member, optional)
    The member whose read status should be changed. By default, the currently-logged in member will be used.
  • $children (boolean, optional, default TRUE)
    Should children of $container be marked as read too?

 

integer unread( [ \IPS\Member $member ] )

Returns an integer indicating the read status of the item. Return values are:

  • 0 if the item is read
  • -1 if the item is unread and has never been read
  • 1 if the item is unread but has previously been read (i.e. there has been new activity since the last read). Only applies if comments are used.

 

  • $member ( \IPS\Member, optional )
    The member whose read status should be checked. By default, the currently-logged in member will be used.

 

void markRead( [ \IPS\Member $member [, integer $time [, mixed $extraContainerWhere ] ] ] )

Marks an item as read.

  • $member (\IPS\Member, optional)
    The member whose read status should be updated. By default, the currently-logged in member will be used.
  • $time (integer, optional)
    The timestamp to to set as 'last read'. By default, or if NULL is passed, the current time will be used.
  • $extraContainerWhere (mixed, optional)
    An array or string containing additional WHERE clauses to be passed into the underlying query.

 

\IPS\DateTime timeLastRead( [ \IPS\Member $member ] )

Returns a DateTime object indicating the last time the item was read by the member (or NULL if it hasn't been read yet)

  • $member (\IPS\Member, optional)
    The member whose last read time should be returned. By default, the currently-logged in member will be used.

  Report Document


×
×
  • Create New...