-
Notifications
You must be signed in to change notification settings - Fork 46
How to add user fields to any report?
Manoj L edited this page Jun 24, 2019
·
8 revisions
TJReport has plugins that let you index the custom fields data created using Joomla's com_fields
component.
Below are steps for adding those user fields data columns into an existing report.
Eg: For a plugin named mytjreportplugin
, open plugin entry file mytjreportplugin.php
Change constructor from
public function __construct($config = array())
{
$this->columns = array (
// Columns setup here
);
parent::__construct($config);
}
to below
public function __construct($config = array())
{
// Joomla fields integration
// Define custom fields table, alias, and table.column to join on
$this->customFieldsTable = '#__tjreports_user_fields';
$this->customFieldsTableAlias = 'tuf';
$this->customFieldsQueryJoinOn = 'lt.user_id';
$this->columns = array (
// Columns setup here
);
parent::__construct($config);
}
In step 1, we define
-
customFieldsTable
- Custom field's indexed table in which we store duplicated data -
customFieldsTableAlias
- Alias for above table -
customFieldsQueryJoinOn
- Table name and column name on which TJReport will do database query join on (TJReports' model will do query join on the custom fields table'srecord_id
column and with the other DB table which plugin mainly runs the report on.)
Change code from
public function displayFilters()
{
// Set filters code here
$dispFilters = array(
array(
// Set filters code here
),
array(
// Set filters code here
)
);
return $dispFilters;
}
to
public function displayFilters()
{
// Set filters code here
$dispFilters = array(
array(
// Set filters code here
),
array(
// Set filters code here
)
);
// Joomla fields integration
// Call parent function to set filters for custom fields
$this->setCustomFieldsDisplayFilters($dispFilters);
return $dispFilters;
}
In step 2, we call the parent method setCustomFieldsDisplayFilters()
, which sets up filters for columns from custom fields to be displayed on the report.
That's it, with these 2 simple steps, you will be able to easily add columns, filters, sorting on the columns form the Joomla user's custom fields.