ReportOptions

This class is responsible for setting all the necessary options for any report you generate. These options include the data source (table or SQL query), data filters, layout, style, column customization options, header, footer, conditional formatting options, security options, and more. Instances of this class are created by calling the 'New' operator, and the methods can be chained together to define all the required report options. To use this class, you need to import it, as shown in the following examples.

# Example Native PHP

 
          
use SRE\Engine\CustomEngine;           
use SRE\Engine\ReportOptions;
require_once  "../sre_bootstrap.php";
try{
$report = new ReportOptions(SRE_PUBLIC_REPORT);
$report->select_tables(array("items"))
      ->set_grouping(array("country"))
      ->select_all_fields();
$engine = new CustomEngine($report);
$report_path = $engine->create_report();
 echo "Your report URL:" . $report_path;
}catch (Exception $ex) {
 echo "Caught exception message:  ".  $ex->getMessage();
}
          

# Example Laravel

 
          
            namespace App\Services;
 
            use Sre\SmartReportingEngine\src\Engine\Constants;
            use Sre\SmartReportingEngine\src\Engine\CustomEngine;
            use Sre\SmartReportingEngine\src\Engine\ReportOptions;

            class ReportService {

                public function generatePublicReport() {
                    try{
                    $report = new ReportOptions(Constants::SRE_PUBLIC_REPORT);
                    $report->select_tables(array("items"))
                           ->set_grouping(array("country"))
                           ->select_all_fields();
                    $engine = new CustomEngine($report);
                    $report_path = $engine->create_report();
                    echo "Your report URL:" . $report_path;
                    }catch (Exception $ex) {
                      echo "Caught exception message:  ".  $ex->getMessage();
                    }                   

                }
            }

          
Method Description
__constructThis method is the class constructor, it's called when an instance of the 'ReportOptions' class is created! Additionally, it initializes the new instance with the access mode of the report, the data source, and the report name.
sub_totalsThis function adds subtotals to your report to get the sum, average, minimum, maximum, or count of any column(s) for each group of records. Additionally, at the end of the report, grand totals should be listed.
sort_byThis method is used for sorting the report that you want to generate by any given column in it. This can be done either in an ascending or descending order based on the value of the order parameter, which if omitted, the ascending order will be used.
set_titleThis is one of the appearance customization methods supported in Smart Report Engine. It allows you to add a title for your report that should appear in the header area of your report.
set_style_nameThis is one of the appearance customization methods supported in Smart Report Engine. It sets the style of your report which can be "blue", "grey", "teal", or "mobile". Please be aware that your users can change the report's style from within the report.
set_sqlIf you are creating a SQL-based report, you need to call this method to define the SQL query you want to use for your report. Please note that the data source is defined when calling the 'ReportOptions' class constructor, where there is only two available options table-based data source "SRE_Table" and SQL-based data source "SRE_SQL"
set_records_per_pageThis method sets the number of records per page in the generated reports. The default value is 25 records per page. Your generated report will have a pager to navigate through pages, additionality it will have the ability to print and export a single page or all pages.
set_mysql_hostnameThis method is used only if you want to override the default MYSQL connection hostname, stored in the engine's configuration file, in the generated report.
set_mysql_db_nameThis method is used only if you want to override the default MYSQL database name, stored in the engine's configuration file, in the generated report.
set_mysql_connection_usernameThis method is used only if you want to override the default MYSQL connection username, stored in the engine's configuration file, in the generated report.
set_mysql_connection_passwordThis method is used only if you want to override the default MYSQL connection password, stored in the engine's configuration file, in the generated report.
set_layoutThis is one of the appearance customization methods supported in Smart Report Engine. It sets the layout of your report, which can be "AlignLeft", "Block", "Stepped", "Outline", "Horizontal" or "mobile". Please be aware that your users can change the report's layout from within the report menu.
set_languageThis method defines the language of your generated report. Smart Report engine supports six languages which are: "en", "de", "ar", "es", "fr" and "it". Smart Report Engine language files can be found at : "/sre_reports/shared/languages/".
set_headerThis is one of the appearance customization methods supported in Smart Report Engine. It allows you to add a custom header for your report.
set_groupingUsing Smart Report Engine, you can generate reports with multiple grouping levels; for example, you could group your report by Country and then by City to get more informative results. This method defines the grouping levels of the report that you want to generate.
set_footerThis is one of the appearance customization methods supported in Smart Report Engine. It allows you to add a footer for your report that should appear in the footer area of your report.
set_chksearchThis method is used to show or hide the search box in the generated report if its data source is table-based. Please note that the search capabilities are supported only in table-based reports. So, no need to call this method with SQL-based reports
select_tablesSmart Report Engine supports two report data sources, which are: 1- Table-based data source (the default data source ): The report is based on one or more MYSQL tables. 2- SQL-based data source: The report is based on a SQL query. You should use this data source if you want to convert some queries to reports. Usually, the report data source is defined when calling the 'ReportOptions' class constructor. So, If you are creating a table-based report, you need to call this method to define the table(s) you want to use for your report. You can select one or more tables.
select_fieldsThis method should be used if you want to show only some columns of the selected table(s) in your report. Therefore, you should either call this method or the “select_all_fields” method (which shows all columns). But, If both methods are called for generating the same report, the latter method will override the former.
select_all_fieldsThis method should be used if you want to show all columns ( of the selected tables ) in your report. Therefore, you should either call this method or the “select_fields” method (which shows only selected columns). But, If both methods are called for generating the same report, the latter method will override the former.
security_initThis security method should be used to set the main security parameters for private reports. These security parameters are the login page to which the engine should redirect any unauthorized users, the logout page to which the engine should redirect users when they click the "logout" link on the report's menu and the session name which is used in your project. If any of these parameters are omitted, their default values, which you can find in the engine configuration file will be used. This method should only used for private reports, and after calling it, you should call one or more of the session verification methods to define all the session validations that you want Smart Report Engine to perform before allowing any access to your private report.
security_check_session_saved_user_keyThis is one of the session verification methods, it configures your report to check whether or not the session of the user (who is trying to access it) has a given key (such as the active user-id) and if this key does not exist in the session, the user should be redirected to the login page that you passed to the "security_init" method. So, this method is meant to be helpful if you are using a login page in your project, for validating the login credentials of each user, and if these credentials are valid, you store a certain key (probably, the active user_id) in the session, and you want Smart Report Engine to only allow users whose sessions have this key to access your report.
security_check_session_saved_ip_keyThis is one of the session verification methods that should be used only with private reports! It configures your report to check both the existence of a given session key and its value which should be equal to the IP address of the active user. If this session validation fails, the user should be redirected to the login page that you passed to the "security_init" method.
security_check_session_saved_group_keyThis is one of the session verification methods for private reports! It configures your report to check both the existence of a given session key (such as the active user's group or group id) and its value which should be an element in the "$allowed_group_array" parameter. This method should be used if your project supports user groups, and you choose to allow only certain groups to access your report. So, in your login page, and after validating the login credentials of each user, you store the active user's group or group id in the session, and you want Smart Report Engine to check this key and allow only the users of the allowed group(s) to be able to access your private report. Like other session verification methods of Smart Report Engine, if this session validation fails, the user should be redirected to the login page that you passed to the "security_init" method.
security_check_session_saved_exact_value_keyThis is one of the session verification methods that should be used only with private reports! This method configures your report to check both the existence of a given session key and its value which should be equal to the "$correct_value" parameter. If this session validation fails, the user should be redirected to the login page that you passed to the "security_init" method.
security_check_session_saved_exact_data_type_keyThis is one of the session verification methods that should be used with private reports! This method sets your report to check both the existence of a given session key and its value's data type which should be equal to the "$correct_data_type" parameter. If this session validation fails, the user should be redirected to the login page that you passed to the "security_init" method.
labelThis method gives a label to any given column in your report to make it friendly, using an alias rather than its original SQL name. If you want to give labels to many columns in your report, you will have to call this method many times as shown in the example below.
format_suffix_text_to_columnThis is one of the appearance customization methods supported in Smart Report Engine. It attaches any text you want as a suffix to all records in any column of your report. For example, adding °F or °C to a temperature column.
format_rating_columnThis is one of the appearance customization methods supported in Smart Report Engine. It displays a certain column in your report as stars rating! So, it is meant to be helpful, if you apply a five-point rating scale and are saving the ratings in a numeric data type column in your MYSQL database and you want to show this column in your report as stars ratings.
format_prefix_text_to_columnThis is one of the appearance customization methods supported in Smart Report Engine. It attaches any text you want as a prefix to all records in any column of your report. For example, adding an "$" to a price column.
format_link_columnThis is one of the appearance customization methods supported in Smart Report Engine. It displays a column in your report as clickable hyperlinks! This method is meant to be helpful if you have URLs stored in columns in your MYSQL database and you want to show this column in your report as clickable hyperlinks.
format_image_columnThis is one of the appearance customization methods supported in Smart Report Engine. It displays any certain column(s) in your report as clickable image thumbnails. When clicking on one of these images a lightbox will popup whereby your visitor can view the clicked image with its actual size. This method is meant to be helpful if you have a column in your MYSQL database for storing names or paths of some images and you want to display these actual images in your report instead.
format_country_flag_columnThis is one of the appearance customization methods supported in Smart Report Engine. It displays small country flags beside their names! This method meant to be helpful if you have countries stored in a column in your MYSQL database and you want to show the flags of these countries besides their names in your report. This should look nice especially if you are grouping your report by country.
format_check_box_columnThis is one of the appearance customization methods supported in Smart Report Engine. It displays a certain column in your report as checkboxes! This method is meant to be helpful if you have a boolean, bit or tiny-int column in your MYSQL database for storing 0, 1 values or true, false values and you want to show this column in your report as checkboxes where checked means true or 1 and unchecked means 0 or false.
filter_not_nullThis is one of the filter functions. Applying this function on any column should return records with NO null values in this filtered column.
filter_not_likeThis filter should be used with a string data type column to get the data that is not like a certain string parameter value. Please note that you can combine multiple filters for the same report.
filter_not_equalThis filter should be used with a numeric or DateTime column to get the data that is not equal to a certain parameter value. Please note that you can combine multiple filters for the same report.
filter_more This filter should be used with a numeric or DateTime column to get the data that is higher than a certain parameter value. Please note that you can combine multiple filters for the same report.
filter_likeThis filter should be used with a textual data type column to get the data that is like a certain textual parameter value. Please note that you can combine multiple filters for the same report.
filter_lessThis filter should be used with a numeric or DateTime column to get the data that is less than a certain parameter value. Please note that you can combine multiple filters for the same report.
filter_is_todayThis is one of the dynamic date filters. Applying this function on any date-type column should return records of the current day which is very helpful if you want to create daily reports.
filter_is_nullThis is one of the data-filtration functions. Applying this function on any column should return records with null values in this filtered column.
filter_is_current_yearThis is one of the dynamic date filters. Applying this function on any date-type column should return records of the current year which is very helpful if you want to create an annual report.
filter_is_current_monthThis is one of the dynamic date filters. Applying this function on any date-type column should return records of the current month which is very helpful if you want to create a monthly report.
filter_is_current_active_userThis data filtration function should filter any report by the current user ID so that each logged-in user sees only their records. In other words, this function should make each user sees only their records even when multiple users are accessing the exact same report. In the following code example, any logged-in user when accessing the "orders" report, should see only the records related to them. Smart Report Engine should implements this by querying the "Orders" table with a where clause for filtering the "Employee_id" column by the value of the "user_id" session key which Smart Report Engine will expect to find in the logged-in user's PHP session. Please note that usually, on logging in, any session-based login system stores some reference identifying the user (often the user's ID) in their PHP session.
filter_equalThis filter should be used with a numeric or DateTime column to get the data that is equal to a certain parameter value. Please note that you can combine multiple filters for the same report.
filter_betweenThis is one of the many filters supported in the Smart Report Engine to filter your report by the data of any column in it. And, you can combine many filters in the same report. This method filters any specific column between two numbers or two dates.
dynamic_filter_not_equalThis is one of the dynamic filters supported in the Smart Report Engine to filter your report by parameters entered by your end users. In other words, your end users can change the output of generated reports based on the parameter values they enter before previewing the reports. For example, using this type of filter you can easily create a sales per region report where each end user can select the regions they don't want to see. And, you can combine many filters in the same report. This filter should be used to filter any column you specify and return all records that are not equal to the filter parameter entered by each end user. Please note that you can combine multiple filters for the same report.
dynamic_filter_moreThis is one of the dynamic filters supported in the Smart Report Engine to filter your report by parameters entered by your end users. In other words, your end users can change the output of generated reports based on the parameter values they enter before previewing the reports. For example, using this type of filter you can easily create a performance report where each end user can set certain indicators. This method should be used with a numeric, date, or DateTime column to get all records that are more than the parameter entered by each end user. Please note that you can combine multiple filters for the same report.
dynamic_filter_lessThis is one of the dynamic filters supported in the Smart Report Engine to filter your report by parameters entered by your end users. In other words, your end users can change the output of generated reports based on the parameter values they enter before previewing the reports. For example, using this type of filter you can easily create a performance report where each end user can set certain indicators. This method should be used with a numeric, date, or DateTime column to get all records that are less than the parameter entered by each end user. Please note that you can combine multiple filters for the same report.
dynamic_filter_equalThis is one of the dynamic filters supported in the Smart Report Engine to filter your report by parameters entered by your end users. In other words, your end users can change the output of generated reports based on the parameter values they enter before previewing the reports. For example, using this type of filter you can easily create a sales per region report where each end user can select the region they want to see. And, you can combine many filters in the same report. This method filters any specific column by a parameter entered by your end user. So all you need to specify is just the column you want to filter and the table containing it.
dynamic_filter_betweenThis is one of the dynamic filters supported in the Smart Report Engine to filter your report by parameters entered by your end users. In other words, your end users can change the output of generated reports based on the parameter values they enter before previewing the reports. For example, using this type of filter you can easily create a sales report by date range where each end user can define the date range they want to see. And, you can combine many filters in the same report. This method filters any specific column between two numbers or two dates entered by the end user(s) of the report. Therefore, all you need to specify is just the filtered column and the table containing it. You don't need to specify filter values, this will be done by your end user in a dialogue box before displaying the report.
conditional_format_not_equalThis method changes the background color of any cells in a given column to any color you like if the values of these cells are not equal to a given parameter.
conditional_format_moreThis method changes the background color of any cells in a given column to any color you like if the values of these cells are more than a given parameter.
conditional_format_lessThis method changes the background color of any cells in a given column to any color you like if the values of these cells are less than a given parameter.
conditional_format_equalThis method changes the background color of any cells in a given column to any color you like if the values of these cells are equal to a given parameter.
conditional_format_end_withThis method changes the background color of any cells in a given column to any color you like if the values of these cells end with a given sub-string parameter.
conditional_format_containThis method changes the background color of any cells in a given column to any color you like if the values of these cells contain a given sub-string parameter.
conditional_format_betweenThis is one of the many conditional formatting methods in Smart Report Engine, which are used to change the background color of any column cells based on their values. This method highlights the background of any cells in any given column, with any selected color, if their values lie between a lower and an upper bound.
conditional_format_begin_withThis method changes the background color of any cells in a given column to any color you like if the values of these cells begin with a given sub-string parameter.
check_session_saved_client_agent_keyThis is one of the session verification methods that should be used only with private reports! This method configures your report to check both the existence of a given session key and its value which should be equal to the active user's user agent, which should be obtained using the PHP variable $_SERVER['HTTP_USER_AGENT']. If this session validation fails, the user should be redirected to the login page that you passed to the "security_init" method.
calculatedcolumnsCalculated columns are virtual columns that are not physically stored in your database table Instead, their values are calculated from one or more other columns. In each generated report by Smart Report Engine, you should find a configuration file named “calculated_columns.php”. This file is for configuring any number of calculated columns needed for any report generated by Smart Report Engine. You can find this file at: /{Smart-Report-Engine-PATH}/SRM8/SRM/Reports8/rep{report-name}/calculated_columns.php where: {Smart-Report-Engine-PATH}: The path in which you uploaded Smart Report Engine on your local or remote server. {report-name}: Your generated report's name. Inside the "calculated_columns.php" configuration file, you should find the "$calculated_columns" predefined array. In this array, you can define each calculated column you want to add to your report along with the method to calculate it as shown in the code example below. In the following code snippet, we define one calculated column “total_price” and linked it to the function that should be used to calculate its value. Please note that the value of any calculated column is calculated by the function linked to it and which should accept only one parameter “$row” which represents any row in the report. Therefore if we need to include any column in the calculation formula we should refer to that column as $row[“name_of_the_column”] For example, $row[“unit_price”]. Once we save the calculated_column.php file changes and refresh the browser we should be able to see the calculated columns displayed in the report.
add_relationshipThis method defines the relationship between any two tables. Therefore, It should be used for reports that are based on multiple tables.