Skip to content

Commit

Permalink
Fix style warnings and test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
alifrumin committed Apr 3, 2019
1 parent c551806 commit 1ae15d3
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 15 deletions.
2 changes: 1 addition & 1 deletion CRM/Activity/Page/AJAX.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand Down
21 changes: 11 additions & 10 deletions CRM/Case/BAO/Case.php
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -3400,4 +3400,5 @@ function getCaseRoleDirection($caseId, $roleTypeId = NULL) {
return $caseRoles;
}
}

}
2 changes: 1 addition & 1 deletion CRM/Case/Form/AddToCaseAsRole.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 3 additions & 1 deletion CRM/Case/ManagedEntities.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
}
}
Expand All @@ -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)) {
Expand All @@ -148,6 +149,7 @@ public static function createManagedRelationshipTypes(CRM_Case_XMLRepository $xm
$result[] = $managed;
}
}

return $result;
}

Expand Down
2 changes: 1 addition & 1 deletion CRM/Case/XMLProcessor/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down
24 changes: 24 additions & 0 deletions tests/karma/unit/crmCaseTypeSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/CRM/Case/BAO/CaseTypeForkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}


Expand Down

0 comments on commit 1ae15d3

Please sign in to comment.