BxBaseChartServices.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 UnaBaseView UNA Base Representation Classes
  7. * @{
  8. */
  9. /**
  10. * Services for chart objects functionality
  11. * @see BxDolChart
  12. */
  13. class BxBaseChartServices extends BxDol
  14. {
  15. public function serviceCheckAllowedView($isPerformAction = false)
  16. {
  17. $iProfileId = bx_get_logged_profile_id();
  18. $aCheck = checkActionModule($iProfileId, 'chart view', 'system', $isPerformAction);
  19. if($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  20. return $aCheck[CHECK_ACTION_MESSAGE];
  21. return CHECK_ACTION_RESULT_ALLOWED;
  22. }
  23. public function serviceGetChartGrowth()
  24. {
  25. $mixedResult = BxDolService::call('system', 'check_allowed_view', array(), 'TemplChartServices');
  26. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  27. return '';
  28. $sDateFrom = date('Y-m-d', time() - 30*24*60*60);
  29. $sDateTo = date('Y-m-d', time());
  30. $aForm = array(
  31. 'form_attrs' => array(
  32. 'id' => 'bx_chart_controls',
  33. 'action' => ''
  34. ),
  35. 'inputs' => array (
  36. 'object' => array(
  37. 'type' => 'select',
  38. 'name' => 'object',
  39. 'caption' => _t('_sys_chart_growth_object'),
  40. 'info' => '',
  41. 'value' => '',
  42. 'values' => array(),
  43. 'required' => '0',
  44. 'attrs' => array(
  45. 'id' => 'bx_chart_growth_objects',
  46. 'onchange' => 'oBxDolChartGrowth.loadData()'
  47. ),
  48. ),
  49. 'date_from' => array(
  50. 'type' => 'datepicker',
  51. 'name' => 'date_from',
  52. 'caption' => _t('_sys_chart_growth_date_from'),
  53. 'info' => '',
  54. 'value' => $sDateFrom,
  55. 'values' => array(),
  56. 'required' => '0',
  57. 'attrs' => array(
  58. 'id' => 'bx_chart_growth_date_from',
  59. 'onchange' => 'oBxDolChartGrowth.loadData()'
  60. ),
  61. ),
  62. 'date_to' => array(
  63. 'type' => 'datepicker',
  64. 'name' => 'date_to',
  65. 'caption' => _t('_sys_chart_growth_date_to'),
  66. 'info' => '',
  67. 'value' => $sDateTo,
  68. 'values' => array(),
  69. 'required' => '0',
  70. 'attrs' => array(
  71. 'id' => 'bx_chart_growth_date_to',
  72. 'onchange' => 'oBxDolChartGrowth.loadData()'
  73. ),
  74. )
  75. )
  76. );
  77. $aObjects = BxDolChartQuery::getChartObjects();
  78. foreach($aObjects as $aObject)
  79. $aForm['inputs']['object']['values'][] = array('key' => $aObject['object'], 'value' => _t($aObject['title']));
  80. $oForm = new BxTemplFormView($aForm);
  81. $oTemplate = BxDolTemplate::getInstance();
  82. $oTemplate->addJs(array('chart.min.js', 'BxDolChartGrowth.js'));
  83. $oTemplate->addCss(array('chart.css'));
  84. return $oTemplate->parseHtmlByName('chart_growth.html', array(
  85. 'date_from' => $sDateFrom,
  86. 'date_to' => $sDateTo,
  87. 'controls' => $oForm->getCode()
  88. ));
  89. }
  90. public function serviceGetChartStats()
  91. {
  92. $mixedResult = BxDolService::call('system', 'check_allowed_view', array(), 'TemplChartServices');
  93. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  94. return '';
  95. $aTmplVarsItems = array();
  96. $aTmplVarsDataLabels = $aTmplVarsDataSet = array();
  97. $oDb = BxDolDb::getInstance();
  98. $sQuery = "SELECT * FROM `sys_statistics` WHERE 1 ORDER BY `order`";
  99. $aItems = $oDb->getAll($sQuery);
  100. foreach($aItems as $aItem) {
  101. $sTitleAttr = bx_html_attribute(_t($aItem['title']));
  102. $iValue = 0;
  103. if(!empty($aItem['query']))
  104. $iValue = (int)$oDb->getOne($aItem['query']);
  105. else if(BxDolRequest::serviceExists($aItem['module'], 'get_query_statistics'))
  106. $iValue = (int)BxDolService::call($aItem['module'], 'get_query_statistics', array($aItem));
  107. $aTmplVarsDataLabels[] = $sTitleAttr . ' - ' . $iValue;
  108. $aTmplVarsDataSet['data'][] = $iValue;
  109. $aTmplVarsDataSet['backgroundColor'][] = '#' . dechex(rand(0x000000, 0xFFFFFF));
  110. }
  111. $oTemplate = BxDolTemplate::getInstance();
  112. $oTemplate->addJs(array('chart.min.js'));
  113. $oTemplate->addCss(array('chart.css'));
  114. return $oTemplate->parseHtmlByName('chart_stats.html', array(
  115. 'chart_data' => json_encode(array(
  116. 'labels' => $aTmplVarsDataLabels,
  117. 'datasets' => array($aTmplVarsDataSet)
  118. ))
  119. ));
  120. }
  121. }
  122. /** @} */