Below is a step-by-step walkthrough of how to create your own custom BrilliantRetail report. Download report.sample.php which is a duplicate of the code featured in this document. To create your own report simply create a new file named report.Your_report_class.php and in that file add a new class that extends the Brilliant_retail_report class as shown below.
Example Report
class Report_report_name extends Brilliant_retail_report { public $title = '##Report Title##'; public $descr = '##Report Description##'; public $category = '##Report Categorisation##'; #(Options: sales, customers, products, general) public $version = 1.0; public $date_range = ''; function get_report(){
This currently disables the Graphing objects for the report.
$graph='';
This creates a variable link to the module page.
$base_url = str_replace('&','&',BASE).'&C=addons_modules&M=show_module_cp&module=brilliant_retail';
Inputs for our report are passed in the following format :
Format (type, label, name)
Currently supported include:
If you do not want any options to display, simply create an empty array for the $input[] variable i.e. $input[] = array(); You will also need to comment the code immediately below which sets up the date variables.
$input[] = array('date','Select Date','date_range');
If there are values in the post array, we can use them. If you create your own post variables, access them from the following : $this->EE->input->post("field_name", TRUE)
$range_type = ($this->date_range == '') ? $this->EE->input->post("date_range", TRUE) : $this->date_range;
This converts your start and end dates into usable variables for your SQL statement.
if($range_type == '') { $range_type = 'week'; } if($range_type == 'custom') { $range["start"] = $this->EE->input->post("date_range_st", TRUE); $range["end"] = $this->EE->input->post("date_range_end", TRUE); }else{ $range = get_range($range_type); }
This is the header of the table and should contain your column headers
$header = array("Header Value","Header Value","Header Value");
This is where you perform your magic - you create your SQL to obtain whatever information you need here in this statement.
$query = $this->EE->db->query("PUT YOUR SQL STATEMENT IN HERE"); $result_array = $query->results_array();
This now loops through the results and generates a $results array to pass into the report. Replace $row['column'] with the name of the columns from your resulting SQL statement.
foreach($result_array as $row) { $results[] = array( $row['column'], $row['column'], $row['column'], $row['column'] ); }
This is the footer of your table, if you are creating a list and want to aggregate the totals in the footer, this is where you would pass this information.
$footer = array( '', '', '', '' );
This is where it now collates all the information that we've created and combines it into a $report array and passes it back to the parent call for rendering on the page.
$report = array( 'input' => $input, 'range' => $range, 'graph' => $graph, 'header' => $header, 'results' => $results, 'footer' => $footer ); return $report; } }