*/
protected $_selectedTables;
+ /**
+ * outputmode e.g 'print', 'csv', 'pdf'
+ * @todo have declared this as public as fixing an e-Notice in a point release - would
+ * be better converted to protected in 4.5
+ * @var string
+ */
+ public $_outputMode;
+
public $_having = NULL;
public $_select = NULL;
public $_selectClauses = array();
public $_whereClauses = array();
public $_havingClauses = array();
+ /**
+ * 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
+ * @var boolean
+ */
+ public $noController = FALSE;
+
/**
* Variable to hold the currency alias
*/
CRM_Core_Region::instance('page-header')->add(array(
'markup' => sprintf('<!-- Report class: [%s] -->', htmlentities(get_class($this))),
));
+ if(!$this->noController) {
+ $this->setID($this->get('instanceId'));
- $this->_id = $this->get('instanceId');
- if (!$this->_id) {
- $this->_id = CRM_Report_Utils_Report::getInstanceID();
if (!$this->_id) {
- $this->_id = CRM_Report_Utils_Report::getInstanceIDForPath();
+ $this->setID(CRM_Report_Utils_Report::getInstanceID());
+ if (!$this->_id) {
+ $this->setID( CRM_Report_Utils_Report::getInstanceIDForPath());
+ }
}
- }
- // set qfkey so that pager picks it up and use it in the "Next > Last >>" links.
- // FIXME: Note setting it in $_GET doesn't work, since pager generates link based on QUERY_STRING
- $_SERVER['QUERY_STRING'] .= "&qfKey={$this->controller->_key}";
+ // set qfkey so that pager picks it up and use it in the "Next > Last >>" links.
+ // FIXME: Note setting it in $_GET doesn't work, since pager generates link based on QUERY_STRING
+ $_SERVER['QUERY_STRING'] .= "&qfKey={$this->controller->_key}";
+ }
if ($this->_id) {
$this->assign('instanceId', $this->_id);
// set the mode
$this->assign('mode', 'instance');
}
- else {
+ elseif (!$this->noController) {
list($optionValueID, $optionValue) = CRM_Report_Utils_Report::getValueIDFromUrl();
$instanceCount = CRM_Report_Utils_Report::getInstanceCount($optionValue);
if (($instanceCount > 0) && $optionValueID) {
return FALSE;
}
+ /**
+ * Setter for $_params
+ * @param array $params
+ */
+ function setParams($params) {
+ $this->_params = $params;
+ }
+
+ /**
+ * Setter for $_id
+ * @param integer $id
+ */
+ function setID($instanceid) {
+ $this->_id = $instanceid;
+ }
+
+ /**
+ * Setter for $_force
+ * @param boolean $force
+ */
+ function setForce($isForce) {
+ $this->_force = $isForce;
+ }
+ /**
+ * Getter for $_defaultValues
+ * @return array $_defaultValues
+ */
+ function getDefaultValues() {
+ return $this->_defaults;
+ }
+
function addColumns() {
$options = array();
$colGroups = NULL;
}
function beginPostProcess() {
- $this->_params = $this->controller->exportValues($this->_name);
+ $this->setParams($this->controller->exportValues($this->_name));
if (empty($this->_params) &&
$this->_force
) {
- $this->_params = $this->_formValues;
+ $this->setParams($this->_formValues);
}
// hack to fix params when submitted from dashboard, CRM-8532
// fields array is missing because form building etc is skipped
// in dashboard mode for report
+ //@todo - this could be done in the dashboard no we have a setter
if (!CRM_Utils_Array::value('fields', $this->_params) && !$this->_noFields) {
- $this->_params = $this->_formValues;
+ $this->setParams($this->_formValues);
}
$this->_formValues = $this->_params;
$this->assign('updateReportButton', TRUE);
}
$this->processReportMode();
+ $this->beginPostProcessCommon();
+ }
+
+ /**
+ * beginPostProcess function run in both report mode and non-report mode (api)
+ */
+ function beginPostProcessCommon() {
+
}
function buildQuery($applyLimit = TRUE) {
return civicrm_api3_option_value_delete($params);
}
+/**
+ * Retrieve rows from a report template
+ *
+ * @param array $params input parameters
+ *
+ * @return array details of found instances
+ * @access public
+ */
+function civicrm_api3_report_template_getrows($params) {
+ list($rows, $instance) = _civicrm_api3_report_template_getrows($params);
+ return civicrm_api3_create_success($rows, $params, 'report_template');
+}
+
+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'],
+ )
+ );
+
+ $reportInstance = new $class();
+ if(!empty($params['instance_id'])) {
+ $reportInstance->setID($params['instance_id']);
+ }
+ $reportInstance->setParams($params);
+ $reportInstance->noController = TRUE;
+ $reportInstance->preProcess();
+ $reportInstance->setDefaultValues(FALSE);
+ $reportInstance->setParams(array_merge($reportInstance->getDefaultValues(), $params));
+ $reportInstance->beginPostProcessCommon();
+ $sql = $reportInstance->buildQuery();
+ $rows = array();
+ $reportInstance->buildRows($sql, $rows);
+ return array($rows, $reportInstance);
+}
+
+function civicrm_api3_report_template_getstatistics($params) {
+ list($rows, $reportInstance) = _civicrm_api3_report_template_getrows($params);
+ $stats = $reportInstance->statistics($rows);
+ return civicrm_api3_create_success($stats, $params, 'report_template');
+}
+/**
+ * Retrieve rows from a report template
+ *
+ * @param array $params input parameters
+ *
+ * @return array details of found instances
+ * @access public
+ */
+function _civicrm_api3_report_template_getrows_spec(&$params) {
+ $params['report_id'] = array(
+ 'api.required' => TRUE,
+ 'title' => 'Report ID - eg. member/lapse',
+ );
+}
+
/*
function civicrm_api3_report_template_getfields($params) {
return civicrm_api3_create_success(array(