Big Reports is a plugin that allows you to create reports using Twig and have the results emailed to you as a CSV. Ideal for large data sets.
This plugin requires Craft CMS 3.0.0 or later.
To install the plugin, follow these instructions.
-
Open your terminal and go to your Craft project:
cd /path/to/project
-
Then tell Composer to load the plugin:
composer require kuriousagency/bigreports
-
In the Control Panel, go to Settings → Plugins and click the “Install” button for Craft Reports.
Set your columns by using the craft.bigreports.service.columns()
method, then add your row data by using the craft.bigreports.service.row()
.
Last thing to do is to use the craft.bigreports.service.data()
method to output the data.
Here is an example report in Twig:
{% do craft.bigreports.service.columns(["Firstname", "Lastname", "email"]) %}
{% for user in craft.users.limit(null).all() %}
{% do craft.bigreports.service.row([
user.firstName,
user.lastName,
user.email
]) %}
{% endfor %}
{{ craft.bigreports.service.data }}
Options
Big Reports can have options that are based on Craft CP forms macro.
{{ craft.forms('dateField', {
id: 'startDate',
label: "Start Date"|t,
name: 'options[startDate]',
value: options.startDate
}) }}
These options can then be accessed in the results. Here's an example that lists all users that have registered between two dates
{% set users = craft.users.
dateCreated(['and','>= ' ~ options.startDate|date('c'),'<= '~ options.endDate|date('Y-m-d 23:59:59')|date('c')])
.all() %}
{% do craft.bigreports.service.columns(["Firstname","LastName","Email"]) %}
{% for user in users %}
{% do craft.bigreports.service.row([
user.firstName,
user.lastName,
user.email,
]) %}
{% endfor %}
{{ craft.bigreports.service.data }}
The results are sent as a CSV attachment to the email address specifed on the report
Reports Template Path
Set the directory to find report templates
Here's an example folder structure
templates
_reports
users
results.twig
settings.twig
In the above case you would enter _reports as the template path
Email Template Path
If you would like to use your own email template to send the report you can set it here
Example files
Examples can be found here: https://github.com/KuriousAgency/craft-bigreports/tree/master/examples
Brought to you by Kurious Agency