Difference between revisions of "Using CjForum activity stream"

From CjWiki
Jump to navigation Jump to search
 
(3 intermediate revisions by the same user not shown)
Line 2: Line 2:
 
== Prerequisites: ==
 
== Prerequisites: ==
 
Add the required CjForum API library:
 
Add the required CjForum API library:
<syntaxhighlight lang="php">require_once JPATH_ROOT.'/components/com_cjforum/lib/api.php';</syntaxhighlight>
+
<pre>require_once JPATH_ROOT.'/components/com_cjforum/lib/api.php';</pre>
  
 
Now get the Stream API:
 
Now get the Stream API:
<syntaxhighlight lang="php">$streamApi = CjForumApi::getStreamApi();</syntaxhighlight>
+
<pre>$streamApi = CjForumApi::getStreamApi();</pre>
  
 
== Creating rules XML file ==
 
== Creating rules XML file ==
 
A rules xml file needs to be created with all rules which you would like to provide with your component. An example of the rules xml file is:
 
A rules xml file needs to be created with all rules which you would like to provide with your component. An example of the rules xml file is:
  
<syntaxhighlight lang="xml">
+
<pre>
 
<?xml version="1.0" encoding="UTF-8"?>
 
<?xml version="1.0" encoding="UTF-8"?>
 
<cjforum>
 
<cjforum>
Line 23: Line 23:
 
</activity_type>
 
</activity_type>
 
</cjforum>
 
</cjforum>
</syntaxhighlight>
+
</pre>
  
 
Save this file as '''administrator/components/com_mycomponentname/cjforum_rules.xml'''. You can package the xml file with your component so that it will be automatically installed along with your component. After installing the file, users can scan for rules and the rules will automatically gets installed. The same xml file may contain multiple activity rules as well as points rules.
 
Save this file as '''administrator/components/com_mycomponentname/cjforum_rules.xml'''. You can package the xml file with your component so that it will be automatically installed along with your component. After installing the file, users can scan for rules and the rules will automatically gets installed. The same xml file may contain multiple activity rules as well as points rules.
Line 38: Line 38:
 
== Syntax: push ==
 
== Syntax: push ==
 
Full Syntax of the push API call:
 
Full Syntax of the push API call:
<syntaxhighlight lang="php">push($activity)</syntaxhighlight>
+
<pre>push($activity)</pre>
  
; $stream - object:
+
; $activity - object:
 
: an object with following properties.
 
: an object with following properties.
 
* $activity->type -> activity type, e.g. com_cjforum.newtopic
 
* $activity->type -> activity type, e.g. com_cjforum.newtopic
Line 55: Line 55:
  
 
An example function call to push an activity
 
An example function call to push an activity
<syntaxhighlight lang="php">$streamApi->push($activity);</syntaxhighlight>
+
<pre>$streamApi->push($activity);</pre>

Latest revision as of 03:46, 8 August 2019

Prerequisites:

Add the required CjForum API library:

require_once JPATH_ROOT.'/components/com_cjforum/lib/api.php';

Now get the Stream API:

$streamApi = CjForumApi::getStreamApi();

Creating rules XML file

A rules xml file needs to be created with all rules which you would like to provide with your component. An example of the rules xml file is:

<?xml version="1.0" encoding="UTF-8"?>
<cjforum>
	<activity_type>
		<name>com_cjforum.topic_reply</name>
		<appname>com_cjforum</appname>
		<title>Reply to a topic</title>
		<description>Activity about new topic reply.</description>
		<state>1</state>
		<access>1</access>
		<language>*</language>
	</activity_type>
</cjforum>

Save this file as administrator/components/com_mycomponentname/cjforum_rules.xml. You can package the xml file with your component so that it will be automatically installed along with your component. After installing the file, users can scan for rules and the rules will automatically gets installed. The same xml file may contain multiple activity rules as well as points rules.

Explanation

  • <name> - A unique name to your rule
  • <appname> - extension name, e.g. com_cjforum
  • <title> - title shown for activity detail
  • <description> - brief description of the activity rule
  • <state> - default state of the rule when it is installed. set 1 to publish state, 0 for unpublished state
  • <access> - access level of this rule, awarded to users only if his access level satisfies. 1 for public user.
  • <language> - default language of this activity, set to * for all languages.

Syntax: push

Full Syntax of the push API call:

push($activity)
$activity - object
an object with following properties.
  • $activity->type -> activity type, e.g. com_cjforum.newtopic
  • $activity->title -> title of the activity
  • $activity->description -> description of the activity
  • $activity->userId -> optional, user who's activity is being added.
  • $activity->featured -> optional, is this featured?
  • $activity->language -> optional, language
  • $activity->itemId -> optional, activity attached to an item
  • $activity->parentId -> optional, parent id of this item_id
  • $activity->length -> optional, description length

Examples:

An example function call to push an activity

$streamApi->push($activity);