<?php
-// $Id$
-
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.3 |
protected $_customGroupExtends = NULL;
protected $_customGroupFilters = TRUE;
protected $_customGroupGroupBy = FALSE;
+ protected $_customGroupJoin = 'LEFT JOIN';
/**
* build tags filter
protected $_autoIncludeIndexedFieldsAsOrderBys = 0;
protected $_absoluteUrl = FALSE;
+ /**
+ * Flag to indicate if result-set is to be stored in a class variable which could be retrieved using getResultSet() method.
+ *
+ * @var boolean
+ */
+ protected $_storeResultSet = FALSE;
+
+ /**
+ * When _storeResultSet Flag is set use this var to store result set in form of array
+ *
+ * @var boolean
+ */
+ protected $_resultSet = array();
+
/**
* To what frequency group-by a date column
*
}
// Get all custom groups
- $allGroups = CRM_Core_PseudoConstant::customGroup();
+ $allGroups = CRM_Core_PseudoConstant::get('CRM_Core_DAO_CustomField', 'custom_group_id');
// Get the custom groupIds for which the user have VIEW permission
require_once 'CRM/ACL/API.php';
$this->assign('instanceId', $this->_id);
$params = array('id' => $this->_id);
$this->_instanceValues = array();
- CRM_Core_DAO::commonRetrieve('CRM_Report_DAO_Instance',
+ CRM_Core_DAO::commonRetrieve('CRM_Report_DAO_ReportInstance',
$params,
$this->_instanceValues
);
// higher preference to bao object
if (array_key_exists('bao', $table)) {
- require_once str_replace('_', DIRECTORY_SEPARATOR, $table['bao'] . '.php');
- eval("\$expFields = {$table['bao']}::exportableFields( );");
+ $baoName = $table['bao'];
+ $expFields = $baoName::exportableFields( );
}
elseif (array_key_exists('dao', $table)){
- require_once str_replace('_', DIRECTORY_SEPARATOR, $table['dao'] . '.php');
- eval("\$expFields = {$table['dao']}::export( );");
+ $daoName = $table['dao'];
+ $expFields = $daoName::export( );
}
else{
$expFields = array();
foreach ($this->_columns as $tableName => $table) {
if (array_key_exists('fields', $table)) {
foreach ($table['fields'] as $fieldName => $field) {
+ $groupTitle = '';
if (!array_key_exists('no_display', $field)) {
- if (isset($field['grouping'])) {
- $tableName = $field['grouping'];
+ foreach ( array('table', 'field') as $var) {
+ if (!empty(${$var}['grouping'])) {
+ if (!is_array(${$var}['grouping'])) {
+ $tableName = ${$var}['grouping'];
+ } else {
+ $tableName = array_keys(${$var}['grouping']);
+ $tableName = $tableName[0];
+ $groupTitle = array_values(${$var}['grouping']);
+ $groupTitle = $groupTitle[0];
+ }
+ }
}
- elseif (isset($table['grouping'])) {
- $tableName = $table['grouping'];
+
+ if (!$groupTitle && isset($table['group_title'])) {
+ $groupTitle = $table['group_title'];
}
- $colGroups[$tableName]['fields'][$fieldName] = CRM_Utils_Array::value('title', $field);
- if (isset($table['group_title'])) {
- $colGroups[$tableName]['group_title'] = $table['group_title'];
+ $colGroups[$tableName]['fields'][$fieldName] = CRM_Utils_Array::value('title', $field);
+ if ($groupTitle && !CRM_Utils_Array::value('group_title', $colGroups[$tableName])) {
+ $colGroups[$tableName]['group_title'] = $groupTitle;
}
$options[$fieldName] = CRM_Utils_Array::value('title', $field);
case CRM_Report_FORM::OP_SELECT:
// assume a select field
$this->addElement('select', "{$fieldName}_op", ts('Operator:'), $operations);
- $this->addElement('select', "{$fieldName}_value", NULL, $field['options']);
+ if (!empty($field['options']))
+ $this->addElement('select', "{$fieldName}_value", NULL, $field['options']);
break;
case CRM_Report_FORM::OP_DATE:
if (isset($field['clause'])) {
// FIXME: we not doing escape here. Better solution is to use two
// different types - data-type and filter-type
- eval("\$clause = \"{$field['clause']}\";");
+ $clause = $field['clause'];
}
else {
$value = CRM_Utils_Type::escape($value, $type);
}
$lastRow = array_pop($rows);
- $this->_grandFlag = FALSE;
foreach ($this->_columnHeaders as $fld => $val) {
if (!in_array($fld, $this->_statFields)) {
if (!$this->_grandFlag) {
$select[] = "$stat({$field['dbAlias']}) as $alias";
$this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['title'] = $label;
$this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['type'] = $field['type'];
- $this->_statFields[] = $alias;
+ $this->_statFields[$label] = $alias;
$this->_selectAliases[] = $alias;
break;
$select[] = "COUNT({$field['dbAlias']}) as $alias";
$this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['title'] = $label;
$this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['type'] = CRM_Utils_Type::T_INT;
- $this->_statFields[] = $alias;
+ $this->_statFields[$label] = $alias;
+ $this->_selectAliases[] = $alias;
+ break;
+
+ case 'count_distinct':
+ $select[] = "COUNT(DISTINCT {$field['dbAlias']}) as $alias";
+ $this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['title'] = $label;
+ $this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['type'] = CRM_Utils_Type::T_INT;
+ $this->_statFields[$label] = $alias;
$this->_selectAliases[] = $alias;
break;
$select[] = "ROUND(AVG({$field['dbAlias']}),2) as $alias";
$this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['title'] = $label;
$this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['type'] = $field['type'];
- $this->_statFields[] = $alias;
+ $this->_statFields[$label] = $alias;
$this->_selectAliases[] = $alias;
break;
}
}
function endPostProcess(&$rows = NULL) {
+ if ( $this->_storeResultSet ) {
+ $this->_resultSet = $rows;
+ }
+
if ($this->_outputMode == 'print' ||
$this->_outputMode == 'pdf' ||
$this->_sendmail
}
}
+ function storeResultSet() {
+ $this->_storeResultSet = TRUE;
+ }
+
+ function getResultSet() {
+ return $this->_resultSet;
+ }
+
/*
* Get Template file name - use default form template if a specific one has not been set up for this report
*
continue;
}
+ $customJoin = is_array($this->_customGroupJoin) ? $this->_customGroupJoin[$table] : $this->_customGroupJoin;
$this->_from .= "
-LEFT JOIN $table {$this->_aliases[$table]} ON {$this->_aliases[$table]}.entity_id = {$this->_aliases[$extendsTable]}.id";
+{$customJoin} {$table} {$this->_aliases[$table]} ON {$this->_aliases[$table]}.entity_id = {$this->_aliases[$extendsTable]}.id";
// handle for ContactReference
if (array_key_exists('fields', $prop)) {
foreach ($prop['fields'] as $fieldName => $field) {
*/
function preProcessOrderBy(&$formValues) {
// Object to show/hide form elements
- $_showHide = &new CRM_Core_ShowHideBlocks('', '');
+ $_showHide = new CRM_Core_ShowHideBlocks('', '');
$_showHide->addShow('optionField_1');
function selectedTables() {
if (!$this->_selectedTables) {
$orderByColumns = array();
- if (is_array($this->_params['order_bys'])) {
+ if (array_key_exists('order_bys', $this->_params) && is_array($this->_params['order_bys'])) {
foreach ($this->_params['order_bys'] as $orderBy) {
$orderByColumns[] = $orderBy['column'];
}