Reporting allows 3rd party application / module provider 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 is 3 main steps that needs 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::_('CC REPORT BAD USER') , 'profile,reportProfile' , array( $user->id ) );
  • JText::_('CC 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::_('CC 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 .

Creating method that will be 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::_('CC 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.

Join 180,000 websites creating Amazing communities

JomSocial is the most complete, easy-to-use addon that turns Joomla CMS into a
full -fledged, social networking site

TRY NOW BUY NOW