Jump to content

Community

Developer Documentation

Hiding/approving content with Content Items

Content Items can be hidden to non-staff members. This can be used to require staff approval before content can be viewed, and as a way for staff members to hide undesirable content.

 

How to implement hiding and approving

To support featuring content items in your application, you first need to implement the interface in your content item model:

implements \IPS\Content\Hideable

Next, add either a hidden or approved key to your $databaseColumnMap property, with the value being the name of the database column that stores the hidden status of your items.

Optionally, you can also add approved_by and approved_date to store some additional metadata about the action.

Next, you need to add support to your templates. For example:

{{if $item->canHide()}}
	<li><a href='{$item->url()->setQueryString( array( 'do' => 'moderate', 'action' => 'hide' ) )}'>{lang="hide"}</a></li>
{{endif}}
{{if $item->canUnhide()}}
	<li><a href='{$item->url()->setQueryString( array( 'do' => 'moderate', 'action' => 'unhide' ) )}'>{{if $item->hidden() ===
1}}{lang="approve"}{{else}}{lang="unhide"}{{endif}}</a></li>
{{endif}}

 

Overriding default moderated content behavior

If a user is configured to have their content approved, their content will be hidden by default automatically. You may want to override the method that handles this so, for example you can make certain nodes have all content posted to them require approval. To do this, override the moderateNewItems() method - for example:

public static function moderateNewItems( \IPS\Member $member, \IPS\Node\Model $container = NULL )
{
	if ( $container and $container->bitoptions['moderation'] and !static::modPermission( 'unhide', $member, $container ) )
	{
		return TRUE;
	}
	
	return parent::moderateNewItems( $member, $container );
}

 

Values stored for hidden status

When checking the hidden status of an item, there are three possible values; they depend on whether your model uses hidden or approved in the $databaseColumnMap.

Element Value if hidden
(normal, default)
Value if hidden
(and was previously unhidden)
Value if pending approval
hidden 0 -1 1
approved 1 -1 0

 

Changes after implementation

  • canView() will return FALSE for an item that is hidden if the member cannot view hidden items. This will also cause loadAndCheckPerms() to throw an OutOfRange exception if such an object is loaded.
  • Hidden items will only show to users who have permission to view hidden content.
  • Users with appropriate moderator permission will see tools to lock/unlock in content item tables.
  • Users who are set to have all new content moderated will have their content hidden until it is manually approved.

 

Additional model methods available

integer hidden()

Returns the status of the item: 

  • -1 indicates the content is now hidden, but was previous unhidden (i.e. it has changed state)
  • 0 indicates the content is unhidden (the default status)
  • 1 indicates the content is hidden and was automatically set as hidden at the time of posting (i.e. it hasn't changed state)

 

boolean canHide( [ \IPS\Member $member ] )

Indicates whether the user can hide the content item. This method takes into account whether the item is already hidden.

  • $member (\IPS\Member, optional)
    The member whose permissions will be used when checking. By default, the currently-logged in member will be used.

 

boolean canUnhide( [ \IPS\Member $member ] )

Indicates whether the user can unhide the content item. This method takes into account whether the item is already visible.

  • $member (\IPS\Member, optional)
    The member whose permissions will be used when checking. By default, the currently-logged in member will be used.

 

boolean static canViewHiddenItems( [ \IPS\Member $member ] )

Indicates whether the user can view hidden items. To check this permission for an individual item, use the canView() method of the item.

  • $member (\IPS\Member, optional)
    The member whose permissions will be used when checking. By default, the currently-logged in member will be used.

  Report Document


×
×
  • Create New...