Skip to content

Commit

Permalink
Add report thumbnails portlet
Browse files Browse the repository at this point in the history
  • Loading branch information
mkzia committed Jun 20, 2019
1 parent 464a778 commit b526407
Show file tree
Hide file tree
Showing 24 changed files with 1,291 additions and 177 deletions.
8 changes: 6 additions & 2 deletions classes/ReportTemplates/GenericReportTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@ class GenericReportTemplate extends aReportTemplate
*
* @param array $params Additional parameters.
*/
public function buildReportFromTemplate(array &$params = array())
public function buildReportFromTemplate(array &$params = array(), $report_id_suffix = null)
{
$rm = new XDReportManager($this->_user);

$id = $this->_user->getUserID() . '-' . microtime(true);
if (!(is_null($report_id_suffix))){
$id = $this->_user->getUserID() . '-' . $report_id_suffix;
} else {
$id = $this->_user->getUserID() . '-' . microtime(true);
}

$rm->configureSelectedReport(
$id,
Expand Down
63 changes: 63 additions & 0 deletions classes/Rest/Controllers/SummaryControllerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public function setupRoutes(Application $app, ControllerCollection $controller)

$controller->post("$root/layout", "$class::setLayout");
$controller->delete("$root/layout", "$class::resetLayout");

$controller->get("$root/rolereport", "$class::getRoleReport");
}

/*
Expand Down Expand Up @@ -191,4 +193,65 @@ public function resetLayout(Request $request, Application $app)
'total' => 1
));
}

/**
* Get charts based on role.
**/
public function getRoleReport(Request $request, Application $app)
{
$user = $this->authorize($request);
$role = $user->getMostPrivilegedRole()->getName();
if ($role == "cd") {
$template_id = 2;
} elseif ($role == "cs") {
$template_id = 3;
} else {
$template_id = 3;
}
$report_id_suffix = 'autogenerated-' . $role;
$report_id = $user->getUserID() . '-' . $report_id_suffix;
if (isset($user)) {
$userReport = null;
$rm = new \XDReportManager($user);
$reports = $rm->fetchReportTable();
foreach ($reports as &$report) {
if ($report['report_id'] === $report_id) {
$userReport = $report;
}
}
if (is_null($userReport)){
$template = $rm->retrieveReportTemplate($user, $template_id);
$template->buildReportFromTemplate($_REQUEST, $report_id_suffix);
$reports = $rm->fetchReportTable();
foreach ($reports as &$report) {
if ($report['report_id'] === $report_id) {
$userReport = $report;
}
}
}
$data = $rm->loadReportData($userReport['report_id']);
$count = 0;
foreach($data['queue'] as $queue) {
$chart_id = urldecode($queue['chart_id']);
$chart_id = explode("&", $chart_id);
$chart_id_parsed = array();
foreach($chart_id as $value) {
list($key, $value) = explode("=", $value);
$json = json_decode($value, true);
if ($json === null) {
$chart_id_parsed[$key] = $value;
} else {
$chart_id_parsed[$key] = $json;
}
}
$data['queue'][$count]['chart_id'] = $chart_id_parsed;
$count++;
}
return $app->json(array(
'success' => true,
'total' => 1,
'data' => $data
));
}
}
}
38 changes: 24 additions & 14 deletions classes/XDReportManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -1324,7 +1324,11 @@ public function fetchChartBlob(
$timeframe_type = $iq[0]['timeframe_type'];
}

if (strtolower($timeframe_type) == 'user defined') {
if (is_array($insertion_rank) && array_key_exists('start_date', $insertion_rank) && array_key_exists('end_date', $insertion_rank) && !(is_null($insertion_rank['start_date'])) && !(is_null($insertion_rank['end_date']))) {
$start_date = $insertion_rank['start_date'];
$end_date = $insertion_rank['end_date'];
}
elseif (strtolower($timeframe_type) == 'user defined') {
$start_date = $active_start;
$end_date = $active_end;
}
Expand Down Expand Up @@ -1601,12 +1605,16 @@ public function generateChartBlob(
* \param outputdir the name of an existing, writable directory in which to put the files.
* \param report_id the identifier for the report
* \param export_format the specified export format
* \param start_date the start date for output
* \param end_date the end date for output
* \returns The name of the report file that was written
*/
private function writeXMLConfiguration(
$outputdir,
$report_id,
$export_format = null
$export_format = null,
$start_date = null,
$end_date = null
) {
$dom = new \DOMDocument("1.0");

Expand Down Expand Up @@ -1681,22 +1689,24 @@ private function writeXMLConfiguration(
$entry['title']
);

if (strtolower($entry['timeframe_type']) == 'user defined') {
list($start_date, $end_date)
= explode(' to ', $entry['comments']);
}
else {
$e = \xd_date\getEndpoints($entry['timeframe_type']);
if ((is_null($start_date) || is_null($end_date))) {
// Use start and end date from report if start or end date is not supplied as function parameters
if (strtolower($entry['timeframe_type']) == 'user defined') {
list($start_date, $end_date)
= explode(' to ', $entry['comments']);
}
else {
$e = \xd_date\getEndpoints($entry['timeframe_type']);

$start_date = $e['start_date'];
$end_date = $e['end_date'];
$start_date = $e['start_date'];
$end_date = $e['end_date'];
}
}

// Update comments and hyperlink so reporting engine can
// work with the correct chart (image)
$entry['comments'] = $start_date . ' to ' . $end_date;

$imagedata = $this->fetchChartBlob("report", array("report_id" => $report_id, "ordering" => $entry['order'] ) );
$imagedata = $this->fetchChartBlob("report", array("report_id" => $report_id, "ordering" => $entry['order'], "start_date" => $start_date, "end_date" => $end_date) );
$imagefilename = $outputdir . "/" . $entry['order'] . ".png";
file_put_contents($imagefilename, $imagedata);

Expand Down Expand Up @@ -1782,7 +1792,7 @@ private function writeXMLConfiguration(
return $report_filename;
}

public function buildReport($report_id, $export_format)
public function buildReport($report_id, $export_format, $start_date = null, $end_date = null)
{

if (
Expand Down Expand Up @@ -1844,7 +1854,7 @@ public function buildReport($report_id, $export_format)

// Generate a report definition (XML) to be used as the input to
// the Jasper Report Builder application
$this->writeXMLConfiguration($template_path, $report_id, $export_format);
$this->writeXMLConfiguration($template_path, $report_id, $export_format, $start_date, $end_date);

$charts_per_page = $this->getReportChartsPerPage($report_id);

Expand Down
6 changes: 5 additions & 1 deletion configuration/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
"xdmod": {
"portal": {
"js": [
"gui/js/modules/summary/ChartPortlet.js"
"gui/js/modules/summary/ChartPortlet.js",
"gui/js/modules/summary/ReportThumbnailsPortlet.js"
],
"css": [
"gui/css/ReportThumbnailsPortlet.css"
]
}
}
Expand Down
109 changes: 109 additions & 0 deletions configuration/etl/etl.d/xdmod-migration-8_1_2-8_5_0.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,115 @@
"schema": "modw_aggregates"
}
}
},
{
"name": "add-moddb_staging-tables",
"description": "Add moddb staging tables",
"namespace": "ETL\\Maintenance",
"class": "ManageTables",
"options_class": "MaintenanceOptions",
"definition_file_list": [
"xdb/report-templates-staging.json",
"xdb/report-template-charts-staging.json"
],
"endpoints": {
"destination": {
"type": "mysql",
"name": "Staging tables",
"config": "database",
"schema": "moddb"
}
}
},
{
"name": "report-templates-staging",
"namespace": "ETL\\Ingestor",
"class": "StructuredFileIngestor",
"options_class": "IngestorOptions",
"description": "report-templates-staging + data",
"definition_file": "xdb/report-templates-staging.json",
"endpoints": {
"source": {
"type": "jsonfile",
"name": "report-templates-staging",
"path": "xdb/report-templates.json"
},
"destination": {
"type": "mysql",
"name": "Staging tables",
"config": "database",
"schema": "moddb"
}
},
"truncate_destination": true
},
{
"name": "report-template-charts-staging",
"namespace": "ETL\\Ingestor",
"class": "StructuredFileIngestor",
"options_class": "IngestorOptions",
"description": "report-template-charts-staging + data",
"definition_file": "xdb/report-template-charts-staging.json",
"endpoints": {
"source": {
"type": "jsonfile",
"name": "report-template-charts-staging",
"path": "xdb/report-template-charts.json"
},
"destination": {
"type": "mysql",
"name": "Staging tables",
"config": "database",
"schema": "moddb"
}
},
"truncate_destination": true
},
{
"name": "report-templates",
"description": "report-templates + data",
"namespace": "ETL\\Ingestor",
"class": "DatabaseIngestor",
"options_class": "IngestorOptions",
"definition_file": "xdb/report-templates.json",
"endpoints": {
"source": {
"type": "mysql",
"name": "Staging tables",
"config": "database",
"schema": "moddb"
},
"destination": {
"type": "mysql",
"name": "Staging tables",
"config": "database",
"schema": "moddb"
}
},
"truncate_destination": true
},
{
"name": "report-template-charts",
"description": "report-template-charts + data",
"namespace": "ETL\\Ingestor",
"class": "DatabaseIngestor",
"options_class": "IngestorOptions",
"definition_file": "xdb/report-template-charts.json",
"endpoints": {
"source": {
"type": "mysql",
"name": "Staging tables",
"config": "database",
"schema": "moddb"
},
"destination": {
"type": "mysql",
"name": "Staging tables",
"config": "database",
"schema": "moddb"
}
},
"truncate_destination": true
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"#": "This action loads data from a structured file and only needs the table definition",
"table_definition": [
{
"$ref": "${table_definition_dir}/xdb/report-template-charts-staging.json#/table_definition"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,44 @@
{
"$ref": "${table_definition_dir}/xdb/report-template-charts.json#/table_definition"
}
]
],
"destination_record_map": {
"ReportTemplateCharts": {
"template_id": "template_id",
"chart_id": "chart_id",
"ordering": "ordering",
"chart_date_description": "chart_date_description",
"chart_title": "chart_title",
"chart_drill_details": "chart_drill_details",
"timeframe_type": "timeframe_type"
}
},
"source_query": {
"records": {
"template_id": "rtcs.template_id",
"chart_id": "rtcs.chart_id",
"ordering": "rtcs.ordering",
"chart_date_description": "rtcs.chart_date_description",
"chart_title": "rtcs.chart_title",
"chart_drill_details": "rtcs.chart_drill_details",
"timeframe_type": "rtcs.timeframe_type"
},
"joins": [
{
"name": "ReportTemplateChartsStaging",
"schema": "${SOURCE_SCHEMA}",
"alias": "rtcs"
},
{
"name": "ReportTemplateCharts",
"schema": "${SOURCE_SCHEMA}",
"alias": "rtc",
"type": "left outer",
"on": "rtcs.template_id=rtc.template_id",
"where": [
"rtc.template_id IS NULL"
]
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"#": "This action loads data from a structured file and only needs the table definition",
"table_definition": [
{
"$ref": "${table_definition_dir}/xdb/report-templates-staging.json#/table_definition"
}
]
}
Loading

0 comments on commit b526407

Please sign in to comment.