public $_having = NULL;
public $_select = NULL;
+ public $_selectClauses = array();
public $_columnHeaders = array();
public $_orderBy = NULL;
+ public $_orderByFields = array();
+ public $_orderByArray = array();
public $_groupBy = NULL;
public $_whereClauses = array();
public $_havingClauses = array();
// Get all custom groups
$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';
- $permCustomGroupIds = CRM_ACL_API::group(CRM_Core_Permission::VIEW, NULL, 'civicrm_custom_group', $allGroups, NULL);
-
- // do not allow custom data for reports if user don't have
- // permission to access custom data.
- if (!empty($this->_customGroupExtends) && !CRM_Core_Permission::check('access all custom data') && empty($permCustomGroupIds)) {
- $this->_customGroupExtends = array();
+ // Get the custom groupIds for which the user has VIEW permission
+ // If the user has 'access all custom data' permission, we'll leave $permCustomGroupIds empty
+ // and addCustomDataToColumns() will allow access to all custom groups.
+ $permCustomGroupIds = array();
+ if (!CRM_Core_Permission::check('access all custom data')) {
+ $permCustomGroupIds = CRM_ACL_API::group(CRM_Core_Permission::VIEW, NULL, 'civicrm_custom_group', $allGroups, NULL);
+ // do not allow custom data for reports if user doesn't have
+ // permission to access custom data.
+ if (!empty($this->_customGroupExtends) && empty($permCustomGroupIds)) {
+ $this->_customGroupExtends = array();
+ }
}
// merge custom data columns to _columns list, if any
}
// a few auto fills for filters
- if ($fieldGrp == 'filters') {
+ if ($fieldGrp == 'filters') {
// fill operator types
if (!array_key_exists('operatorType', $this->_columns[$tableName][$fieldGrp][$fieldName])) {
switch (CRM_Utils_Array::value('type', $this->_columns[$tableName][$fieldGrp][$fieldName])) {
$this->_columns[$tableName][$fieldGrp][$fieldName]['operatorType'] = CRM_Report_Form::OP_INT;
break;
case CRM_Utils_Type::T_DATE:
- $this->_columns[$tableName][$fieldGrp][$fieldName]['operatorType'] = CRM_Report_Form::OP_DATE;
+ $this->_columns[$tableName][$fieldGrp][$fieldName]['operatorType'] = CRM_Report_Form::OP_DATE;
break;
case CRM_Utils_Type::T_BOOLEAN:
$this->_columns[$tableName][$fieldGrp][$fieldName]['operatorType'] = CRM_Report_Form::OP_SELECT;
if (!array_key_exists('options', $this->_columns[$tableName][$fieldGrp][$fieldName])) {
- $this->_columns[$tableName][$fieldGrp][$fieldName]['options'] =
+ $this->_columns[$tableName][$fieldGrp][$fieldName]['options'] =
array('' => ts('Any'), '0' => ts('No'), '1' => ts('Yes'));
}
break;
default:
- if ($daoOrBaoName &&
- (array_key_exists('pseudoconstant', $this->_columns[$tableName][$fieldGrp][$fieldName])
+ if ($daoOrBaoName &&
+ (array_key_exists('pseudoconstant', $this->_columns[$tableName][$fieldGrp][$fieldName])
|| array_key_exists('enumValues', $this->_columns[$tableName][$fieldGrp][$fieldName]))
) {
// with multiple options operator-type is generally multi-select
foreach ($this->_columns as $tableName => $table) {
if (array_key_exists('fields', $table)) {
foreach ($table['fields'] as $fieldName => $field) {
- if (!array_key_exists('no_display', $field)) {
+ if (!CRM_Utils_Array::value('no_display', $field)) {
if (isset($field['required'])) {
// set default
$this->_defaults['fields'][$fieldName] = 1;
if (array_key_exists('fields', $table)) {
foreach ($table['fields'] as $fieldName => $field) {
$groupTitle = '';
- if (!array_key_exists('no_display', $field)) {
+ if (!CRM_Utils_Array::value('no_display', $field)) {
foreach ( array('table', 'field') as $var) {
if (!empty(${$var}['grouping'])) {
if (!is_array(${$var}['grouping'])) {
if ($this->_autoIncludeIndexedFieldsAsOrderBys && array_key_exists('extends', $table) && !empty($table['extends'])) {
foreach ($table['fields'] as $fieldName => $field) {
- if (!array_key_exists('no_display', $field)) {
+ if (!CRM_Utils_Array::value('no_display', $field)) {
$options[$fieldName] = $field['title'];
}
}
// unset columns not to be displayed.
foreach ($this->_columnHeaders as $key => $value) {
- if (is_array($value) && isset($value['no_display'])) {
+ if (CRM_Utils_Array::value('no_display', $value)) {
unset($this->_columnHeaders[$key]);
}
}
// still be having their own select() method. We should fix them as and when encountered and move
// towards generalizing the select() method below.
function select() {
- $select = array();
+ $select = $this->_selectAliases = array();
foreach ($this->_columns as $tableName => $table) {
if (array_key_exists('fields', $table)) {
}
}
+ $this->_selectClauses = $select;
$this->_select = "SELECT " . implode(', ', $select) . " ";
}
}
$this->assign('sections', $this->_sections);
}
+
/*
* In some cases other functions want to know which fields are selected for ordering by
* Separating this into a separate function allows it to be called separately from constructing
if (!empty($fields) && is_array($fields)) {
foreach ($fields as $fieldName => $field) {
if ($fieldName == $orderBy['column']) {
- $orderByField = $field;
+ $orderByField = array_merge($field, $orderBy);
$orderByField['tplField'] = "{$tableName}_{$fieldName}";
break 2;
}
}
if (!empty($orderByField)) {
+ $this->_orderByFields[] = $orderByField;
$orderBys[] = "{$orderByField['dbAlias']} {$orderBy['order']}";
// Record any section headers for assignment to the template
}
}
}
+
if (is_array($this->_sections)) {
return array_diff_key($this->_sections, $selectColumns);
}
$this->set(CRM_Utils_Pager::PAGE_ID, $pageId);
$offset = ($pageId - 1) * $rowCount;
- $this->_limit = " LIMIT $offset, " . $rowCount;
+ $offset = CRM_Utils_Type::escape($offset, 'Int');
+ $rowCount = CRM_Utils_Type::escape($rowCount, 'Int');
+
+ $this->_limit = " LIMIT $offset, $rowCount";
return array($offset, $rowCount);
}
}