Feb
19

How to create Addons for JSPC

#1 : Create a folder with the name of addon (so that you can remember). Let say "friends".
#2 : Crete two files in the recently created folder friends
  • friends.php
  • friends.xml
#3 : Copy below mentioned code into friends.xml file.




Imp : You can add any number of parameters here. we have added only one parameter.
Imp : In the above code you have to give the name of parameter as "addonname_total". It is mandatory to give name like this for working of your addon.
#4 : Copy below mentioned code into friends.php file.
// no direct access
defined('_JEXEC') or die('Restricted access');

class friends extends jspcAddons
{

function __construct($debugMode)
{
parent::__construct(__CLASS__, $debugMode);
}

/*create link, to feature complete: e.g this addon, list users whom user can add as friends */
function getCompletionLink($userid)
{
$result = array();
$result['text']= $this->getDisplayText($userid); //JText::_("ADD ALBUM");
$result['link']="index.php?option=com_community&view=search&task=browse";
return $result;
}

/*Put the logic here to count user's completed count for the feature */
public function calculateCount($userid)
{
$db =& JFactory::getDBO();
$query = 'SELECT COUNT(*) '
. ' FROM ' . $db->nameQuote( 'jxi_community_connection' )
. ' WHERE `connect_from`=' . $db->Quote( $userid )
. ' AND `status`=1';

$db->setQuery( $query );
$count = $db->loadResult();
return $count;
}
}
#5 : Change the link in function getCompletionLink to the link to which you want to redirect the user when he he/she clicks on link to complete his/her profile.
#6 : Change the query in function calculateCount as according to you which fulfils your criteria.
#7 : Here is new Addon ready to use.
It was all about create a simple rule with only one parameter. If you want to develop more advanced addon then please refer our profilefields addon. It will be very helpful to create more advanced addons. You can override any behavior.
Imp : Please share your addon to community, if you find any beautiful application of this addon.
Author
/ / Category - JS-Addons / 1249 visits