12.24. RLIB compatibility API #

12.24.1. Initialize a report
12.24.2. Destroy a report
12.24.3. Get library version
12.24.4. Add a MySQL/MariaDB datasource
12.24.5. Add a MySQL/MariaDB datasource from an INI group
12.24.6. Add a PostgreSQL datasource
12.24.7. Add an ODBC datasource
12.24.8. Add an array datasource
12.24.9. Add an XML datasource
12.24.10. Add a CSV datasource
12.24.11. Add a query
12.24.12. Add a resultset follower
12.24.13. Add a resultset N:1 follower
12.24.14. Set datasource encoding
12.24.15. Add a report XML
12.24.16. Add a report XML from buffer
12.24.17. Add a search path
12.24.18. Set locale
12.24.19. Setup translation
12.24.20. Set output format
12.24.21. Add a custom report function
12.24.22. Set output encoding
12.24.23. Add a report parameter
12.24.24. Set an output parameter
12.24.25. Refresh array query contents
12.24.26. Add an event callback
12.24.27. Execute the report
12.24.28. Dump the report output
12.24.29. Get content type
12.24.30. Set radix character
12.24.31. Compile and evaluate an expression
12.24.32. Add graph background region
12.24.33. Clear graph background region
12.24.34. Set graph minor tick
12.24.35. Set graph minor tick by location

These functions mimic the behaviour of the RLIB PHP API but their declaration differ in a way that the RLIB compatibility API in OpenCReports create and use OpenCReport objects, making the OpenCReports methods and RLIB compatibility functions inter-operable.

12.24.1. Initialize a report #

function
rlib_init(): ?OpenCReport;

Note that initializing the report using this function automatically enables some RLIB compatibility settings, like the output parameter "xml_rlib_compat".

12.24.2. Destroy a report #

function
rlib_free(OpenCReport $r): void;

12.24.3. Get library version #

function
rlib_version(void): string;

12.24.4. Add a MySQL/MariaDB datasource #

function
rlib_add_datasource_mysql(
                     OpenCReport $r,
                     string $source_name,
                     string $host,
                     string $user,
                     string $password,
                     string $dbname):
                     OpenCReport\Datasource;

This function is equivalent to using OpenCReport::datasource_add() with the MariaDB input driver with expanded connection parameters, but without specifying a custom port:

$o = new OpenCReport();

$conn_params = [
    "host" => "myserver",
    "dbname" => "ocrpttest",
    "user" => "ocrpt"
];

$ds = $o->datasource_add("mariadb", "mariadb", $conn_params);

12.24.5. Add a MySQL/MariaDB datasource from an INI group #

function
rlib_add_datasource_mysql_from_group(
                     OpenCReport $r,
                     string $source_name,
                     string $group,
                     ?string $option_file = null):
                     OpenCReport\Datasource;

This function is equivalent to using OpenCReport::datasource_add() with MariaDB input driver, using the option file and group parameters:

$o = new OpenCReport();

$conn_params = [
    "optionfile" => "./mariadb/ocrpt.cnf",
    "group" => "ocrpt"
];

$ds = $o->datasource_add("mariadb", "mariadb", $conn_params);

12.24.6. Add a PostgreSQL datasource #

function
rlib_add_datasource_postgres(
                     OpenCReport $r,
                     string $source_name,
                     ?string $connection_info = null):
                     OpenCReport\Datasource;

This function is equivalent to using OpenCReport::datasource_add() with the PostgreSQL input driver using the connection info string:

$o = new OpenCReport();

$conn_params = [ "connstr" => "dbname=ocrpttest user=ocrpt" ];

$ds = $o->datasource_add("pgsql", "postgresql", $conn_params);

12.24.7. Add an ODBC datasource #

function
rlib_add_datasource_odbc(
                     OpenCReport $r,
                     string $source_name,
                     string $dbname,
                     ?string $user, = null,
                     ?string $password = null):
                     OpenCReport\Datasource;

This function is equivalent to using OpenCReport::datasource_add() with the ODBC input driver with expanded connection parameters:

$o = new OpenCReport();

$conn_params = [
    "dbname" => "mydb",
    "user" => "myuser"
];

$ds = $o->datasource_add("odbc", "odbc", $conn_params);

12.24.8. Add an array datasource #

function
rlib_add_datasource_array(
                     OpenCReport $r,
                     string $source_name):
                     OpenCReport\Datasource;

This function is equivalent to using OpenCReport::datasource_add() with the array input driver:

$o = new OpenCReport();

$ds = $o->datasource_add("array", "array");

12.24.9. Add an XML datasource #

function
rlib_add_datasource_xml(
                     OpenCReport $r,
                     string $source_name):
                     OpenCReport\Datasource;

This function is equivalent to using OpenCReport::datasource_add() with the XML input driver:

$o = new OpenCReport();

$ds = $o->datasource_add("xml", "xml");

12.24.10. Add a CSV datasource #

function
rlib_add_datasource_csv(
                     OpenCReport $r,
                     string $source_name):
                     OpenCReport\Datasource;

This function is equivalent to using OpenCReport::datasource_add() with the CSV input driver:

$o = new OpenCReport();

$ds = $o->datasource_add("csv", "csv");

12.24.11. Add a query #

This function is equivalent to OpenCReport\Datasource::query_add() with a different order of parameters. The query name is the last parameter.

function
rlib_add_query_as(
                     OpenCReport $r,
                     string $source_name,
                     string $array_or_file_or_sql,
                     string $name):
                     OpenCReport\Datasource;

12.24.12. Add a resultset follower #

This function is about equivalent to OpenCReport\Query::add_follower(). The $leader and $follower are query names.

function
rlib_add_resultset_follower(
                     OpenCReport $r,
                     string $leader,
                     string $follower): bool;

12.24.13. Add a resultset N:1 follower #

This function is about equivalent to OpenCReport\Query::add_follower_n_to_1(). The former allows an arbitrary match expression, while the RLIB compatibility function will use the $leader_field = $follower_field expression. Similarly to the above function, $leader and $follower are query names.

function
rlib_add_resultset_follower_n_to_1(
                     OpenCReport $r,
                     string $leader,
                     string $leader_field,
                     string $follower,
                     string $follower_field): bool;

12.24.14. Set datasource encoding #

This function is equivalent to OpenCReport\Datasource::set_encoding(). See Section 12.5.3

function
rlib_set_datasource_encoding(
                     OpenCReport $r,
                     string $name,
                     string $encoding): void;

12.24.15. Add a report XML #

This function is equivalent to OpenCReport::parse_xml().

function
rlib_add_report(
                     OpenCReport $r,
                     string $filename): bool;

12.24.16. Add a report XML from buffer #

This function is equivalent to OpenCReport::parse_xml_from_buffer().

function
rlib_add_report_from_buffer(
                     OpenCReport $r,
                     string $buffer): bool;

12.24.17. Add a search path #

This function is equivalent to OpenCReport::add_search_path().

function
rlib_add_search_path(
                     OpenCReport $r,
                     string $path): bool;

12.24.18. Set locale #

This function is equivalent to OpenCReport::set_locale().

function
rlib_set_locale(
                     OpenCReport $r,
                     string $locale): void;

12.24.19. Setup translation #

This function is equivalent to OpenCReport::bindtextdomain().

function
rlib_bindtextdomain(
                     OpenCReport $r,
                     string $domain,
                     string $dirname): void;

12.24.20. Set output format #

This function is about equivalent to OpenCReport::set_output_format() but accepts textual format names (like pdf instead of the numeric constants like OpenCReport::OUTPUT_PDF

function
rlib_set_output_format_from_text(
                     OpenCReport $r,
                     string $format): void;

12.24.21. Add a custom report function #

This function is the RLIB compatible variant of OpenCReport::function_add(). Unlike the OpenCReports API, the function added by this function does not have the control knobs to optimize it properly. After this function returns, subsequently parsed expressions may use a function name passed in with $name. The PHP function name is in $function

function
rlib_add_function(
                     OpenCReport $r,
                     string $name,
                     string $function,
                     long $params): void;

The interface of the PHP function must follow the below prototype. It must contain the exact number of arguments passed in via $params, i.e. it may not pass -1 to indicate variadic arguments.

function my_function($arg1, $arg2, ...)

The function implementation may return any PHP base type (string, long, double or bool).

12.24.22. Set output encoding #

This function silently does nothing. For PDF, it's not relevant. Other (CURRENTLY NOT IMPLEMENTED) output formats will all use UTF-8.

function
rlib_set_output_encoding(
                     OpenCReport $r,
                     string $encoding): void;

12.24.23. Add a report parameter #

This function is equivalent to OpenCReport::set_mvariable().

function
rlib_add_parameter(
                     OpenCReport $r,
                     string $param,
                     ?string $value = null): void;

12.24.24. Set an output parameter #

Set output parameters for the report. For accepted parameters, see Section 12.3.6

function
rlib_set_output_parameter(
                     OpenCReport $r,
                     string $param,
                     string $value): void;

12.24.25. Refresh array query contents #

This function is equivalent to executing OpenCReport::query_refresh(). The same limitations apply.

function
rlib_query_refresh(OpenCReport $r): void;

12.24.26. Add an event callback #

This function adds a callback for the specified $signal in an RLIB compatible way. The signal name may be row_change, report_done, report_start, report_iteration, part_iteration or precalculation_done.

function
rlib_signal_connect(
                     OpenCReport $r,
                     string $signal,
                     string $function): void;

The PHP function prototype must follow this:

function my_callback()

This function is different from the methods that add specific callback types for parts, reports, breaks, etc. in that the callback is added to the toplevel OpenCReport object context, meaning that a report_start callback will be called for every report in case there are multiple reports in the same context. Similarly, the same part_iteration callback will be called for every part in a multi-part report.

Since there is no way to know which part or which report triggers the callback, it is recommended to use rlib_signal_connect() for single-part single-report reports. For more special purposes, the callback creation class methods are recommended.

12.24.27. Execute the report #

It is equivalent to OpenCReport::execute()

function
rlib_execute(OpenCReport $r): bool;

12.24.28. Dump the report output #

It is equivalent to OpenCReport::spool()

function
rlib_spool(OpenCReport $r): ?string;

12.24.29. Get content type #

It is equivalent to OpenCReport::get_content_type()

function
rlib_get_content_type(OpenCReport $r): ?string;

12.24.30. Set radix character #

This function silently does nothing. Formatting numbers correctly follow the locale information regarding the decimal separator.

function
rlib_set_radix_character(OpenCReport $r): void;

12.24.31. Compile and evaluate an expression #

function
rlib_compile_infix(string $expr_string):
                     string|double|null;

Since only the expression string is passed but not the $r resource in RLIB, the compatibility implementation of this function is equivalent to the sequence of creating an internal OpenCReport object, parsing, optimizing and evaluating the expression, converting its result to a PHP base type, then destroying the internal object. For this reason, the expression may not reference any query columns or report variables.

12.24.32. Add graph background region #

This function silently does nothing. GRAPHING IS NOT IMPLEMENTED YET.

function
rlib_graph_add_bg_region(
                     OpenCReport $r,
                     string $graph,
                     string $region,
                     string $color,
                     double $start,
                     double $end): void;

12.24.33. Clear graph background region #

This function silently does nothing. GRAPHING IS NOT IMPLEMENTED YET.

function
rlib_graph_clear_bg_region(
                     OpenCReport $r,
                     string $graph): void;

12.24.34. Set graph minor tick #

This function silently does nothing. GRAPHING IS NOT IMPLEMENTED YET.

function
rlib_graph_set_x_minor_tick(
                     OpenCReport $r,
                     string $graph,
                     string $x): void;

12.24.35. Set graph minor tick by location #

This function silently does nothing. GRAPHING IS NOT IMPLEMENTED YET.

function
rlib_graph_set_x_minor_tick_by_location(
                     OpenCReport $r,
                     string $graph,
                     double $location): void;