Some developers who integrate their components with Touch may want to add activities of the users in their component to Touch activity stream (Wall). It is very simple.
<?php $API = JPATH_ROOT.DS.'components'.DS.'com_community'.DS.'api.php'; if(file_exists($API)) { require_once $API; if($params->get('activity_add_something') && $user->get('id')) { $text = "Added <a href='/something/new.html'>Something</a>"; $icon = 'components/com_somthing/images/activity/'. $params->get('activity_icon'); JSCommunityApi::registerActivity(0, $text, $user->get('id'), $icon, 'user', null, 'com_resource', '', 'Somthing'); } } ?>
First we check if the api.php file exists, and thus also check if component is installed. There is of course other neat way of checking if component is installed like JComponentHelper::isEnabled(‘com_community’) but what if api file somehow is not there? Then it produce fatal error. So we found that this is most reliable way of checking component presence.
After we check, require file and creating Touch API class we start adding activity.
What is if($params->get('activity_add_something') && $user->get('id'))?
Actually it is not needed in the code. You may immediately call registerActivity() but this is just an idea for you. If you have more than one activity type or only one type you may consider to add parameters to your component configuration and allow your customers to chose what activity to register and what activity not. And even set their own icon in line where $icon is defined. I did not add it to example but in some cases also would be smart to allow user to define what would be the text of activity.
Here explanation of registerActivity() parameters
- $client - should be always 0 (unless your component integrated with Touch groups)
- $text – text of activity is any HTML text.
- $user_id – ID of the user who act this activity
- $icon – full path from Joomla root, to image that will be shown as icon of that activity
- $client - should be always ‘user’ (unless your component integrated with Touch groups)
- $ctime – time of registering an activity. If null will be current time.
- $component – name of your component. If null will be name of the current component
- $params – Not yet used but may be used in future. You may save params in string INI format. Later it is planned to be used on activity list.
- $type – Is a type of activity. On activity stream (example) on the right top you can see drop down with list of activity types. So you need to insert some text that will create category for your activities. You may create the same type for few different activities that is similar, or set different type for every activity.
Note, do not use JText::_() for type text. It will be passed through JText when needed.

+1 (209) 800 1209