Custom Statistics Panels

The Concrete5 Traffic & Statistics package, from version 2.12, allows other package and block developers to integrate their own stats display panels directly on the stats page of the dashboard.

Just follow these steps:

1) Create a new folder than will hold you panel's files, like /packages/my_package_name/stats_panel/

2) In that folder create a view.php file and a controller.php file

3) You controller's class must be named according to your panel's directory, and must extend the ParticleTrafficPanel class. So if it's placed within a folder called /my_package_statistics/, then it should have the class named MyPackageStatisticsParticleTrafficPanel. Here's an example:

class MyPackageStatisticsParticleTrafficPanel extends ParticleTrafficPanel {
     protected $title="My Package Stats";
     public function view(){
         //optional - place any initiation logic here
     }
}

4A) Automatic installation:

Just copy your folder into the /packages/tony_stats/panels/ directory, then visit the stats settings page. It will notify you if there are any errors with your package.

4B) Programatic Installation:

To register your new panel with the traffic and stats from within another package or application, add these lines to your code (not in the panel's view or controller) to include the required libraries:

Loader::helper('stats',$packageHandle);
Loader::model('panel',$packageHandle);

…then register the panel by giving it the absolute file path to your panel's directory.

$urlHelper = Loader::helper('concrete/urls');
$packageHandle='my_package_handle';
$statsPkg = Package::getByHandle($packageHandle);
$absoluteFilePath = $urlHelper->getPackageURL($statsPkg).'/stats_panel/';
$result = self::registerPanel( $absoluteFilePath );

The $result['msg'] will contain an error message if it detects any problems with your panel.

5) Your package should now be displayed on the main stats page.

Like this post?
Tweet This

Enjoy this post?

Comments:

Add a New Comment
(will not be made public)
(optional)

Please type the letters and numbers shown in the image.Captcha Code