/** * Retrieves a saved report and chart data, given a report ID in the args * * @param $api ServiceBase The API class of the request * @param $args array The arguments array passed in from the API * @return array */ public function getSavedReportChartById($api, $args) { require_once "include/SugarCharts/ChartDisplay.php"; $chartReport = $this->getSavedReportById($args['reportId']); if (isset($args['filter_id']) && $args['filter_id'] !== 'all_records') { $chartReport->content = $this->updateFilterDef($chartReport->content, $args['filter_id']); } if (!empty($chartReport)) { if (!$chartReport->ACLAccess('view')) { throw new SugarApiExceptionNotAuthorized('No access to view this report'); } $returnData = array(); $this->title = $chartReport->name; require_once "modules/Reports/Report.php"; $reporter = new Report($chartReport->content); $reporter->saved_report_id = $chartReport->id; if ($reporter && !$reporter->has_summary_columns()) { return ''; } // build report data since it isn't a SugarBean $reportData = array(); $reportData['name'] = $reporter->name; $reportData['id'] = $reporter->saved_report_id; $reportData['summary_columns'] = $reporter->report_def['summary_columns']; $reportData['group_defs'] = $reporter->report_def['group_defs']; // add reportData to returnData $returnData['reportData'] = $reportData; $chartDisplay = new ChartDisplay(); $chartDisplay->setReporter($reporter); $chart = $chartDisplay->getSugarChart(); $json = json_decode($chart->buildJson($chart->generateXML())); $returnData['chartData'] = $json; return $returnData; } }