Difference between revisions of "OnCommunityStreamRender"

 
(One intermediate revision by the same user not shown)
Line 2: Line 2:
 
{{alert|<center>'''Note:''' This article is still work in progress</center>|alert}}
 
{{alert|<center>'''Note:''' This article is still work in progress</center>|alert}}
  
Used in the standard community plugin to gather data for creating activity stream item
+
Used in the standard community plugin to gather data for creating activity stream item<br/>
 +
More information and full guide can be [[Stream API v2|seen here]]
  
1) create a standart JomSocial plugin.
+
====Example====
 
+
<syntaxhighlight lang="php">
2) add onCommunityStreamRender function in the plugin. The function must be public.
+
    class plgCommunityExample extends CApplications
 
+
    {
3) Arrange the data according to this format:-
+
    public function onCommunityStreamRender($act)
 
+
    {
 
+
    $actor = CFactory::getUser($act->actor);
 
+
   
{
+
    $stream = new stdClass();
 
+
    $stream->actor = $actor;
//UserId
+
    $stream->headline = 'Headline';
 
+
    $stream->message = 'Message';
"actor":5,
+
    return $stream;
 
+
    }
//target id
+
    }
 
+
</syntaxhighlight>
"target": 6,
+
<br />
 
+
"message":"string",
+
 
+
"group" : "JTableGroup object",
+
 
+
"event" : "JTableEvent object",
+
 
+
"headline" : "string",
+
 
+
"location" : "Kuala Lumpur",
+
 
+
"attachments":
+
 
+
[
+
 
+
  {"type":"media"},
+
 
+
  {"type":"video", "id":0, "title":"", "description":"", "duration": "string"},
+
 
+
  {"type":"quote"}
+
 
+
]
+
 
+
 
+
 
+
PHP file of example plugin with code comments and explanations
+
 
+
//refer activities.videos.php file
+
 
+
$stream = new stdClass();
+
 
+
$stream->actor = $user;
+
 
+
$stream->target = null;
+
 
+
$stream->headline = CVideos::getActivityTitleHTML($act);;
+
 
+
$stream->message = "";
+
 
+
$stream->groupid = $act->groupid;
+
 
+
$stream->eventid = $act->eventid;
+
 
+
$stream->attachments = array();
+
 
+
if($act->groupid){
+
 
+
  $group    = JTable::getInstance( 'Group' , 'CTable' );
+
 
+
  $group->load( $act->groupid );
+
 
+
  $stream->group = $group;
+
 
+
}
+
 
+
$attachment = new stdClass();
+
 
+
$attachment->type = 'video';
+
 
+
$attachment->id = $act->cid;
+
 
+
$attachment->title = $video->title;
+
 
+
$attachment->thumbnail = $video->getThumbnail();
+
 
+
$attachment->description = $video->description;
+
 
+
$attachment->duration = CVideosHelper::toNiceHMS(CVideosHelper::formatDuration($video->getDuration()));
+
 
+
$stream->attachments[] = $attachment;
+
 
+
$quoteContent = CActivities::format($act->title);
+
 
+
if(!empty($quoteContent) && $param->get('style') == COMMUNITY_STREAM_STYLE){
+
 
+
  $attachment = new stdClass();
+
 
+
  $attachment->type = 'quote';
+
 
+
  $attachment->message = $quoteContent;
+
 
+
  $stream->attachments[] = $attachment;
+
 
+
}
+
 
+
$this->set('stream', $stream);
+
 
+
$this->load('activities.stream');
+

Latest revision as of 22:27, 24 April 2013

Since JomSocial 2.8
Note: This article is still work in progress

Used in the standard community plugin to gather data for creating activity stream item
More information and full guide can be seen here

Example

    class plgCommunityExample extends CApplications
    {
    public function onCommunityStreamRender($act)
    {
    $actor = CFactory::getUser($act->actor);
 
    $stream = new stdClass();
    $stream->actor = $actor;
    $stream->headline = 'Headline';
    $stream->message = 'Message';
    return $stream;
    }
    }