From 1ae15d3ef92b0b02f8de6a9cc6bd7559eb4cdcf8 Mon Sep 17 00:00:00 2001 From: Alice Frumin Date: Fri, 29 Mar 2019 15:07:21 -0400 Subject: [PATCH] Fix style warnings and test failures --- CRM/Activity/Page/AJAX.php | 2 +- CRM/Case/BAO/Case.php | 21 ++++++++-------- CRM/Case/Form/AddToCaseAsRole.php | 2 +- CRM/Case/ManagedEntities.php | 4 +++- CRM/Case/XMLProcessor/Process.php | 2 +- tests/karma/unit/crmCaseTypeSpec.js | 24 +++++++++++++++++++ .../phpunit/CRM/Case/BAO/CaseTypeForkTest.php | 2 +- 7 files changed, 42 insertions(+), 15 deletions(-) diff --git a/CRM/Activity/Page/AJAX.php b/CRM/Activity/Page/AJAX.php index cc04489cd51..a097e4d82ae 100644 --- a/CRM/Activity/Page/AJAX.php +++ b/CRM/Activity/Page/AJAX.php @@ -161,7 +161,7 @@ public static function getCaseRoles() { foreach ($caseRelationships as $key => $value) { // This role has been filled - unset($caseRoles[$value['relation_type'] . '_'. $value['relationship_direction']]); + unset($caseRoles[$value['relation_type'] . '_' . $value['relationship_direction']]); // mark original case relationships record to use on setting edit links below $caseRelationships[$key]['source'] = 'caseRel'; } diff --git a/CRM/Case/BAO/Case.php b/CRM/Case/BAO/Case.php index a78da8fc602..4e60660e74c 100644 --- a/CRM/Case/BAO/Case.php +++ b/CRM/Case/BAO/Case.php @@ -434,7 +434,7 @@ public static function getCaseActivityQuery($type = 'upcoming', $userID, $condit 'cov_status.label as case_status_name', 't_act.status_id', 'civicrm_case.start_date as case_start_date', - "IF(case_relationship.contact_id_b = $userID, case_relation_type.label_a_b, case_relation_type.label_b_a) as case_role", + "GROUP_CONCAT(DISTINCT IF(case_relationship.contact_id_b = $userID, case_relation_type.label_a_b, case_relation_type.label_b_a) SEPARATOR ', ') as case_role", ); if ($type == 'upcoming') { @@ -626,11 +626,11 @@ public static function getCases($allCases = TRUE, $params = array(), $context = $whereClauses = array('civicrm_case.is_deleted = 0 AND civicrm_contact.is_deleted <> 1'); if (!$allCases) { - $whereClauses[] .= " case_relationship.contact_id_b = {$userID} OR case_relationship.contact_id_a = {$userID}"; - $whereClauses[] .= ' case_relationship.is_active '; + $whereClauses[] = "(case_relationship.contact_id_b = {$userID} OR case_relationship.contact_id_a = {$userID})"; + $whereClauses[] = 'case_relationship.is_active'; } if (empty($params['status_id']) && ($type == 'upcoming' || $type == 'any')) { - $whereClauses[] = " civicrm_case.status_id != " . CRM_Core_PseudoConstant::getKey('CRM_Case_BAO_Case', 'case_status_id', 'Closed'); + $whereClauses[] = "civicrm_case.status_id != " . CRM_Core_PseudoConstant::getKey('CRM_Case_BAO_Case', 'case_status_id', 'Closed'); } foreach (array('case_type_id', 'status_id') as $column) { @@ -791,13 +791,13 @@ public static function getCasesSummary($allCases = TRUE) { // build rows with actual data $rows = array(); - $myGroupByClause = $mySelectClause = $myCaseFromClause = $myCaseWhereClause = ''; + $myGroupByClause = $mySelectClause = $myCaseFromClause = $myCaseWhereClauseA = $myCaseWhereClauseB = ''; if ($allCases) { $userID = 'null'; $all = 1; $case_owner = 1; - $myGroupByClause = ' GROUP BY civicrm_case.id'; + $myGroupByClauseB = ' GROUP BY civicrm_case.id'; } else { $all = 0; @@ -807,8 +807,8 @@ public static function getCasesSummary($allCases = TRUE) { $myCaseWhereClauseB = " AND case_relationship.contact_id_b = {$userID} AND case_relationship.is_active "; $myGroupByClauseB = " GROUP BY CONCAT(case_relationship.case_id,'-',case_relationship.contact_id_b)"; } - $myGroupByClause .= ", case_status.label, status_id, case_type_id"; - + $myGroupByClauseB .= ", case_status.label, status_id, case_type_id"; + $myGroupByClauseA = $myGroupByClauseB; // FIXME: This query could be a lot more efficient if it used COUNT() instead of returning all rows and then counting them with php $query = " SELECT case_status.label AS case_status, status_id, civicrm_case_type.title AS case_type, @@ -1347,7 +1347,7 @@ public static function getRelatedContacts($caseID, $includeDetails = TRUE) { HERESQL; $params = array( 1 => array($caseID, 'Integer'), - 2 => array(implode(',', $caseInfo['client_id']), 'String') + 2 => array(implode(',', $caseInfo['client_id']), 'String'), ); $dao = CRM_Core_DAO::executeQuery($query, $params); @@ -3350,7 +3350,7 @@ public static function getEntityRefFilters() { /** * Fetch Case Role direction from Case Type */ - function getCaseRoleDirection($caseId, $roleTypeId = NULL) { + public static function getCaseRoleDirection($caseId, $roleTypeId = NULL) { try { $case = civicrm_api3('Case', 'getsingle', array('id' => $caseId)); } @@ -3400,4 +3400,5 @@ function getCaseRoleDirection($caseId, $roleTypeId = NULL) { return $caseRoles; } } + } diff --git a/CRM/Case/Form/AddToCaseAsRole.php b/CRM/Case/Form/AddToCaseAsRole.php index 51124087ab7..467949ac545 100644 --- a/CRM/Case/Form/AddToCaseAsRole.php +++ b/CRM/Case/Form/AddToCaseAsRole.php @@ -85,7 +85,7 @@ public function postProcess() { $params['contact_id_b'] = $contacts; CRM_Contact_BAO_Relationship::createMultiple($params, 'a'); } - + $url = CRM_Utils_System::url( 'civicrm/contact/view/case', array( diff --git a/CRM/Case/ManagedEntities.php b/CRM/Case/ManagedEntities.php index 13e06dd9132..ed558c2675c 100644 --- a/CRM/Case/ManagedEntities.php +++ b/CRM/Case/ManagedEntities.php @@ -113,7 +113,7 @@ public static function createManagedRelationshipTypes(CRM_Case_XMLRepository $xm $validRelTypes = []; foreach ($relationshipInfo as $id => $relTypeDetails) { $validRelTypes["{$id}_a_b"] = $relTypeDetails['label_a_b']; - if ($relTypeDetails['label_a_b']!= $relTypeDetails['label_b_a']) { + if ($relTypeDetails['label_a_b'] != $relTypeDetails['label_b_a']) { $validRelTypes["{$id}_b_a"] = $relTypeDetails['label_b_a']; } } @@ -139,6 +139,7 @@ public static function createManagedRelationshipTypes(CRM_Case_XMLRepository $xm 'contact_sub_type_b' => NULL, ), ); + // We'll create managed-entity if this record doesn't exist yet // or if we previously decided to manage this record. if (!in_array($relType, $validRelTypes)) { @@ -148,6 +149,7 @@ public static function createManagedRelationshipTypes(CRM_Case_XMLRepository $xm $result[] = $managed; } } + return $result; } diff --git a/CRM/Case/XMLProcessor/Process.php b/CRM/Case/XMLProcessor/Process.php index c602b757f15..48b08b7f723 100644 --- a/CRM/Case/XMLProcessor/Process.php +++ b/CRM/Case/XMLProcessor/Process.php @@ -238,7 +238,7 @@ public function createRelationships($relationshipTypeName, &$params) { 'start_date' => date("Ymd"), 'end_date' => CRM_Utils_Array::value('relationship_end_date', $params), ); - + if (substr($relationshipType, -4) == '_b_a') { $relationshipParams['contact_id_b'] = $clientId; $relationshipParams['contact_id_a'] = $params['creatorID']; diff --git a/tests/karma/unit/crmCaseTypeSpec.js b/tests/karma/unit/crmCaseTypeSpec.js index 8ae00e6de9c..4b0a221346b 100644 --- a/tests/karma/unit/crmCaseTypeSpec.js +++ b/tests/karma/unit/crmCaseTypeSpec.js @@ -199,6 +199,30 @@ describe('crmCaseType', function() { } ] }, + relTypesForm: { + values: [ + { + "key": "14_b_a", + "value": "Benefits Specialist" + }, + { + "key": "14_a_b", + "value": "Benefits Specialist is" + }, + { + "key": "9_b_a", + "value": "Case Coordinator" + }, + { + "key": "9_a_b", + "value": "Case Coordinator is" + }, + { + "key": "2_b_a", + "value": "Spouse of" + } + ] + }, caseType: { "id": "1", "name": "housing_support", diff --git a/tests/phpunit/CRM/Case/BAO/CaseTypeForkTest.php b/tests/phpunit/CRM/Case/BAO/CaseTypeForkTest.php index 21f0c46eb63..5c9d7bca54f 100644 --- a/tests/phpunit/CRM/Case/BAO/CaseTypeForkTest.php +++ b/tests/phpunit/CRM/Case/BAO/CaseTypeForkTest.php @@ -38,7 +38,7 @@ public function testManagerContact() { ]); //Check if manager is correctly retrieved from xml processor. $xmlProcessor = new CRM_Case_XMLProcessor_Process(); - $this->assertEquals($relTypeID, $xmlProcessor->getCaseManagerRoleId('ForkableCaseType')); + $this->assertEquals($relTypeID . '_b_a', $xmlProcessor->getCaseManagerRoleId('ForkableCaseType')); }