PHPackages                             mothership-ec/cog-mothership-reports - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. mothership-ec/cog-mothership-reports

AbandonedLibrary

mothership-ec/cog-mothership-reports
====================================

Mothership cogule for reports

2.2.0(10y ago)12.5k1[2 issues](https://github.com/mothership-ec/cog-mothership-reports/issues)[1 PRs](https://github.com/mothership-ec/cog-mothership-reports/pulls)8proprietaryPHPPHP &gt;=5.4.0

Since Dec 23Pushed 10y ago4 watchersCompare

[ Source](https://github.com/mothership-ec/cog-mothership-reports)[ Packagist](https://packagist.org/packages/mothership-ec/cog-mothership-reports)[ Docs](http://mothership.ec)[ RSS](/packages/mothership-ec-cog-mothership-reports/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelogDependencies (2)Versions (12)Used By (8)

Mothership Reports
==================

[](#mothership-reports)

The `Message\Mothership\Report` cogule provides a framework for providing reports in a new tab in the control panel.

Creating a new report
---------------------

[](#creating-a-new-report)

### Registering reports

[](#registering-reports)

Register your reports in the Service container of the module it's in. This is an example of code in MS-User:

```
public function registerReports($services)
{
	$services['user.user_summary'] = $services->factory(function($c) {
		return new User\Report\UserSummary(
			$c['db.query.builder.factory'],
			$c['routing.generator']
		);
	});

	$services['user.reports'] = function($c) {
		$reports = new ReportCollection;
		$reports
			->add($c['user.user_summary'])
		;
			return $reports;
	};
}

```

### Creating reports

[](#creating-reports)

Create a folder `Reports` within `Src` if there isn't already one. All reports for this module will be saved in here.

##### Initial set up

[](#initial-set-up)

All reports must extend `AbstractReport` and will use:

- `Message\Cog\DB\QueryBuilderInterface;`
- `Message\Cog\DB\QueryBuilderFactory;`
- `Message\Cog\Routing\UrlGenerator;`

##### Constructor

[](#constructor)

Set the:

- name: Used as an identifier and for naming the download file.
- displayName: Used on the front-end.
- description: Used on the front-end.
- reportGroup: Used to group similar reports on the dashboard.

Set all the filters and charts you want to use in the report.

Set any default filters you want for the report when it's first viewed.

This report displays `TableChart`, and uses filters `DateRange` and `Choices`. It sets the form default `StartDate` for 1 month ago.

```
		parent::__construct($builderFactory, $routingGenerator);
		$this->_setName('payments_refunds');
		$this->_setDisplayName('Payments & Refunds');
		$this->_setReportGroup('Transactions');
		$this->_setDescription('
			This report displays all payments & refunds.
			By default it includes all data from the last month (by completed date).
		');
		$this->_charts[]   = new TableChart;
		$this->_filters->add(new DateRange);
		$startDate = new \DateTime;
		$this->getFilters()
			->get('date_range')
			->setStartDate($startDate->setTimestamp(strtotime(date('Y-m-d H:i')." -1 month")));
		// Params for Choices filter: unique filter name, label, choices, multi-choice
		$this->_filters->add(new Choices(
			"type",
			"Type",
			[
				'payment' => 'Payment',
				'refund' => 'Refund',
			],
			false
		));
	}

```

##### getCharts()

[](#getcharts)

All reports need this function:

```
public function getCharts()
{
	$data = $this->_dataTransform($this->_getQuery()->run(), "json");
	$columns = $this->_parseColumns($this->getColumns());
		foreach ($this->_charts as $chart) {
		$chart->setColumns($columns);
		$chart->setData($data);
	}
	return $this->_charts;
}

```

##### getColumns()

[](#getcolumns)

Set all the columns needed into an array with the key as the name and value as type of data that's expected. This type is used for Google Charts.

```
public function getColumns()
{
	return [
		'Date'         => 'string',
		'Created by'   => 'string',
		'Currency'     => 'string',
		'Method'       => 'string',
		'Amount'       => 'number',
		'Type'         => 'string',
		'Order/Return' => 'string',
	];
}

```

##### \_getQuery()

[](#_getquery)

Using QueryBuilder create your report query. A simple example is the User Summary report:

```
protected function _getQuery()
{
	$queryBuilder = $this->_builderFactory->getQueryBuilder();
		$queryBuilder
		->select('user.user_id AS "ID"')
		->select('created_at AS "Created"')
		->select('CONCAT(surname,", ",forename) AS "User"')
		->select('email AS "Email"')
		->from('user')
		->orderBy('surname')
	;

	return $queryBuilder->getQuery();
}

```

#### \_dataTransform()

[](#_datatransform)

This takes the data from the query and converts it into either a string in JSON format for use in Google Charts, or a simple array for the CSV download.

For more complicated data you might need to pass in some optional properties. See: [https://developers.google.com/chart/interactive/docs/reference#cell\_object](https://developers.google.com/chart/interactive/docs/reference#cell_object)

For example, to order dates in their numerical representation rather than alphabetically you will need to send the timestamp as a *value* but the string as *formatted value*.

```
[
	'v' => $row->Created,
	'f' => date('Y-m-d H:i', $row->Created)
],

```

Another example is for currency values:

```
[
	'v' => (float) $row->Gross,
	'f' => (string) number_format($row->Gross,2,'.',',')
],

```

For links, if you send just the html link as the *value* it will order the values using the full html rather than the display text. This is fine if the text is the same values used to create the URL, but in most cases the ID isn't what will be displayed. In this case, the user's name is sent as the *value* and the html (using the user-id) is sent as the *formatted value*.

```
[
	'v' => utf8_encode($row->User),
	'f' => (string) '
		'
		.ucwords(utf8_encode($row->User)).''
]

```

Any strings which may contain special characters need encoded to UTF-8, as User does in the above example.

The full code used in the User Summary report:

```
	protected function _dataTransform($data, $output = null)
	{
		$result = [];

		if ($output === "json") {

			foreach ($data as $row) {

				$result[] = [
					$row->User ? [
						'v' => utf8_encode($row->User),
						'f' => (string) ''.ucwords(utf8_encode($row->User)).''
					] : $row->User,
					$row->Email,
					[
						'v' => $row->Created,
						'f' => date('Y-m-d H:i', $row->Created)
					],
				];

			}
			return json_encode($result);

		} else {

			foreach ($data as $row) {
				$result[] = [
					utf8_encode($row->User),
					$row->Email,
					date('Y-m-d H:i', $row->Created),
				];
			}
			return $result;

		}
	}

```

### Filters

[](#filters)

#### DateRange

[](#daterange)

This has two datetime form fields to select a range of data between the two.

#### Date

[](#date)

This is a singular date form field to select data from one specific date.

#### Choices

[](#choices)

The Choices form field can be customised depending on what data you are getting in the report.

When adding a choice form you must add the following parameters:

- A unique filter name, it cannot be the same as any other report
- A label for displaying on the form
- The choices
- Whether the field is multiple-choice

```
$this->_filters->add(new Choices(
	"type",
	"Sale Type",
		[
			'Order' => 'Order',
			'Return' => 'Return',
			'Exchange' => 'Exchange',
			'shipping' => 'Shipping',
		],
	true
));

```

### Charts

[](#charts)

#### Table

[](#table)

TableChart is currently the only chart available.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community22

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~57 days

Recently: every ~71 days

Total

6

Last Release

3871d ago

Major Versions

1.0.2 → 2.0.02015-02-24

### Community

Maintainers

![](https://www.gravatar.com/avatar/9c80abec1ec847de90ada27e2239c31f4374ed1d91912493f5415a688c269a78?d=identicon)[thomasjthomasj](/maintainers/thomasjthomasj)

---

Top Contributors

[![thomasjthomasj](https://avatars.githubusercontent.com/u/4520924?v=4)](https://github.com/thomasjthomasj "thomasjthomasj (26 commits)")[![eleanorshakeshaft](https://avatars.githubusercontent.com/u/5039349?v=4)](https://github.com/eleanorshakeshaft "eleanorshakeshaft (24 commits)")[![kuiche](https://avatars.githubusercontent.com/u/5089510?v=4)](https://github.com/kuiche "kuiche (14 commits)")[![joeholdcroft](https://avatars.githubusercontent.com/u/2511043?v=4)](https://github.com/joeholdcroft "joeholdcroft (2 commits)")

---

Tags

datareportingstatsinformationmothershipreports

### Embed Badge

![Health badge](/badges/mothership-ec-cog-mothership-reports/health.svg)

```
[![Health](https://phpackages.com/badges/mothership-ec-cog-mothership-reports/health.svg)](https://phpackages.com/packages/mothership-ec-cog-mothership-reports)
```

###  Alternatives

[entrepreneur-interet-general/bulletins

Bulletins is a simple weekly retrospective tool for multiple projects or teams

122.6k](/packages/entrepreneur-interet-general-bulletins)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
