Skip to content

Commit

Permalink
[REF] Be able to remove clients whom are not the primary client of th…
Browse files Browse the repository at this point in the history
…e case from manage case view
  • Loading branch information
seamuslee001 committed Oct 28, 2022
1 parent e2a2a09 commit 30f8b98
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CRM/Case/Form/CaseView.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ public function preProcess() {

$this->assign('contactID', $this->_contactID = (int) $this->get('cid'));
$this->assign('caseID', $this->_caseID = (int) $this->get('id'));
$this->assign('primaryCaseContactID', civicrm_api3('Activity', 'get', [
'case_id' => $this->_caseID,
'activity_type_id' => 'Open Case',
'return' => ['assignee_contact_id', 'source_contact_id', 'target_contact_id'],
'sequential' => 1,
])['values'][0]['target_contact_id'][0]);

// Access check.
if (!CRM_Case_BAO_Case::accessCase($this->_caseID, FALSE)) {
Expand Down
117 changes: 117 additions & 0 deletions CRM/Case/Form/DeleteClient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<?php
/*
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC. All rights reserved. |
| |
| This work is published under the GNU AGPLv3 license with some |
| permitted exceptions and without any warranty. For full license |
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/

/**
*
* @package CRM
* @copyright CiviCRM LLC https://civicrm.org/licensing
*/

/**
* This class assigns the current case to another client.
*/
class CRM_Case_Form_DeleteClient extends CRM_Core_Form {

/**
* case ID
* @var int
*/
protected $id;

/**
* Client ID
* @var int
*/
protected $cid;

/**
* Build all the data structures needed to build the form.
*/
public function preProcess() {
$this->cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
$this->id = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE);
$context = CRM_Utils_Request::retrieve('context', 'Alphanumeric', $this);

//get current client name.
$this->assign('currentClientName', CRM_Contact_BAO_Contact::displayName($this->cid));
$this->assign('id', $this->id);

//set the context.
$url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&force=1&cid={$this->cid}&selectedChild=case");
if ($context == 'search') {
$qfKey = CRM_Utils_Request::retrieve('key', 'String', $this);
//validate the qfKey
$urlParams = 'force=1';
if (CRM_Utils_Rule::qfKey($qfKey)) {
$urlParams .= "&qfKey=$qfKey";
}
$url = CRM_Utils_System::url('civicrm/case/search', $urlParams);
}
elseif ($context == 'dashboard') {
$url = CRM_Utils_System::url('civicrm/case', 'reset=1');
}
elseif (in_array($context, [
'dashlet',
'dashletFullscreen',
])) {
$url = CRM_Utils_System::url('civicrm/dashboard', 'reset=1');
}
$session = CRM_Core_Session::singleton();
$session->pushUserContext($url);
}

/**
* Build the form object.
*/
public function buildQuickForm() {
$this->add('hidden', 'id', $this->id);
$this->add('hidden', 'contact_id', $this->cid);
$this->addButtons([
[
'type' => 'submit',
'name' => ts('Remove Client from Case'),
],
[
'type' => 'cancel',
'name' => ts('Cancel'),
],
]);

// This form may change the url structure so should not submit via ajax
$this->preventAjaxSubmit();
}

/**
* Process the form.
*/
public function postProcess() {
$params = $this->controller->exportValues($this->_name);
civicrm_api3('CaseContact', 'get', [
'case_id' => $params['id'],
'contact_id' => $params['contact_id'],
'api.case_contact.delete' => ['id' => "\$value.id"],
]);

$pirmaryCaseContact = civicrm_api3('Activity', 'get', [
'case_id' => $this->id,
'activity_type_id' => 'Open Case',
'return' => ['assignee_contact_id', 'source_contact_id', 'target_contact_id'],
'sequential' => 1,
])['values'][0]['target_contact_id'][0];
// user context
$url = CRM_Utils_System::url('civicrm/contact/view/case',
"reset=1&action=view&cid={$pirmaryCaseContact}&id={$params['id']}&show=1"
);
CRM_Utils_System::redirect($url);

}

}
5 changes: 5 additions & 0 deletions CRM/Case/xml/Menu/Case.xml
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,9 @@
<title>Email</title>
<page_callback>CRM_Case_Form_Task_Email</page_callback>
</item>
<item>
<path>civicrm/contact/view/case/deleteClient</path>
<title>Remove Client</title>
<page_callback>CRM_Case_Form_DeleteClient</page_callback>
</item>
</menu>
2 changes: 1 addition & 1 deletion templates/CRM/Case/Form/CaseView.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<td colspan="5" class="label">
{ts}Clients:{/ts}
{foreach from=$caseRoles.client item=client name=clients}
<a href="{crmURL p='civicrm/contact/view' q="action=view&reset=1&cid=`$client.contact_id`"}" title="{ts}View contact record{/ts}">{$client.display_name}</a>{if not $smarty.foreach.clients.last}, &nbsp; {/if}
<a href="{crmURL p='civicrm/contact/view' q="action=view&reset=1&cid=`$client.contact_id`"}" title="{ts}View contact record{/ts}">{$client.display_name}</a>{if $primaryCaseContactID neq $client.contact_id && call_user_func(array('CRM_Core_Permission','giveMeAllACLs'))}<a href="{crmURL p='civicrm/contact/view/case/deleteClient' q="action=delete&reset=1&cid=`$client.contact_id`&id=`$caseId`"}" title="{ts}Remove Client{/ts}"><i class="crm-i fa-times" aria-hidden="true"></i></a>{/if}{if not $smarty.foreach.clients.last}, &nbsp; {/if}
{/foreach}
<a href="#addClientDialog" class="crm-hover-button case-miniform" title="{ts}Add Client{/ts}" data-key="{crmKey name='civicrm/case/ajax/addclient'}">
<i class="crm-i fa-user-plus" aria-hidden="true"></i>
Expand Down
18 changes: 18 additions & 0 deletions templates/CRM/Case/Form/DeleteClient.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{*
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC. All rights reserved. |
| |
| This work is published under the GNU AGPLv3 license with some |
| permitted exceptions and without any warranty. For full license |
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*}
{* template for assigning the current case to another client*}
<div class="crm-block crm-form-block crm-case-editclient-form-block">
<div class="messages status no-popup">
{icon icon="fa-info-circle"}{/icon} {ts 1=$currentClientName 2=$id}Remove Client %1 from case %2{/ts}
</div>
<div class="crm-form-block">
<div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
</div>
</div>

0 comments on commit 30f8b98

Please sign in to comment.