Skip to content

Commit

Permalink
Merge pull request #11350 from MiyaNoctem/CRM-21498-change-status-of-…
Browse files Browse the repository at this point in the history
…linked-cases

CRM-21498: Implement Option to Change Status of Linked Cases
  • Loading branch information
colemanw authored Jan 8, 2018
2 parents 8ba0b06 + 74b15fa commit 06640b2
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 6 deletions.
5 changes: 4 additions & 1 deletion CRM/Case/BAO/Case.php
Original file line number Diff line number Diff line change
Expand Up @@ -1989,7 +1989,8 @@ public static function getRelatedCases($caseId, $excludeDeleted = TRUE) {
SELECT relCase.id as id,
civicrm_case_type.title as case_type,
client.display_name as client_name,
client.id as client_id
client.id as client_id,
relCase.status_id
FROM civicrm_case relCase
INNER JOIN civicrm_case_contact relCaseContact ON ( relCase.id = relCaseContact.case_id )
INNER JOIN civicrm_contact client ON ( client.id = relCaseContact.contact_id )
Expand All @@ -1999,6 +2000,7 @@ public static function getRelatedCases($caseId, $excludeDeleted = TRUE) {
$dao = CRM_Core_DAO::executeQuery($query);
$contactViewUrl = CRM_Utils_System::url("civicrm/contact/view", "reset=1&cid=");
$hasViewContact = CRM_Core_Permission::giveMeAllACLs();
$statuses = CRM_Case_BAO_Case::buildOptions('status_id');

while ($dao->fetch()) {
$caseView = NULL;
Expand All @@ -2016,6 +2018,7 @@ public static function getRelatedCases($caseId, $excludeDeleted = TRUE) {
'case_id' => $dao->id,
'case_type' => $dao->case_type,
'client_name' => $clientView,
'case_status' => $statuses[$dao->status_id],
'links' => $caseView,
);
}
Expand Down
20 changes: 18 additions & 2 deletions CRM/Case/Form/Activity/ChangeCaseStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ public static function preProcess(&$form) {
if (!isset($form->_caseId)) {
CRM_Core_Error::fatal(ts('Case Id not found.'));
}

$form->addElement('checkbox', 'updateLinkedCases', NULL, NULL, array('class' => 'select-row'));

$caseID = CRM_Utils_Array::first($form->_caseId);
$cases = CRM_Case_BAO_Case::getRelatedCases($caseID);
$form->assign('linkedCases', $cases);
}

/**
Expand Down Expand Up @@ -136,23 +142,33 @@ public static function formRule($values, $files, $form) {
/**
* Process the form submission.
*
*
* @param CRM_Core_Form $form
* @param array $params
*/
public static function beginPostProcess(&$form, &$params) {
$params['id'] = CRM_Utils_Array::value('case_id', $params);

if ($params['updateLinkedCases'] === '1') {
$caseID = CRM_Utils_Array::first($form->_caseId);
$cases = CRM_Case_BAO_Case::getRelatedCases($caseID);

foreach ($cases as $currentCase) {
if ($currentCase['status_id'] != $params['case_status_id']) {
$form->_caseId[] = $currentCase['case_id'];
}
}
}
}

/**
* Process the form submission.
*
*
* @param CRM_Core_Form $form
* @param array $params
* @param CRM_Activity_BAO_Activity $activity
*/
public static function endPostProcess(&$form, &$params, $activity) {

$groupingValues = CRM_Core_OptionGroup::values('case_status', FALSE, TRUE, FALSE, NULL, 'value');

// Set case end_date if we're closing the case. Clear end_date if we're (re)opening it.
Expand Down
32 changes: 29 additions & 3 deletions templates/CRM/Case/Form/Activity/ChangeCaseStatus.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,40 @@
+--------------------------------------------------------------------+
*}
{* Template for "Change Case Status" activities. *}
<div class="crm-block crm-form-block crm-case-changecasestatus-form-block">
<div class="crm-block crm-form-block crm-case-changecasestatus-form-block">
<tr class="crm-case-changecasestatus-form-block-case_status_id">
<td class="label">{$form.case_status_id.label}</td>
<td>{$form.case_status_id.html}</td>
<td>{$form.case_status_id.html}</td>
</tr>
{if sizeof($linkedCases) > 0}
<tr>
<td rowspan="2">{ts}Update Linked Cases Status?{/ts}</td>
<td>{$form.updateLinkedCases.html}</td>
</tr>
<tr>
<td>
<table>
<tr>
<th>ID</th>
<th>Case Client</th>
<th>Case Type</th>
<th>Status</th>
</tr>
{foreach from=$linkedCases item="linkedCase"}
<tr>
<td>{$linkedCase.case_id}</td>
<td>{$linkedCase.client_name}</td>
<td>{$linkedCase.case_type}</td>
<td>{$linkedCase.case_status}</td>
</tr>
{/foreach}
</table>
</td>
</tr>
{/if}
{if $groupTree}
<tr>
<td colspan="2">{include file="CRM/Custom/Form/CustomData.tpl" noPostCustomButton=1}</td>
</tr>
{/if}
</div>
</div>

0 comments on commit 06640b2

Please sign in to comment.