From 6f900755312461a3cd4f58bba91abbb4dfcdd002 Mon Sep 17 00:00:00 2001 From: Eileen Date: Mon, 6 Jan 2014 15:44:23 +1300 Subject: [PATCH] CRM-13918 Report api - add ability to specify rowCount (& pager) as suggested by deepak ---------------------------------------- * CRM-13918: Add Report.getrows api http://issues.civicrm.org/jira/browse/CRM-13918 --- CRM/Report/Form.php | 46 +++++++++++++++++++++++++++++++++++++++ api/v3/ReportTemplate.php | 11 ++++++---- 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/CRM/Report/Form.php b/CRM/Report/Form.php index 92686b6b2d..dd24018223 100644 --- a/CRM/Report/Form.php +++ b/CRM/Report/Form.php @@ -194,7 +194,28 @@ class CRM_Report_Form extends CRM_Core_Form { protected $_rowsFound = NULL; protected $_selectAliases = array(); protected $_rollup = NULL; + + /** + * SQL Limit clause + * @var string + */ protected $_limit = NULL; + + /** + * This can be set to specify a limit to the number of rows + * Since it is currently envisaged as part of the api usage it is only being applied + * when $_output mode is not 'html' or 'group' so as not to have to interpret / mess with that part + * of the code (see limit() fn + * @var integer + */ + protected $_limitValue = NULL; + + /** + * This can be set to specify row offset + * See notes on _limitValue + * @var integer + */ + protected $_offsetValue = NULL; protected $_sections = NULL; protected $_autoIncludeIndexedFieldsAsOrderBys = 0; protected $_absoluteUrl = FALSE; @@ -767,6 +788,23 @@ class CRM_Report_Form extends CRM_Core_Form { function setForce($isForce) { $this->_force = $isForce; } + + /** + * Setter for $_limitValue + * @param number $_limitValue + */ + function setLimitValue($_limitValue) { + $this->_limitValue = $_limitValue; + } + + /** + * Setter for $_offsetValue + * @param number $_offsetValue + */ + function setOffsetValue($_offsetValue) { + $this->_offsetValue = $_offsetValue; + } + /** * Getter for $_defaultValues * @return array $_defaultValues @@ -2668,6 +2706,14 @@ WHERE cg.extends IN ('" . implode("','", $this->_customGroupExtends) . "') AND $this->_limit = " LIMIT $offset, $rowCount"; return array($offset, $rowCount); } + if($this->_limitValue) { + if($this->_offsetValue) { + $this->_limit = " LIMIT {$this->_offsetValue}, {$this->_limitValue} "; + } + else { + $this->_limit = " LIMIT " . $this->_limitValue; + } + } } function setPager($rowCount = self::ROW_COUNT_LIMIT) { diff --git a/api/v3/ReportTemplate.php b/api/v3/ReportTemplate.php index 37ffaeb965..b52cefa15f 100644 --- a/api/v3/ReportTemplate.php +++ b/api/v3/ReportTemplate.php @@ -93,10 +93,10 @@ function civicrm_api3_report_template_getrows($params) { function _civicrm_api3_report_template_getrows($params) { $class = civicrm_api3('option_value', 'getvalue', array( - 'option_group_id' => 'report_template', - 'return' => 'name', - 'value' => $params['report_id'], - ) + 'option_group_id' => 'report_template', + 'return' => 'name', + 'value' => $params['report_id'], + ) ); $reportInstance = new $class(); @@ -108,6 +108,9 @@ function _civicrm_api3_report_template_getrows($params) { $reportInstance->preProcess(); $reportInstance->setDefaultValues(FALSE); $reportInstance->setParams(array_merge($reportInstance->getDefaultValues(), $params)); + $options = _civicrm_api3_get_options_from_params($params, TRUE,'report_template','get'); + $reportInstance->setLimitValue($options['limit']); + $reportInstance->setOffsetValue($options['offset']); $reportInstance->beginPostProcessCommon(); $sql = $reportInstance->buildQuery(); $rows = array(); -- 2.25.1