Jump to content

Developer Documentation

core/StreamItems

What it is

The StreamItems extension allows an application to add "extra items" to stream results. While content stored in the search index (which includes content item data) is automatically returned in activity streams, if you want to show other data such as users signing up in an application or users performing another action  in an application in activity streams, you will need to use a StreamItems extension to accomplish this.

Calendar uses this functionality to show when a user has RSVP'd for an event in activity streams, for example.

How to use

The extension will define a single method where you will fetch and return extra stream results

 

    /**
     * Is there content to display?
     *
     * @param    \IPS\Member|NULL    $author        The author to limit extra items to
     * @param    Timestamp|NULL    $lastTime    If provided, only items since this date are included. If NULL, it works out which to include based on what results are being shown
     * @param    Timestamp|NULL    $firstTime    If provided, only items before this date are included. If NULL, it works out which to include based on what results are being shown
     * @return    array Array of \IPS\Content\Search\Result\Custom objects
     */
    public function extraItems( $author=NULL, $lastTime=NULL, $firstTime=NULL )
    {
        // Note!
        // Your application must define a setting and a language string in the format of "all_activity_{application}_{extensionname}" all in lower case. Without this, this plugin will not be executed.
        // This setting will automatically be used to store the administrators choice of whether to show this data or not.

    }
        return array();

You need to define a specific language string as shown in the code comment above for the extension to process, however otherwise this is all you need.

If the content is being limited by author, the $author parameter will be set to an \IPS\Member object, otherwise it will be set to NULL. Similarly, $lastTime and $firstTime may be set to timestamps or may be set to NULL ($lastTime will typically be set, however). You will then fetch any results that match the parameters supplied, and create an array of \IPS\Content\Search\Result\Custom objects to return.

    /**
     * Is there content to display?
     *
     * @param    \IPS\Member|NULL    $author        The author to limit extra items to
     * @param    Timestamp|NULL    $lastTime    If provided, only items since this date are included. If NULL, it works out which to include based on what results are being shown
     * @param    Timestamp|NULL    $firstTime    If provided, only items before this date are included. If NULL, it works out which to include based on what results are being shown
     * @return    array Array of \IPS\Content\Search\Result\Custom objects
     */
    public function extraItems( $author=NULL, $lastTime=NULL, $firstTime=NULL )
    {
        $results = array();
        $where = array( array( 'date>?', $lastTime ) );
        if ( $firstTime )
        {
            $where[] = array( 'date<?', $firstTime );
        }
        if ( $author )
        {
            $where[] = array( 'author_id=?', $author->member_id );
        }
        foreach ( \IPS\Db::i()->select( '*', 'my_table', $where, 'date DESC', 10 ) as $row )
        {
            $results[] = new \IPS\Content\Search\Result\Custom( \IPS\DateTime::ts( $row[ 'date' ] ), \IPS\Member::loggedIn()->language()->addToStack( 'some_language_string' ) );
        }
        return $results;
    }

 


  Report Document


×
×
  • Create New...