The High level PHP API is also part of the low level API. The class methods described below allow creating a report using program code, or simply fine tuning the report behavior by mostly using the High level PHP API.
Note that whenever the method argument is
string $expr_string
,
such arguments are treated as
Expressions and are only
parsed when calling the method. Evaluation
of the expressions is delayed to report
execution time.
Also note that for class methods that return
objects, the parent object must not be
unset()
before using
such a derived object. These derived objects
are merely wrappers over C pointers in
their parent objects' C representation.
Such a "use after free" is a sure way to
crash the PHP process.
Set numeric precision
#The default is 256 bits of floating point precision.
public final OpenCReport::set_numeric_precision_bits( string $expr_string): void;
The rounding modes may be
nearest
,
to_minus_inf
,
to_inf
,
to_zero
,
away_from_zero
and
faithful
.
The default is nearest
.
final public OpenCReport::set_rounding_mode( string $expr_string): void;
Setting up the translation needs two parameters: the so called translation domain and the toplevel directory for the translations. It relies on GNU Gettext.
public final OpenCReport::bindtextdomain( string $domainname, string $dirname): void;
Setting the locale for the report does not affect
the main program or other threads. Locale setting
includes the language, the country. The UTF-8 suffix
is necessary. E.g.: en_GB.UTF-8
or
de_DE.UTF-8
public final OpenCReport::set_locale(string $locale): void;
For the OpenCReport\Datasource
class methods, see The OpenCReport\Datasource class
public final OpenCReport::datasource_add(string $source_name, string $source_type, ?array $conn_params = null): ?OpenCReport\Datasource;
This method adds a datasource of the specified type to the report, using the optional connection parameters.
The possible datasource types are:
array
, csv
,
json
, xml
,
mariadb
(also aliased as
mysql
), postgresql
and odbc
.
The connection parameter array is an associative array which contains keys and value pairs. The contents of this array is needed to connect to SQL databases. For example:
$conn_params = [ "dbname" => "mydatabase", "user" => "myuser" ];
The array
,
csv
, json
,
and xml
datasource types do not
need connection parameters.
The list of connection parameters
to establish database connection for
mariadb
,
postgresql
, and
odbc
are listed at
Section 10.1.3.1, in the
Low level C API Reference.
For the OpenCReport\Datasource
class methods, see The OpenCReport\Datasource class.
public final OpenCReport:: datasource_get(string $source_name): ?OpenCReport\Datasource;
For the OpenCReport\Query
class methods, see The OpenCReport\Query class.
public final OpenCReport::query_get(string $query_name): ?OpenCReport\Query;
A two dimensional array (actually, a one dimensional array of one dimensional arrays) can be used in PHP as an array query.
The PHP array may be modified during executing the report, e.g. in an event callback called after one iteration of a report part. This method refreshes the the query's internals to be aware of the new contents of the array.
public final query_refresh(): void;
There are some limitations what may be done to the source PHP array, though.
The array contents must not change during a report iteration, i.e. in a new row callback and some others. This would invalidate the contents of the PHP internal representation in a way that OpenCReports may break in subtle ways.
Changes to the first row of the array (i.e. the column names) are ignored.
The number of columns in the array must not change.
Expressions in OpenCReports is explained in the Expressions chapter.
The expression string may not reference report specific identifiers.
public final OpenCReport::expr_parse(string $expr_string): ?OpenCReport\Expr;
If the expression is in any way invalid,
OpenCReport::expr_parse()
returns null
. The error
is returned by:
public final OpenCReport::expr_error(): ?string;
public final OpenCReport::function_add( string $expr_func_name, string $zend_func_name, long $n_ops, bool $commutative, bool $associative, bool $left_associative, bool $dont_optimize): bool;
After this function returns with
success, subsequently parsed expressions
may use the function named as the
value of $expr_func_name
.
During evaluation of the function, the
PHP function named as the value of
$zend_func_name
is called.
The expressions that use the new function
may call it with either the number of arguments
given in $n_ops
, or
if the value is -1
,
any number of arguments.
The remaining bool
arguments indicate the named properties
of the function that the expression optimizer
considers.
The declaration of the PHP function named
as the value of $zend_func_name
must follow this:
function my_function(OpenCReport\Expr $e)
The function implementation may return
any PHP base type (string
,
long
, double
or bool
) or it may not return
a value at all (i.e. void
).
In the latter case, the function must set the
return value in the passed-in
$e
object.
For class methods of
OpenCReport\Expr
,
please see The OpenCReport\Expr class.
For class methods of
OpenCReport\Part
,
see The OpenCReport\Part class.
public final OpenCReport::part_new(): OpenCReport\Part;
This function returns an object
of the OpenCReport\Part
class. The object is internally marked
as an "iterator object", so
OpenCReport\Part::get_next()
may be called on it again to iterate
through every report part of the
parent OpenCReport
object.
public final OpenCReport::part_get_first(): OpenCReport\Part;
Set the paper type using the paper name,
i.e. 'letter'
,
'A4'
, etc.
public final OpenCReport::set_paper(string $paper): void;
Set the size unit.
See Size unit attribute.
Possible settings are
points
and rlib
.
Default is rlib
for RLIB compatibility.
public final OpenCReport::set_size_unit(string $expr_string): ?OpenCReport\Expr; public final OpenCReport::get_size_unit(): ?OpenCReport\Expr;
public final OpenCReport::set_noquery_show_nodata( string $expr_string): ?OpenCReport\Expr; public final OpenCReport::get_noquery_show_nodata(): ?OpenCReport\Expr;
public final OpenCReport::set_report_height_after_last( string $expr_string): ?OpenCReport\Expr; public final OpenCReport::set_report_height_after_last(): ?OpenCReport\Expr;
See Follower match single attribute.
public final OpenCReport::set_follower_match_single( string $expr_string): ?OpenCReport\Expr; public final OpenCReport::get_follower_match_single(): ?OpenCReport\Expr; public final OpenCReport::set_follower_match_single_direct( bool $value): void; public final OpenCReport::get_follower_match_single_direct(): bool;
These methods add a callback function that are called at certain points during executing the report.
public final OpenCReport::add_precalculation_done_cb( string $callback): void; public final OpenCReport::add_part_added_cb( string $callback): void; public final OpenCReport::add_report_added_cb( string $callback): void;
The "precalculation done" callback is called after the first phase of the report is finished. The interface of the callback function must follow this:
function my_callback(OpenCReport $o)
The "part added" callback is called when
either OpenCReport::part_new()
is called, or a report XML description is parsed
via either OpenCReport::parse_xml()
or OpenCReport::parse_xml_from_buffer()
and a <Part>
node is being parsed.
The interface of the callback function must follow this:
function my_callback(OpenCReport $o, OpenCReport\Part $p)
The "report added" callback is called when
either OpenCReport\Column::report_new()
is called, or a report XML description is parsed
via either OpenCReport::parse_xml()
or OpenCReport::parse_xml_from_buffer()
and a <Report>
node is being parsed.
The interface of the callback function must follow this:
function my_callback(OpenCReport $o, OpenCReport\Report $r)
In PHP, the "environment" includes both
global variables and actual environment
variables. If a global variable name exists
in the PHP environment, its value is returned
as OpenCReport\Result
.
If such a PHP global variable doesn't exist,
the variable from operating (e.g. UNIX)
environment is used and its value is returned
if it exists. Otherwise NULL
is returned.
public final OpenCReport::env_get(string $var_name): OpenCReport\Result;
Add an "m" domain variable.
If such a variable name
didn't exist yet, and value
is not NULL
, then
the variable is set. If value
is NULL
or omitted, the
variable is removed. Such an explicit variable
takes precedence over the PHP global variable
or the environment variable of the same name when
used in expressions.
public final OpenCReport::set_mvariable( string $name, string $value): void;
This method creates an uninitialized
OpenCReport\Result
with no value. See The OpenCReport\Result class
to set the value.
public final OpenCReport::result_new(): OpenCReport\Result;
This method returns (a possibly modified)
path that will create a canonical
absolute path that doesn't contain
.
and ..
references, symlinks are replaced with
the actual target directory, etc.
public static final OpenCReport::canonicalize_path(string $path): string;
Find a (possibly relative) file using the search paths and return the canonical absolute path if found.
public final OpenCReport::find_file(string $path): $string;
Get an array with double
components for the color name or color
specification.
public static OpenCReport::final get_color( string $color_name, ?bool $bgcolor = false): array;