ReportManager extends AppModel
Report Manager
Table of Contents
Properties
| $company_id | |
| $temp_dir |
Methods
| __construct() | Load language |
| addReport() | Add a custom report |
| deleteReport() | Delete a custom report |
| editReport() | Edit a custom report |
| fetchAll() | Generates the report type with the given vars. Sets Input errors on failure |
| getAvailable() | Retrieves a list of all available reports (those that exist on the file system) |
| getFormats() | Retrieves a list of report formats |
| getName() | Retrieves the name for the given report type |
| getOptions() | Retrieves the options for the given report type. Sets Input errors on failure |
| getReport() | Fetch a custom report |
| getReports() | Get all custom reports available |
| reportFieldTypes() | Fetch report field types |
| reportRequiredType() | Fetche report field required types |
| validateFormat() | Validates that the given format is valid for the report type given |
| validateQuery() | Validate that only one query is present, and it is a select query |
| validateType() | Validates that the given report type exists |
| buildCsvRow() | Builds a CSV row |
| formatCsv() | Uses Excel-style formatting for CSV fields (individual cells) |
| getReportFields() | Fetch custom report fields |
| reportDefaultRegex() | Fetch the default regex for the given report field type |
| requiredToRegex() | Convert the report field type and required status to a regex |
| saveReportFields() | Save report fields |
| buildCsv() | Build the report file in CSV format |
| buildJson() | Build the report file in JSON format |
| getReportRules() | Fetches rules for adding/editing custom reports |
| getRow() | Get data for a row and format it |
| getRules() | Returns the rules to validate the report type |
| loadReport() | Instantiates the given report and returns its instance |
| makeFileName() | Creates a temporary file name to store to disk |
Methods
__construct()
Load language
public
__construct() : mixed
addReport()
Add a custom report
public
addReport(array<string|int, mixed> $vars) : stdClass
Parameters
- $vars : array<string|int, mixed>
Return values
stdClass —The report added
deleteReport()
Delete a custom report
public
deleteReport(int $id) : mixed
Parameters
- $id : int
-
The ID of the custom report to delete
editReport()
Edit a custom report
public
editReport(int $id, array<string|int, mixed> $vars) : stdClass
Parameters
- $id : int
- $vars : array<string|int, mixed>
Return values
stdClass —The report updated
fetchAll()
Generates the report type with the given vars. Sets Input errors on failure
public
fetchAll(string $type, array<string|int, mixed> $vars[, string $format = 'csv' ][, string $return = 'download' ]) : mixed
Parameters
- $type : string
-
The type of report to fetch
- $vars : array<string|int, mixed>
-
A list of option values to pass to the report
- $format : string = 'csv'
-
The format of the report to generate (optional, default csv)
- $return : string = 'download'
-
(optional, default "download") One of the following:
- download To build and send the report to the browser to prompt for download; returns null
- false To build and send the report to the browser to prompt for download; returns null
- object To return a PDOStatement object representing the report data; returns PDOStatement
- true To return a PDOStatement object representing the report data; returns PDOStatement
- file To build the report and store it on the file system; returns the path to the file
Return values
mixed —A PDOStatement, string, or void based on the $return parameter
getAvailable()
Retrieves a list of all available reports (those that exist on the file system)
public
getAvailable([string $format = 'any' ]) : array<string|int, mixed>
Parameters
- $format : string = 'any'
-
The format the reports must support (optional)
Return values
array<string|int, mixed> —An array representing each report and its name
getFormats()
Retrieves a list of report formats
public
getFormats() : array<string|int, mixed>
Return values
array<string|int, mixed> —A list of report formats and their language
getName()
Retrieves the name for the given report type
public
getName(string $type) : string
Parameters
- $type : string
-
The type of report to fetch the name for
Return values
string —The name of the report
getOptions()
Retrieves the options for the given report type. Sets Input errors on failure
public
getOptions(string $type[, array<string|int, mixed> $vars = [] ]) : string
Parameters
- $type : string
-
The type of report to fetch the options for
- $vars : array<string|int, mixed> = []
-
A list of option values to pass to the report (optional)
Return values
string —The options as a view
getReport()
Fetch a custom report
public
getReport(int $id) : stdClass
Parameters
- $id : int
-
The ID of the custom report
Return values
stdClass —The custom report
getReports()
Get all custom reports available
public
getReports() : array<string|int, mixed>
Return values
array<string|int, mixed> —An array of stdClass objects each representing a report
reportFieldTypes()
Fetch report field types
public
reportFieldTypes() : array<string|int, mixed>
Return values
array<string|int, mixed> —An array of key/value pairs
reportRequiredType()
Fetche report field required types
public
reportRequiredType() : array<string|int, mixed>
Return values
array<string|int, mixed> —An array of key/value pairs
validateFormat()
Validates that the given format is valid for the report type given
public
validateFormat(string $format, string $type) : bool
Parameters
- $format : string
-
The report format
- $type : string
-
The report type
Return values
bool —True if the format is valid, false otherwise
validateQuery()
Validate that only one query is present, and it is a select query
public
validateQuery(string $sql) : bool
Parameters
- $sql : string
-
The user provided query
Return values
bool —True if the query is valid, false otherwise
validateType()
Validates that the given report type exists
public
validateType(string $type) : bool
Parameters
- $type : string
-
The report type
Return values
bool —True if the report type exists, false otherwise
buildCsvRow()
Builds a CSV row
protected
buildCsvRow(array<string|int, mixed> $fields) : string
Parameters
- $fields : array<string|int, mixed>
-
A list of data to place in each cell
Return values
string —A CSV row containing the field data
formatCsv()
Uses Excel-style formatting for CSV fields (individual cells)
protected
formatCsv(mixed $field) : mixed
Parameters
- $field : mixed
-
A single string of data representing a cell, or an array of fields representing a row
Return values
mixed —An escaped and formatted single cell or array of fields as given
getReportFields()
Fetch custom report fields
protected
getReportFields(int $id) : array<string|int, mixed>
Parameters
- $id : int
-
The ID of the custom report
Return values
array<string|int, mixed> —An array of stdClass objects representing custom report fields
reportDefaultRegex()
Fetch the default regex for the given report field type
protected
reportDefaultRegex(string $type) : string
Parameters
- $type : string
-
The field type
Return values
string —The default regex to use for that type
requiredToRegex()
Convert the report field type and required status to a regex
protected
requiredToRegex(string $type, string $required[, string $regex = null ]) : string
Parameters
- $type : string
-
The field type
- $required : string
-
Required option
- $regex : string = null
-
Defined regex (if any)
Return values
string —The regex to use
saveReportFields()
Save report fields
protected
saveReportFields(int $id, array<string|int, mixed> $report_fields) : mixed
Parameters
- $id : int
-
The ID of the report whose fields to save
- $report_fields : array<string|int, mixed>
-
A numerically indexed array of report fields containing:
- id
- name
- label
- type
- values
- regex
buildCsv()
Build the report file in CSV format
private
buildCsv(ReportInterface $report, Iterator $results, string $path_to_file) : mixed
Parameters
- $report : ReportInterface
-
The report type this row is for
- $results : Iterator
-
A list of data with which to populate the CSV rows
- $path_to_file : string
-
The path to the CSV file
buildJson()
Build the report file in JSON format
private
buildJson(ReportInterface $report, Iterator $results, string $path_to_file) : mixed
Parameters
- $report : ReportInterface
-
The report type this row is for
- $results : Iterator
-
A list of data with which to create a JSON object
- $path_to_file : string
-
The path to the JSON file
getReportRules()
Fetches rules for adding/editing custom reports
private
getReportRules(array<string|int, mixed> $vars[, bool $edit = false ]) : array<string|int, mixed>
Parameters
- $vars : array<string|int, mixed>
- $edit : bool = false
Return values
array<string|int, mixed> —Rules
getRow()
Get data for a row and format it
private
getRow(stdClass $fields, stdClass $keys, stdClass $format) : array<string|int, mixed>
Parameters
- $fields : stdClass
-
A list of data with which to populate the CSV rows
- $keys : stdClass
-
A list of keys and their formatting rules
- $format : stdClass
-
What report format is being used
Return values
array<string|int, mixed> —A row of data
getRules()
Returns the rules to validate the report type
private
getRules() : array<string|int, mixed>
Return values
array<string|int, mixed> —A list of rules
loadReport()
Instantiates the given report and returns its instance
private
loadReport(string $class) : An
Parameters
- $class : string
-
The name of the class in file_case to load
Return values
An —instance of the report specified
makeFileName()
Creates a temporary file name to store to disk
private
makeFileName(string $ext) : string
Parameters
- $ext : string
-
The file extension
Return values
string —The rewritten file name in the format of YmdTHisO_[hash].[ext] (e.g. 20121009T154802+0000_1f3870be274f6c49b3e31a0c6728957f.txt)