Skip to content

Commit

Permalink
Merge pull request #390 from eileenmcnaughton/increment
Browse files Browse the repository at this point in the history
Extract adding fields to metadata
  • Loading branch information
eileenmcnaughton authored Jul 11, 2020
2 parents 8496081 + 563858c commit 8b304c1
Showing 1 changed file with 39 additions and 16 deletions.
55 changes: 39 additions & 16 deletions CRM/Extendedreport/Form/Report/ExtendedReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,16 +347,14 @@ public function getMetadata():array {
foreach ($this->_columns as $table => $tableSpec) {
foreach ($definitionTypes as $type) {
foreach ($tableSpec['metadata'] as $fieldName => $fieldSpec) {
$fieldSpec = array_merge(['table_name' => $table, 'group_title' => $tableSpec['group_title']], $fieldSpec);
if (!isset($this->metaData[$fieldName])) {
$this->metaData['metadata'][$fieldName] = $fieldSpec;
}
if ($fieldSpec['is_' . $type]) {
$this->metaData[$type][$fieldName] = $fieldSpec;
}
if ($type === 'filters' && !empty($fieldSpec['having'])) {
$this->metaData['having'][$fieldName] = $fieldSpec;
}
$fieldSpec = array_merge([
'table_name' => $table,
'group_title' => $tableSpec['group_title'],
'prefix' => $tableSpec['prefix'] ?? '',
'prefix_label' => $tableSpec['prefix_label'] ?? '',
], $fieldSpec);
$this->addFieldToMetadata($fieldSpec, $table, $fieldName);

}
}
}
Expand Down Expand Up @@ -840,8 +838,6 @@ function select() {
* Generally a rowHeader and a columnHeader will be defined.
*
* Column Header is optional - in which case a single total column will show.
*
* @throws \Exception
*/
function aggregateSelect() {
if (empty($this->_customGroupAggregates)) {
Expand Down Expand Up @@ -903,8 +899,6 @@ function aggregateSelect() {
* @param string $fieldName
* @param string $dbAlias
* @param array $spec
*
* @throws Exception
*/
function addColumnAggregateSelect($fieldName, $dbAlias, $spec) {
if (empty($fieldName)) {
Expand Down Expand Up @@ -2206,6 +2200,8 @@ function getTemplateFileName() {
*
* @param bool $addFields
* @param array $permCustomGroupIds
*
* @throws \CiviCRM_API3_Exception
*/
function addCustomDataToColumns($addFields = TRUE, $permCustomGroupIds = []) {
if (empty($this->_customGroupExtends)) {
Expand Down Expand Up @@ -2433,7 +2429,7 @@ public function extendedCustomDataFrom() {
continue;
}

$baseJoin = CRM_Utils_Array::value($prop['extends'], $this->_customGroupExtendsJoin, "{$this->_aliases[$prop['extends_table']]}.id");
$baseJoin = $this->_customGroupExtendsJoin[$prop['extends']] ?? "{$this->_aliases[$prop['extends_table']]}.id";
$customJoin = is_array($this->_customGroupJoin) ? $this->_customGroupJoin[$table] : $this->_customGroupJoin;
$tableKey = CRM_Utils_Array::value('prefix', $prop) . $prop['table_name'];
if (stripos($this->_from, $this->_aliases[$tableKey]) === FALSE) {
Expand Down Expand Up @@ -8017,7 +8013,7 @@ protected function getCustomDataDAOs($extends) {
if (empty($permissionedCustomGroupIDs)) {
return [];
}
$customGroupWhere = "cg.id IN (" . implode(',', $permissionedCustomGroupIDs) . ") AND";
$customGroupWhere = 'cg.id IN (' . implode(',', $permissionedCustomGroupIDs) . ') AND';
}
$extendsMap = [];
$extendsEntities = array_flip($extends);
Expand Down Expand Up @@ -8168,6 +8164,7 @@ protected function getCustomFieldMetadata($field, $prefixLabel, $prefix = '') {
* @param array $spec
*
* @return array
*
* @throws CRM_Core_Exception
*/
protected function getCustomFieldOptions($spec) {
Expand Down Expand Up @@ -8740,4 +8737,30 @@ protected function getAllUsedFields(): array {
);
}

/**
* @param array $fieldSpec
* @param string $tableKey
* @param string $fieldName
*/
protected function addFieldToMetadata($fieldSpec, string $tableKey, string $fieldName) {
$definitionTypes = [
'fields',
'filters',
'join_filters',
'group_bys',
'order_bys',
'aggregate_columns',
];
$this->_columns[$tableKey]['metadata'][] = $fieldSpec;
$this->metaData['metadata'][$fieldName] = $fieldSpec;
foreach ($definitionTypes as $type) {
if ($fieldSpec['is_' . $type]) {
$this->metaData[$type][$fieldName] = $fieldSpec;
}
if ($type === 'filters' && !empty($fieldSpec['having'])) {
$this->metaData['having'][$fieldName] = $fieldSpec;
}
}
}

}

0 comments on commit 8b304c1

Please sign in to comment.