How to create Addons for JSPC

Swati Goyal , 19 February, 2010

In JSPC 2.0 some addons are already added so that you can make any number of rule on them. But there may be some other addon on which you want to calculate completeness. So here is article, which describes how to create a new Addon. Just follow these steps.
<div>
    Note:  All addon are stored at  Administrator //
    components  // com_jspc //  addons location
</div>

<div>
    Lets try to create a plugin, to motivate user to add at least 5
    friends.
</div>
#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
<ul style="color: #333333; font-family: Tahoma, Helvetica, Arial, sans-serif; font-size: 12px; line-height: 15.800000190734863px;"><li><em>friends</em>.php</li>

    <li><em>friends</em>.xml</li>
</ul><div>
    #3 : Copy below mentioned code into friends.xml file.
</div>
<pre lang="xml" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; line-height: 15.800000190734863px; margin: 8px;" xml:lang="xml">





<div>
    Imp : You can add any number of parameters here. we have added only one
    parameter.
</div>

<div>
    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.
</div>

<div>
    #4 : Copy below mentioned code into friends.php file.
</div>
<pre lang="php" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; line-height: 15.800000190734863px; margin: 8px;" xml:lang="php">

// 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;
}
}

<div>
    #5 : Change the link in
    function <em>getCompletionLink</em> to the link to which you
    want to redirect the user when he he/she clicks on link to complete
    his/her profile.
</div>

<div>
    #6 : Change the query in function calculateCount as according to you
    which fulfils your criteria.
</div>

<div>
    #7 : Here is new Addon ready to use.
</div>

<div>
    It was all about create a simple rule with only one parameter. If you
    want to develop more advanced addon then please refer
    our <strong>profilefields</strong> addon. It will be very
    helpful to create more advanced addons. You can override any behavior.
</div>

<div>
    Imp : Please share your addon to community, if you find any beautiful
    application of this addon.
</div>
blog comments powered by Disqus