Actions

Before we start to learn any details about using phpReport we need to know something about actions.

Calling the run() method starts the execution and phpReport takes control over the program flow. Whenever an important event occurs an action might be invoked.

Typical actions are:

  • call a method in the target object (The target parameter of the report class)

  • append a string to the output

  • execute a callable

  • call a method in the prototyp class

Within the configuration file you can specify exactly what action will be executed. During instantiation of the report class you might replace some of the configuration parameters.

Events like a group change will trigger individual action for defined groups. To be able to execute different action types the group() method also allows replacing the default action.

The default rules are simple: 1) If action is a string this string will be appended to $output. 2) If action is a method name the method will only be called when the method exist. The returned value will be appended to $output. 3) If action is a callable the returned value will be appended to $output.

The above rules can be altered by calling the setCallOption().

Named events

Each named event is mapped to an action. Below are all events listed. Parameters passed to the action object are shown in parenthesis.

Data independent events

These methods are called even when no data are provided.

init()

First event. Use to initialize application properties independent from the __construct method.

close()

Last event. Use to clean up the dishes independent from __destruct method.

totalHeader()

Called once to build the total header page of the report.

totalFooter()

Called once to build the total footer page of the report.

Data driven events

noData()

This event only occurs when the given data set is empty. In this case the following events will never be raised.

beforeGroupHeader($groupValue, $row, $rowKey)

Raised before the group header action. To suppress any further actions return ‘false’.

param mixed $groupValue

The current group value.

param array|object $row

The current row which triggered the group change.

param mixed $rowKey

The rowKey is the key of the current row taken from the input data set or given by calling the next() method.

groupHeader($groupValue, $row, $rowKey)

Raised when group values between two rows are not equal. Each group has its own groupHeader.

Group headers are executed from the changed group level down to the lowest declared group (within an data dimension).

After executing all headers the detail event will be performed.

param mixed $groupValue

The current group value.

param array|object $row

The current row which triggered the group change.

param mixed $rowKey

The rowKey is the key of the current row taken from the input data set or given by calling the next() method.

groupFooter($groupValue, $row, $rowKey, $dimID)

groupFooters are executed like groupHeaders when group values between to rows are not equal.

But the footers are called from the lowest declared group (within a dimension) up to the changed group.

The signature is the same as for groupHeader() methods but the values belongs to the last row within this group and not to the latest read row which triggered the group change.

afterGroupFooter($groupValue, $row, $rowKey)

Raised after groupFooter. Might be used to handle the current output. Examples: Write outut to file and reset current output. Generate pdf file. Send output per mail.

beforeDetail($row, $rowKey)

Raised before detail actions. This is after the last afterGroupFooter action. Might be used to create header for details when groupFooter of last group is not suitable or to be more flexible.

detail($row, $rowKey)

Executed for each row of the last data dimension. When the row triggered a group change then the related group footers and group headers will be called before.

param array|object $row

The current row.

param mixed $rowKey

The rowKey is the key of the current row taken from the input data set or given by calling the next() method.

afterDetail($row, $rowKey)

Raised after detail actions.

Methods for multi dimensional data

Following events belongs only to data sources having joined data.

noData_n($dimID)

Called when the declared source for the next data dimension doesn’t return any data. :param int $dimID: The ID of data dimension not having related data.

detail_n($row, $rowKey)

Except for the last dimension this event is raised for each data row (See detail method).

When group(s) are declared for this data dimension consider using groupHeader and groupFooter methods instead.

param array|object $row

The current row.

param mixed $rowKey

The rowKey is the key of the current row taken from the input data set or given by calling the next() method.

noGroupChange_n($row, $rowKey, $dimID)

Raised only for rows not related to the last dimension and when group(s) are declared but current row don’t trigger a group change. (Row has the same group values than previous row.) In most cases this is an unexpected behaviour and you might want to trigger an error. That’s also the default behaviour.

But sometimes it’s deliberated (e.g. From a date field only the year or month is declared as a group) and you want to handle this non unique rows.

param array|object $row

The current row which triggered the group change.

param mixed $rowKey

The rowKey is the key of the current row taken from the input data set or given by calling the next() method.

param int $dimID

The ID of the current data dimension.