<?php
 namespace App\Dashboard\Widget; abstract class Charts_GeneralAbstract extends \Engine\Dashboard\Widgets\WidgetAbstract { protected $cacheLifetime=null; protected function getDefaultOptions() { } protected function populateLocalOptionsForm(\Engine\Form\Container\GeneralAbstract $form) { return $form; } protected function extractFormOptions($formData) { } public function getTemplatePath() { return APP_REAL_PATH."/_templates/application/dashboard/widgets/ChartAbstract.tpl"; } protected function getData() { $output = []; $chart = $this->defineChart(); if (!($chart instanceof \App\QuickReports\Charts\Types\GeneralAbstract)) { throw new \Exception('The return of defineChart() must be an instance of \App\QuickReports\Charts\Types\GeneralAbstract.'); } try { $output['chart'] = $chart; $chart->generateContent(); } catch (\App\QuickReports\PivotTables\Data\Exception $e) { $output['errorMessage'] = $e->getMessage(); } return $output; } abstract protected function defineChart(); protected function executeAndCacheSql($sql, array $bindVars) { $CFG = \Engine\Loader_Cfg::getInstance()->getGlobal(); $cacheObj = new \Engine\Cache\DiskWithLRU(); $cacheObj->setPath($CFG['paths']['quickReportsCache']); $cacheKey = 'quickReports_sql_'.$sql.'['.serialize($bindVars).']'; $records = $cacheObj->get($cacheKey); if ($records===null) { $db = \DB::getInstance(); $records = $db->GetAll($sql, $bindVars); if ($db->ErrorMsg()) { throw new \DBException("Could not run SQL for QR pivot source."); } $cacheObj->set($cacheKey, $records, 86400); } return $records; } } 