PageRenderTime 36ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/AOR_Reports/Dashlets/AORReportsDashlet/AORReportsDashlet.php

https://gitlab.com/tjaafar/SuiteCRM
PHP | 106 lines | 95 code | 11 blank | 0 comment | 7 complexity | 9af25acd6d7527efee59b8e9b83edfb8 MD5 | raw file
  1. <?php
  2. if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
  3. require_once('include/Dashlets/Dashlet.php');
  4. require_once 'modules/AOR_Reports/aor_utils.php';
  5. class AORReportsDashlet extends Dashlet {
  6. var $def;
  7. var $report;
  8. var $charts;
  9. var $onlyCharts;
  10. function AORReportsDashlet($id, $def = array()) {
  11. global $current_user, $app_strings;
  12. parent::Dashlet($id);
  13. $this->isConfigurable = true;
  14. $this->def = $def;
  15. if(empty($def['dashletTitle'])) {
  16. $this->title = translate('LBL_AOR_REPORTS_DASHLET', 'AOR_Reports');
  17. }else{
  18. $this->title = $def['dashletTitle'];
  19. }
  20. $this->params = array();
  21. if(!empty($def['parameter_id'])) {
  22. foreach ($def['parameter_id'] as $key => $parameterId) {
  23. $this->params[$parameterId] = array(
  24. 'id' => $parameterId,
  25. 'operator' => $def['parameter_operator'][$key],
  26. 'type' => $def['parameter_type'][$key],
  27. 'value' => $def['parameter_value'][$key]);
  28. }
  29. }
  30. if(!empty($def['aor_report_id'])) {
  31. $this->report = BeanFactory::getBean('AOR_Reports', $def['aor_report_id']);
  32. $this->report->user_parameters = $this->params;
  33. }
  34. $this->onlyCharts = !empty($def['onlyCharts']);
  35. $this->charts = !empty($def['charts']) ? $def['charts'] : array();
  36. }
  37. public function display() {
  38. global $current_language;
  39. $mod_strings = return_module_language($current_language, 'AOR_Reports');
  40. $dashletSmarty = new Sugar_Smarty();
  41. $dashletTemplate = get_custom_file_if_exists('modules/AOR_Reports/Dashlets/AORReportsDashlet/dashlet.tpl');
  42. $dashletSmarty->assign('MOD',$mod_strings);
  43. $dashletSmarty->assign('dashlet_id',$this->id);
  44. $dashletSmarty->assign('report_id',$this->report->id);
  45. $dashletSmarty->assign('chartHTML',$this->getChartHTML());
  46. $dashletSmarty->assign('onlyCharts', $this->onlyCharts);
  47. $dashletSmarty->assign('parameters',json_encode(array(
  48. 'ids' => $this->def['parameter_id'],
  49. 'operators' => $this->def['parameter_operator'],
  50. 'types' => $this->def['parameter_type'],
  51. 'values' => $this->def['parameter_value'])));
  52. return $dashletSmarty->fetch($dashletTemplate);
  53. }
  54. function getChartHTML(){
  55. if(!empty($this->report->id)) {
  56. return $this->report->build_report_chart($this->charts, AOR_Report::CHART_TYPE_CHARTJS);
  57. }else{
  58. return '';
  59. }
  60. }
  61. function process() {
  62. }
  63. public function displayOptions() {
  64. ob_start();
  65. global $current_language, $app_list_strings;
  66. $mod_strings = return_module_language($current_language, 'AOR_Reports');
  67. $optionsSmarty = new Sugar_Smarty();
  68. $optionsSmarty->assign('MOD',$mod_strings);
  69. $optionsSmarty->assign('id', $this->id);
  70. $optionsSmarty->assign('dashletTitle', $this->title);
  71. $optionsSmarty->assign('aor_report_id', $this->report->id);
  72. $optionsSmarty->assign('aor_report_name', $this->report->name);
  73. $optionsSmarty->assign('onlyCharts', $this->onlyCharts);
  74. $charts = array();
  75. if(!empty($this->report->id)){
  76. foreach($this->report->get_linked_beans('aor_charts','AOR_Charts') as $chart){
  77. $charts[$chart->id] = $chart->name;
  78. }
  79. }
  80. $conditions = getConditionsAsParameters($this->report, $this->params);
  81. $optionsSmarty->assign('parameters', $conditions);
  82. $chartOptions = get_select_options_with_id($charts,$this->charts);
  83. $optionsSmarty->assign('chartOptions', $chartOptions);
  84. $optionsTemplate = get_custom_file_if_exists('modules/AOR_Reports/Dashlets/AORReportsDashlet/dashletConfigure.tpl');
  85. ob_clean();
  86. return $optionsSmarty->fetch($optionsTemplate);
  87. }
  88. public function saveOptions($req) {
  89. $allowedKeys = array_flip(array('aor_report_id','dashletTitle','charts','onlyCharts','parameter_id','parameter_value','parameter_type','parameter_operator'));
  90. return array_intersect_key($req,$allowedKeys);
  91. }
  92. public function hasAccess() {
  93. return true;
  94. }
  95. }