BxChartsTemplate.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup Charts Charts
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. bx_import ('BxDolModuleTemplate');
  12. class BxChartsTemplate extends BxBaseModGeneralTemplate
  13. {
  14. function __construct(&$oConfig, &$oDb)
  15. {
  16. $this->MODULE = 'bx_charts';
  17. parent::__construct($oConfig, $oDb);
  18. }
  19. function getChartGrowth($sChartName, $iHeight)
  20. {
  21. $this->getModule();
  22. $aTmp = $this->_oModule->getSelectedModulesGrowth();
  23. $aModules = $aTmp[0];
  24. $aModulesList = $aTmp[1];
  25. $aModulesList2 = array();
  26. foreach($aModules as $sModule){
  27. $aModulesList2[] = array('value' => $sModule, 'title' => $aModulesList[$sModule]);
  28. }
  29. return $this->parseHtmlByName('chart-growth.html', array(
  30. 'chart' => $this->getChart($sChartName, $iHeight),
  31. 'bx_if:show_module_selector' => array(
  32. 'condition' => count($aModulesList2)>1 ? true : false,
  33. 'content' => array(
  34. 'chart_name' => $sChartName,
  35. 'bx_repeat:items' => $aModulesList2
  36. )
  37. )));
  38. }
  39. function getChart($sChartName, $iHeight)
  40. {
  41. $this->addJs(array('chart.umd.min.js', 'chartjs-adapter-moment.min.js', 'chart.js'));
  42. $this->addCss(array('chart.css'));
  43. return $this->getJsCode('chart', array('chartName' => $sChartName)) . $this->parseHtmlByName('chart.html', array('chart_name' => $sChartName, 'height' => $iHeight));
  44. }
  45. public function getJsCode($sType, $aParams = array(), $bWrap = true)
  46. {
  47. $aParams = array_merge(array(
  48. 'sChartName' => $aParams['chartName'],
  49. ), $aParams);
  50. return parent::getJsCode($sType, $aParams, $bWrap);
  51. }
  52. }
  53. /** @} */