From dbb4a0f98a837767c75a5d9837705f85d6ed9bec Mon Sep 17 00:00:00 2001 From: Pradeep Nayak Date: Sat, 3 May 2014 19:24:29 +0530 Subject: [PATCH] -- CRM-14115, added code to limit count on dashboard. ---------------------------------------- * CRM-14115: Allow maximum number of Reportlet rows to be specified https://issues.civicrm.org/jira/browse/CRM-14115 --- CRM/Report/BAO/ReportInstance.php | 9 ++++++--- CRM/Report/Form.php | 24 ++++++++++++++++++++++++ CRM/Report/Form/Contribute/TopDonor.php | 5 +++++ CRM/Report/Form/Instance.php | 13 +++++++++++-- templates/CRM/Report/Form/Instance.tpl | 12 ++++++++++++ 5 files changed, 58 insertions(+), 5 deletions(-) diff --git a/CRM/Report/BAO/ReportInstance.php b/CRM/Report/BAO/ReportInstance.php index 2094b55457..afd4cf0dd4 100644 --- a/CRM/Report/BAO/ReportInstance.php +++ b/CRM/Report/BAO/ReportInstance.php @@ -214,9 +214,12 @@ class CRM_Report_BAO_ReportInstance extends CRM_Report_DAO_ReportInstance { $section = 1; $chart = "&charts=" . $params['charts']; } - - $dashletParams['url'] = "civicrm/report/instance/{$instance->id}&reset=1§ion={$section}&snippet=5{$chart}&context=dashlet"; - $dashletParams['fullscreen_url'] = "civicrm/report/instance/{$instance->id}&reset=1§ion={$section}&snippet=5{$chart}&context=dashletFullscreen"; + $limitResult = NULL; + if (CRM_Utils_Array::value('row_count', $params)) { + $limitResult = '&rowCount=' . $params['row_count']; + } + $dashletParams['url'] = "civicrm/report/instance/{$instance->id}&reset=1§ion={$section}&snippet=5{$chart}&context=dashlet" . $limitResult; + $dashletParams['fullscreen_url'] = "civicrm/report/instance/{$instance->id}&reset=1§ion={$section}&snippet=5{$chart}&context=dashletFullscreen" . $limitResult; $dashletParams['instanceURL'] = "civicrm/report/instance/{$instance->id}"; CRM_Core_BAO_Dashboard::addDashlet($dashletParams); } diff --git a/CRM/Report/Form.php b/CRM/Report/Form.php index 3fe222c536..ab56388125 100644 --- a/CRM/Report/Form.php +++ b/CRM/Report/Form.php @@ -276,6 +276,12 @@ class CRM_Report_Form extends CRM_Core_Form { public $_whereClauses = array(); public $_havingClauses = array(); + /** + * dashBoardRowCount Dashboard row count + * @var Integer + */ + public $_dashBoardRowCount; + /** * Is this being called without a form controller (ie. the report is being render outside the normal form * - e.g the api is retrieving the rows @@ -345,6 +351,13 @@ class CRM_Report_Form extends CRM_Core_Form { 'Boolean', CRM_Core_DAO::$_nullObject ); + + $this->_dashBoardRowCount = + CRM_Utils_Request::retrieve( + 'rowCount', + 'Integer', + CRM_Core_DAO::$_nullObject + ); $this->_section = CRM_Utils_Request::retrieve('section', 'Integer', CRM_Core_DAO::$_nullObject); @@ -2680,6 +2693,11 @@ WHERE cg.extends IN ('" . implode("','", $this->_customGroupExtends) . "') AND function limit($rowCount = self::ROW_COUNT_LIMIT) { // lets do the pager if in html mode $this->_limit = NULL; + + // CRM-14115, over-ride row count if rowCount is specified in URL + if ($this->_dashBoardRowCount) { + $rowCount = $this->_dashBoardRowCount; + } if ($this->_outputMode == 'html' || $this->_outputMode == 'group') { $this->_select = str_ireplace('SELECT ', 'SELECT SQL_CALC_FOUND_ROWS ', $this->_select); @@ -2716,6 +2734,12 @@ WHERE cg.extends IN ('" . implode("','", $this->_customGroupExtends) . "') AND } function setPager($rowCount = self::ROW_COUNT_LIMIT) { + + // CRM-14115, over-ride row count if rowCount is specified in URL + if ($this->_dashBoardRowCount) { + $rowCount = $this->_dashBoardRowCount; + } + if ($this->_limit && ($this->_limit != '')) { $sql = "SELECT FOUND_ROWS();"; $this->_rowsFound = CRM_Core_DAO::singleValueQuery($sql); diff --git a/CRM/Report/Form/Contribute/TopDonor.php b/CRM/Report/Form/Contribute/TopDonor.php index 78bcc39ab3..51e71dce26 100644 --- a/CRM/Report/Form/Contribute/TopDonor.php +++ b/CRM/Report/Form/Contribute/TopDonor.php @@ -397,6 +397,11 @@ ORDER BY civicrm_contribution_total_amount_sum DESC function limit($rowCount = CRM_Report_Form::ROW_COUNT_LIMIT) { // lets do the pager if in html mode $this->_limit = NULL; + + // CRM-14115, over-ride row count if rowCount is specified in URL + if ($this->_dashBoardRowCount) { + $rowCount = $this->_dashBoardRowCount; + } if ($this->_outputMode == 'html' || $this->_outputMode == 'group') { //replace only first occurence of SELECT $this->_select = preg_replace('/SELECT/', 'SELECT SQL_CALC_FOUND_ROWS ', $this->_select, 1); diff --git a/CRM/Report/Form/Instance.php b/CRM/Report/Form/Instance.php index f5e307c071..f0e2a40231 100644 --- a/CRM/Report/Form/Instance.php +++ b/CRM/Report/Form/Instance.php @@ -80,7 +80,15 @@ class CRM_Report_Form_Instance { ts('CC'), $attributes['email_subject'] ); - + + $form->add('text', + 'row_count', + ts('Limit Dashboard Results'), + array('maxlength' => 64, + 'size' => 5 + ) + ); + $form->add('textarea', 'report_header', ts('Report Header'), @@ -97,7 +105,8 @@ class CRM_Report_Form_Instance { array('onclick' => "return showHideByValue('is_navigation','','navigation_menu','table-row','radio',false);") ); - $form->addElement('checkbox', 'addToDashboard', ts('Available for Dashboard?')); + $form->addElement('checkbox', 'addToDashboard', ts('Available for Dashboard?'), NULL, + array('onclick' => "return showHideByValue('addToDashboard','','limit_result','table-row','radio',false);")); $form->addElement('checkbox', 'is_reserved', ts('Reserved Report?')); if (!CRM_Core_Permission::check('administer reserved reports')) { $form->freeze('is_reserved'); diff --git a/templates/CRM/Report/Form/Instance.tpl b/templates/CRM/Report/Form/Instance.tpl index e4b638cf6d..2745751ba6 100644 --- a/templates/CRM/Report/Form/Instance.tpl +++ b/templates/CRM/Report/Form/Instance.tpl @@ -99,6 +99,10 @@ {ts}Users with appropriate permissions can add this report to their dashboard.{/ts} + + {$form.row_count.label} + {$form.row_count.html} + {include file="CRM/common/showHideByFieldValue.tpl" @@ -109,6 +113,14 @@ field_type ="radio" invert = 0 } +{include file="CRM/common/showHideByFieldValue.tpl" + trigger_field_id ="addToDashboard" + trigger_value ="" + target_element_id ="limit_result" + target_element_type ="table-row" + field_type ="radio" + invert = 0 +} {if $is_navigation}