Getting started

Getting started with the Smart Report Engine Community Edition is incredibly easy. To directly download the community edition of Smart Report Engine Please use the link below.

Download The Community Edition

If you're using Composer, you have the alternative option of employing the following Composer command:

 
							
 composer create-project webuccinoco/sre-community
  				
							

Getting started with Smart Report Engine

What's downloaded?


After downloading, extract the compressed folder to reveal the structure of SmartReportEngine. The contents will resemble something similar to the following:
 
							

    ├── SmartReportingEngine/
    ├── sre_config/
       └── config.php
    ├── sre_reports/
    ├── db/       
      └── example.sql
    ├── examples/
    └── sre_bootstrap.php
  				
							

Getting Started with Smart Report Engine: Your First Project


Step 1: To initiate your first project on your server, you need to import a sample MySQL database. This process will enable you to get started with Smart Report Engine smoothly.
  • Inside the downloaded package of Smart Report Engine, locate the "/db/example.sql" file in the "db" directory. This SQL file contains the necessary commands to create and populate a single MySQL table named 'items'.
  • Select the MySQL database for your first project setup.You can opt for an existing database or create a new one specifically for this project.
  • Import the "example.sql" file into your chosen MySQL database. This will create the "items" table and populate it with initial data.
Step 2: Configure the database Connection String
  • Navigate to the "sre_config" directory within the Smart Report Engine Community Edition package. There, you will find the "config.php" file. Please open this file using any text editor you prefer.
  • In the "config.php" file, you will find a section dedicated to database configuration. Update the connection string with the appropriate details of the MySQL database where you imported the example SQL file during Step 1. Make sure to provide the correct hostname, database name, username, and password in their respective fields.
  • Save the changes to the "config.php" file.
Step 3: Coding!

In the Community Edition's "/examples" directory, you'll find three helpful examples to get you started with Smart Report Engine. To execute any of these examples, just access their URLs from your web browser. This will enable you to view the generated report based on the code in each example. Should you prefer to build the example projects from scratch, kindly proceed with the next step of the installation process.Regardless of your choice, the code walkthrough sections will provide explanations for the code in each example.

To begin writing your first project, you'll require a new PHP script. For the purpose of this tutorial, you can add the script to the root directory of the community edition, alongside the "sre_bootstrap.php" file. If you've obtained the community edition through manual download (without utilizing Composer), you'll have to include the autoload file "sre_bootstrap.php" in your code, as shown in the example below. Conversely, if Composer has been employed, you'll have to include the Composer autoloader file "vendor/autoload.php". It's important to consider that if your code resides in a location other than the root directory, you must appropriately modify the path to the autoload file. Please follow these steps to get started with your project:

  • Create a new PHP script for your project.
  • Optionally, place the script in the root directory of the community edition (same level as "sre_bootstrap.php") for this tutorial's purpose.
  • In your first new project, try writing the following simple PHP code. It should work without any issues.

								
use SRE\Engine\CustomEngine;
use SRE\Engine\ReportOptions;

require_once "sre_bootstrap.php"; //require 'vendor/autoload.php' incase of using composer
 

try {
     
    $report = new ReportOptions();
    $report->select_tables("items")
            ->set_grouping("country")
            ->set_title("Items Per country")
            ->select_all_fields();
    $engine = new CustomEngine($report);
    $report_path = $engine->create_report();
    if ($report_path) {
       // The user will be redirected to the URL of the generated report. All generated reports are stored as subdirectories under /sre_reports.
       header("location: ".$report_path);
       exit();
    }
} catch (Exception $e) {
    echo $e->getMessage();
}

Code Walkthrough: Understanding the Example


The given code demonstrates a basic example of using Smart Report Engine effectively. Let's walk through the code step by step to understand how it functions:

  • Namespaces: The given code utilizes two namespaces, "SRE\Engine\CustomEngine" and "SRE\Engine\ReportOptions." These namespaces help organize and access specific parts of the code.
  • Requiring "sre_bootstrap.php": If you manually downloaded the community edition (without using Composer), you need to add a special file called "sre_bootstrap.php" to your code.
  • Creating the ReportOptions Object: The code initializes an object from the "ReportOptions" class. This object is responsible for defining the options needed for your report. You can customize various options, keeping in mind that some features are exclusive to the commercial edition.
  • Passing ReportOptions Object to CustomEngine: Once you have set your report options, you pass the "ReportOptions" object to the constructor of the "CustomEngine" class. This class handles the creation of your report based on the provided options.
  • Calling CreateReport Function: To generate your report, you call the "CreateReport" function using the "CustomEngine" object. This function processes the defined options and generates the report. Upon successful creation, it returns the URL of the report. All the reports generated using Smart Report Engine will be automatically saved in the "sre_reports" directory.

More Examples




use SRE\Engine\CustomEngine;
use SRE\Engine\ReportOptions;

require_once "sre_bootstrap.php";

try {
     
    $report = new ReportOptions();
    $report->select_tables("items")
            ->set_grouping("country")
            ->sort_by("country", 1)
            ->filter_like("category", "sunglasses")
            ->filter_between("price", 15, 50)
            ->filter_more("rating", 3.5)
            ->filter_not_null("code")
            ->set_title("Using data filters")
            ->select_fields(array("id","code","name","price","reorder_level","units_in_stock","category","country","rating"));
    $engine = new CustomEngine($report);
    $report_path = $engine->create_report();
    if ($report_path) {
       // The user will be redirected to the URL of the generated report. All generated reports are stored as subdirectories under /sre_reports.
       header("location: ".$report_path);
       exit();
    }
} catch (Exception $e) {
    echo $e->getMessage();
}

In the code example provided earlier, we applied additional methods to the "items" table, enabling us to achieve the following:

  • Combining specific data filter methods to extract records and display a report based on selected criteria.
  • Sorting and grouping the report by country in descending order.
  • Instead of displaying all columns from the table, we chose to select only specific columns to be shown in the report.





use SRE\Engine\CustomEngine;
use SRE\Engine\ReportOptions;

require_once "sre_bootstrap.php";

try {
     
    $report = new ReportOptions();
    $report->select_tables("items")
            ->set_grouping(array("category","country"))
            ->sort_by("category",1)          
            ->filter_between("price", 15, 50)
            ->filter_more("rating", 3.5)
            ->filter_not_null("code")
            ->set_filters_grouping("or")
            ->set_chkSearch(false)
            ->select_fields(array("id","code","name","price","reorder_level","units_in_stock","category","country","rating"))
            ->set_style_name("grey")
            ->set_records_per_page(25)
            ->set_language("es")
            ->set_title("Items Per category")
            ->set_header("Here is some HTML code that you can use to customize the header of the report.");
    $engine = new CustomEngine($report);
    $report_path = $engine->create_report();
    if ($report_path) {
       // The user will be redirected to the URL of the generated report. All generated reports are stored as subdirectories under /sre_reports.
       header("location: ".$report_path);
       exit();
    }
} catch (Exception $e) {
    echo $e->getMessage();
}

In the previously provided code example, we demonstrated a two-level grouping, showcasing Smart Report Engine's ability to support multiple grouping levels. Additionally, we modified the data filters to be grouped using the "or" logic.

Moreover, we performed some appearance customization by changing the report theme and changing the report interface language. This is especially useful if the report data is in a language other than English, as it allows the report interface to align with the data language. Smart Report Engine supports English, French, Spanish, German, Arabic, and Italian by default and other languages could be easily added.

Furthermore, we enhanced the report's presentation by adding a title, header, and footer sections. Additionally, we changed the default number of records displayed per page for better usability.

Lastly, we disabled the ordinary and advanced search features for this particular generated report, tailoring the report's functionalities to specific requirements.

If you face any issues while installing or using Smart Report Engine, refer to this troubleshooting guide.

Community Edition License


The Community Edition permits you to:

  • Experiment with Smart Report Engine (Non-Premium features only).
  • Freely utilize Smart Report Engine for personal use.
  • Freely integrate Smart Report Engine into free open-source projects as long as you keep our copyright claims.

The Community Edition restricts you from:

  • Accessing Premium features.
  • Integrating Smart Report Engine into commercial or SaaS projects.
  • Removing the "Powered by" claim from reports generated by the community edition of Smart Report Maker.

Please note that By using any of our commercial editions you are granted access to all premium features, as well as the removal of all community restrictions mentioned above.