Jump to content

Developer Documentation

Supporting polls in Content Items

By implementing polls in your application, members will be able to attach a poll when creating a new content item. The process is automatic; a new tab will be displayed on the create item form that allows the poll to be managed


How to implement polls

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

implements \IPS\Content\Polls

Next, add a poll key to your $databaseColumnMap with the value being the name of the database column that stores the poll ID for this item (note, you can only have one poll per content item).

Finally, display the poll in your content item view. For example:



Performing additional actions after receiving a vote

Optionally, your model can be notified when a member votes on a poll. To add support for this, you first need to implement the SPL Observer:

implements \SplObserver

In your model, add an update method, which will be called when a poll receives a vote:

void update( \IPS\Poll $poll )
  • $poll (\IPS\Poll)
    The poll that has been voted on.

Finally, when displaying your content item, attach the item to the poll. For example:

if ( $poll = $item->getPoll() )
	$poll->attach( $item );


Additional model methods available

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

Indicates whether the member can create a poll.

  • $member (\IPS\Member, optional)
    The member whose permissions should be checked. By default, the currently-logged in member will be used.
  • $container (\IPS\Node\Model, optional)
    Specifically checks whether polls can be created in this container.


\IPS\Poll getPoll()

Returns the poll for this item (or NULL if no poll is attached).

  Report Document

  • Create New...