From cdd322b903ff52a94665327bb6c54913d17a69c3 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Fri, 14 Jul 2023 14:28:06 +1200 Subject: [PATCH] Reduce test fails on edge for Contact_Detail report There are still more - I lost the will --- CRM/Report/Form/Contact/Detail.php | 52 ++++++++++++++++-------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/CRM/Report/Form/Contact/Detail.php b/CRM/Report/Form/Contact/Detail.php index 1394293d97..6b54458eed 100644 --- a/CRM/Report/Form/Contact/Detail.php +++ b/CRM/Report/Form/Contact/Detail.php @@ -366,29 +366,23 @@ class CRM_Report_Form_Contact_Detail extends CRM_Report_Form { $this->setRowCount(10); } - public function preProcess() { + public function preProcess(): void { $this->_csvSupported = FALSE; parent::preProcess(); } - public function select() { + public function select(): void { $select = []; $this->_columnHeaders = []; - $this->_component = [ - 'contribution_civireport', - 'membership_civireport', - 'participant_civireport', - 'relationship_civireport', - 'activity_civireport', - ]; + foreach ($this->_columns as $tableName => $table) { if (array_key_exists('fields', $table)) { foreach ($table['fields'] as $fieldName => $field) { if (!empty($field['required']) || !empty($this->_params['fields'][$fieldName]) ) { - //isolate the select clause compoenent wise - if (in_array($table['alias'], $this->_component)) { + //isolate the select clause component wise + if (in_array($table['alias'], $this->getAvailableComponents())) { $select[$table['alias']][] = "{$field['dbAlias']} as {$tableName}_{$fieldName}"; $this->_columnHeadersComponent[$table['alias']]["{$tableName}_{$fieldName}"]['type'] = $field['type'] ?? NULL; $this->_columnHeadersComponent[$table['alias']]["{$tableName}_{$fieldName}"]['title'] = $field['title'] ?? NULL; @@ -427,7 +421,7 @@ class CRM_Report_Form_Contact_Detail extends CRM_Report_Form { } } - foreach ($this->_component as $val) { + foreach ($this->getAvailableComponents() as $val) { if (!empty($select[$val])) { $this->_selectComponent[$val] = "SELECT " . implode(', ', $select[$val]) . " "; unset($select[$val]); @@ -460,7 +454,7 @@ class CRM_Report_Form_Contact_Detail extends CRM_Report_Form { $this->joinEmailFromContact(); // only include tables that are in from clause - $componentTables = array_intersect($this->_aliases, $this->_component); + $componentTables = array_intersect($this->_aliases, $this->getAvailableComponents()); $componentTables = array_flip($componentTables); $this->_selectedTables = array_diff($this->_selectedTables, $componentTables); @@ -646,11 +640,10 @@ HERESQL; */ public function clauseComponent() { $selectedContacts = implode(',', $this->_contactSelected); - $contribution = $membership = $participant = NULL; $eligibleResult = $rows = $tempArray = []; - foreach ($this->_component as $val) { + foreach ($this->getAvailableComponents() as $val) { if (!empty($this->_selectComponent[$val]) && - ($val != 'activity_civireport' && $val != 'relationship_civireport') + ($val !== 'activity_civireport' && $val !== 'relationship_civireport') ) { $sql = <<_selectComponent[$val]} {$this->_formComponent[$val]} @@ -697,7 +690,7 @@ HERESQL; $dao = CRM_Core_DAO::executeQuery($sql); while ($dao->fetch()) { foreach ($this->_columnHeadersComponent[$val] as $key => $value) { - if ($key == 'civicrm_relationship_contact_id_b') { + if ($key === 'civicrm_relationship_contact_id_b') { $row[$key] = $dao->contact_b_name; continue; } @@ -712,7 +705,7 @@ HERESQL; $rows[$dao->contact_a_id][$val][] = $row; $row['civicrm_relationship_contact_id_b'] = $dao->contact_a_name; - $relTitle = "" . $dao->civicrm_relationship_relationship_type_id . + $relTitle = '' . $dao->civicrm_relationship_relationship_type_id . '_b_a'; if (isset($relTypes[$relTitle])) { $row['civicrm_relationship_relationship_type_id'] = $relTypes[$relTitle]; @@ -729,7 +722,7 @@ HERESQL; // target, assignee, source, or the client on a case. Since the vast // majority of activities will not involve the client, it's impractical to // retrieve all activities and use OR clauses in the WHERE. Instead, we - // use a union of subqueries for each of the four ways activities might + // use a union of sub-queries for each of the four ways activities might // join to the contact. $unionParts = []; foreach ($this->activityContactJoin as $activityContactJoinClauses) { @@ -773,7 +766,7 @@ HERESQL; } //unset the component header if data is not present - foreach ($this->_component as $val) { + foreach ($this->getAvailableComponents() as $val) { if (!in_array($val, $eligibleResult)) { unset($this->_columnHeadersComponent[$val]); @@ -838,18 +831,17 @@ HERESQL; $componentRows = $this->clauseComponent(); $this->alterComponentDisplay($componentRows); - //unset Conmponent id and contact id from display + //unset Component id and contact id from display foreach ($this->_columnHeadersComponent as $componentTitle => $headers) { $id_header = 'civicrm_' . substr_replace($componentTitle, '', -11, 11) . '_' . substr_replace($componentTitle, '', -11, 11) . '_id'; $contact_header = 'civicrm_' . substr_replace($componentTitle, '', -11, 11) . '_contact_id'; - if ($componentTitle == 'activity_civireport') { + if ($componentTitle === 'activity_civireport') { $id_header = 'civicrm_' . substr_replace($componentTitle, '', -11, 11) . '_id'; } - unset($this->_columnHeadersComponent[$componentTitle][$id_header]); - unset($this->_columnHeadersComponent[$componentTitle][$contact_header]); + unset($this->_columnHeadersComponent[$componentTitle][$id_header], $this->_columnHeadersComponent[$componentTitle][$contact_header]); } $this->assign_by_ref('columnHeadersComponent', $this->_columnHeadersComponent); @@ -927,7 +919,7 @@ HERESQL; $entryFound = TRUE; } - if ($component == 'membership_civireport') { + if ($component === 'membership_civireport') { if ($val = CRM_Utils_Array::value('civicrm_membership_membership_type_id', $row)) { $componentRows[$contactID][$component][$rowNum]['civicrm_membership_membership_type_id'] = CRM_Member_PseudoConstant::membershipType($val, FALSE); } @@ -992,4 +984,14 @@ HERESQL; } } + protected function getAvailableComponents(): array { + return [ + 'contribution_civireport', + 'membership_civireport', + 'participant_civireport', + 'relationship_civireport', + 'activity_civireport', + ]; + } + } -- 2.25.1