-- CRM-14115, added code to limit count on dashboard.
authorPradeep Nayak <pradeep.nayak@webaccess.co.in>
Sat, 3 May 2014 13:54:29 +0000 (19:24 +0530)
committerPradeep Nayak <pradeep.nayak@webaccess.co.in>
Sat, 3 May 2014 13:54:29 +0000 (19:24 +0530)
----------------------------------------
* CRM-14115: Allow maximum number of Reportlet rows to be specified
  https://issues.civicrm.org/jira/browse/CRM-14115

CRM/Report/BAO/ReportInstance.php
CRM/Report/Form.php
CRM/Report/Form/Contribute/TopDonor.php
CRM/Report/Form/Instance.php
templates/CRM/Report/Form/Instance.tpl

index 2094b55457fe1b27b14e806318a7ce3cabba2d3d..afd4cf0dd4b02eb9733a424d49fd3072f251462c 100644 (file)
@@ -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&section={$section}&snippet=5{$chart}&context=dashlet";
-      $dashletParams['fullscreen_url'] = "civicrm/report/instance/{$instance->id}&reset=1&section={$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&section={$section}&snippet=5{$chart}&context=dashlet" . $limitResult;
+      $dashletParams['fullscreen_url'] = "civicrm/report/instance/{$instance->id}&reset=1&section={$section}&snippet=5{$chart}&context=dashletFullscreen" . $limitResult;
       $dashletParams['instanceURL'] = "civicrm/report/instance/{$instance->id}";
       CRM_Core_BAO_Dashboard::addDashlet($dashletParams);
     }
index 3fe222c536219651a6bf9c7e8ac6a5f20f0a0c1b..ab5638812518fdf3c4c4f1d1b11080ae7204e20e 100644 (file)
@@ -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);
index 78bcc39ab320d1abc9e7db0988a188db88c2d766..51e71dce2654c9e1fa2a2a3f6fbaf51913b84bb5 100644 (file)
@@ -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);
index f5e307c071874f57a0de9cad8e9f47689af86200..f0e2a40231b5d44e6f62ba38842f8523c11f26f6 100644 (file)
@@ -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');
index e4b638cf6dd86762e5c210ea078dd0a327a6a5d4..2745751ba69c5f241e1f776409980dd2b5ab7049 100644 (file)
         <span class="description">{ts}Users with appropriate permissions can add this report to their dashboard.{/ts}</span>
       </td>
     </tr>
+    <tr id ="limit_result" class="crm-report-instanceForm-form-block-limitUser">
+      <td class="report-label">{$form.row_count.label}</td>
+      <td>{$form.row_count.html}</td>
+    </tr>
 </table>
 
 {include file="CRM/common/showHideByFieldValue.tpl"
     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}
  <script type="text/javascript">