return $getCount ? 0 : $casesList;
}
+ $type = $params['type'] ?? 'upcoming';
+
// Return cached value instead of re-running query
- if (isset(Civi::$statics[__CLASS__]['totalCount']) && $getCount) {
- return Civi::$statics[__CLASS__]['totalCount'];
+ if (isset(Civi::$statics[__CLASS__]['totalCount'][$type]) && $getCount) {
+ return Civi::$statics[__CLASS__]['totalCount'][$type];
}
- $type = CRM_Utils_Array::value('type', $params, 'upcoming');
$userID = CRM_Core_Session::getLoggedInContactID();
// validate access for all cases.
}
$condition = implode(' AND ', $whereClauses);
- Civi::$statics[__CLASS__]['totalCount'] = $totalCount = CRM_Core_DAO::singleValueQuery(self::getCaseActivityCountQuery($type, $userID, $condition));
+ Civi::$statics[__CLASS__]['totalCount'][$type] = $totalCount = CRM_Core_DAO::singleValueQuery(self::getCaseActivityCountQuery($type, $userID, $condition));
if ($getCount) {
return $totalCount;
}
}
}
+ /**
+ * Test that if there's only recently performed activities in the system
+ * and no future ones then it still shows on dashboard.
+ */
+ public function testOnlyRecent() {
+ $loggedInUserId = $this->createLoggedInUser();
+ $clientId = $this->individualCreate([], 0, TRUE);
+ // old start date so there's no upcoming
+ $caseObj = $this->createCase($clientId, $loggedInUserId, ['start_date' => date('Y-m-d', strtotime('-2 years'))]);
+ // quickie hack to make them all completed
+ CRM_Core_DAO::executeQuery("UPDATE civicrm_case_activity ca INNER JOIN civicrm_activity a ON a.id = ca.activity_id SET a.status_id = 2 WHERE ca.case_id = %1", [1 => [$caseObj->id, 'Integer']]);
+ // Add a recent one
+ $activity = $this->callAPISuccess('Activity', 'create', [
+ 'source_contact_id' => $loggedInUserId,
+ 'target_contact_id' => $clientId,
+ 'activity_type_id' => 'Follow up',
+ 'status_id' => 'Completed',
+ 'activity_date_time' => date('Y-m-d H:i:s', strtotime('-2 days')),
+ 'subject' => 'backdated',
+ 'case_id' => $caseObj->id,
+ ]);
+ $this->assertEquals(0, CRM_Case_BAO_Case::getCases(TRUE, ['type' => 'upcoming'], 'dashboard', TRUE));
+ $this->assertEquals(1, CRM_Case_BAO_Case::getCases(TRUE, ['type' => 'recent'], 'dashboard', TRUE));
+ }
+
}