Reporting API

Reporting allows Third-Party application / module providers to generate a link that will allow guests / members to report against an item. The item here could refer to any object within the page. There are three (3) main steps that need to be done to achieve this,

Generate HTML Codes

Generate the 'HTML' codes and display it within your application / module.

// Load libraries
CFactory::load('libraries', 'reporting');
$report	 = new CReportingLibrary();
$html	 = $report->getReportingHTML( JText::_('COM_COMMUNITY_REPORT_BAD_USER') , 'profile,reportProfile' , array( $user->id ) );


JText::_('COM_COMMUNITY_REPORT_BAD_USER) - The first parameter here informs the library to display this text in the html codes.

profile,reportProfile - Second parameter informs the library to call the method to register your tasks. To register a call for plugins, you can use plugins,pluginname,method.

array( $user->id ) - Third parameter is the unique id that you are reporting against.

Registering the Report Action

/**
 * Method is called from the reporting library. Function calls should be
 * registered here.
 *
 * return	String	Message that will be displayed to user upon submission.
 **/
function reportProfile( $link, $message , $id )
{
	CFactory::load( 'libraries' , 'reporting' );
	$report = new CReportingLibrary();
 
	$report->createReport( JText::_('Bad user') , $link , $message );
	$action					= new stdClass();
	$action->label			= 'Block User';
	$action->method			= 'profile,blockProfile';
	$action->parameters		= $id;
	$action->defaultAction	= false;
 
	$report->addActions( array( $action ) );
 
	return JText::_('COM_COMMUNITY_REPORT_SUBMITTED');
}


For plugins, simply create the function in your plugin and the system will automatically call this method.

$action->method - To register a call for plugins, you can use plugins,pluginname,method

Create Method Executed by the Administrator

When the report item is added to the system, the administrator will then be able to perform the actions based on what you have parsed to the system. For an example, the 'block profile' method below, will block the user when the administrator clicks on the link.

/**
 * Function that is called from the back end
 **/	 	
function blockProfile( $userId )
{
	$user		=& CFactory::getUser( $userId );
	$user->set( 'block' , 1 );
	$user->save();
	return JText::_('COM_COMMUNITY_USER_ACCOUNT_BLOCKED');
}


The return value will be a normal string output which will be displayed to the administrator. For plugins, simply create the function in your plugin and the system will automatically call this method.