Piwik\ReportRenderer::getStaticGraph PHP Method

getStaticGraph() public static method

public static getStaticGraph ( $reportMetadata, $width, $height, $evolution, $segment )
    public static function getStaticGraph($reportMetadata, $width, $height, $evolution, $segment)
    {
        $imageGraphUrl = $reportMetadata['imageGraphUrl'];
        if ($evolution && !empty($reportMetadata['imageGraphEvolutionUrl'])) {
            $imageGraphUrl = $reportMetadata['imageGraphEvolutionUrl'];
        }
        $requestGraph = $imageGraphUrl . '&outputType=' . API::GRAPH_OUTPUT_PHP . '&format=original&serialize=0' . '&filter_truncate=' . '&width=' . $width . '&height=' . $height . ($segment != null ? '&segment=' . urlencode($segment['definition']) : '');
        $request = new Request($requestGraph);
        try {
            $imageGraph = $request->process();
            // Get image data as string
            ob_start();
            imagepng($imageGraph);
            $imageGraphData = ob_get_contents();
            ob_end_clean();
            imagedestroy($imageGraph);
            return $imageGraphData;
        } catch (Exception $e) {
            throw new Exception("ImageGraph API returned an error: " . $e->getMessage() . "\n");
        }
    }

Usage Example

Example #1
0
 private function createAttachment($report, $processedReport, $prettyDate)
 {
     $additionalFile = array();
     $segment = self::getSegment($report['idsegment']);
     $segmentName = $segment != null ? sprintf(' (%s)', $segment['name']) : '';
     $processedReportMetadata = $processedReport['metadata'];
     $additionalFile['filename'] = sprintf('%s - %s - %s %d - %s %d%s.png', $processedReportMetadata['name'], $prettyDate, Piwik::translate('General_Website'), $report['idsite'], Piwik::translate('General_Report'), $report['idreport'], $segmentName);
     $additionalFile['cid'] = $processedReportMetadata['uniqueId'];
     $additionalFile['content'] = ReportRenderer::getStaticGraph($processedReportMetadata, Html::IMAGE_GRAPH_WIDTH, Html::IMAGE_GRAPH_HEIGHT, $processedReport['evolutionGraph'], $segment);
     $additionalFile['mimeType'] = 'image/png';
     $additionalFile['encoding'] = Zend_Mime::ENCODING_BASE64;
     return $additionalFile;
 }
All Usage Examples Of Piwik\ReportRenderer::getStaticGraph