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

Modify to allow any other than the currently viewed contact to be removed from a case and create activity when it is removed
  • Loading branch information
seamuslee001 committed Nov 14, 2022
1 parent 7762f45 commit ded1760
Show file tree
Hide file tree
Showing 8 changed files with 5,202 additions and 5,008 deletions.
130 changes: 130 additions & 0 deletions CRM/Case/Form/DeleteClient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<?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 |
+--------------------------------------------------------------------+
*/
use Civi\Api4\CaseContact;

/**
*
* @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;

/**
* Return ContactId
* @var int
*/
protected $returnContactId;

/**
* 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);
$this->returnContactId = CRM_Utils_Request::retrieve('rcid', '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);
$caseContacts = CaseContact::get()->addWhere('case_id', '=', $this->id)->execute();
if (count($caseContacts) === 1) {
CRM_Core_Error::statusBounce(ts('Cannot Remove Client from case as is the only client on the case'), $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"],
]);
civicrm_api3('Activity', 'create', [
'activity_type_id' => 'Case Client Removed',
'subject' => ts('Case Client Removed'),
'source_contact_id' => CRM_Core_Session::getLoggedInContactID(),
'case_id' => $params['id'],
'target_contact_id' => $params['contact_id'],
]);

// user context
$url = CRM_Utils_System::url('civicrm/contact/view/case',
"reset=1&action=view&cid={$this->returnContactId}&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>
12 changes: 6 additions & 6 deletions CRM/Core/DAO/County.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* Generated from xml/schema/CRM/Core/County.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:92832b47b40ec2c72c41adfa9442b635)
* (GenCodeChecksum:e932f1c10938d67078e2343656b68903)
*/

/**
Expand Down Expand Up @@ -132,7 +132,7 @@ public static function &fields() {
'where' => 'civicrm_county.id',
'table_name' => 'civicrm_county',
'entity' => 'County',
'bao' => 'CRM_Core_DAO_County',
'bao' => 'CRM_Core_BAO_County',
'localizable' => 0,
'html' => [
'type' => 'Number',
Expand All @@ -154,7 +154,7 @@ public static function &fields() {
'export' => TRUE,
'table_name' => 'civicrm_county',
'entity' => 'County',
'bao' => 'CRM_Core_DAO_County',
'bao' => 'CRM_Core_BAO_County',
'localizable' => 0,
'add' => '1.1',
],
Expand All @@ -168,7 +168,7 @@ public static function &fields() {
'where' => 'civicrm_county.abbreviation',
'table_name' => 'civicrm_county',
'entity' => 'County',
'bao' => 'CRM_Core_DAO_County',
'bao' => 'CRM_Core_BAO_County',
'localizable' => 0,
'add' => '1.1',
],
Expand All @@ -181,7 +181,7 @@ public static function &fields() {
'where' => 'civicrm_county.state_province_id',
'table_name' => 'civicrm_county',
'entity' => 'County',
'bao' => 'CRM_Core_DAO_County',
'bao' => 'CRM_Core_BAO_County',
'localizable' => 0,
'FKClassName' => 'CRM_Core_DAO_StateProvince',
'html' => [
Expand All @@ -205,7 +205,7 @@ public static function &fields() {
'default' => '1',
'table_name' => 'civicrm_county',
'entity' => 'County',
'bao' => 'CRM_Core_DAO_County',
'bao' => 'CRM_Core_BAO_County',
'localizable' => 0,
'add' => '5.35',
],
Expand Down
15 changes: 15 additions & 0 deletions CRM/Upgrade/Incremental/php/FiveFiftySeven.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@ class CRM_Upgrade_Incremental_php_FiveFiftySeven extends CRM_Upgrade_Incremental
*/
public function upgrade_5_57_alpha1($rev): void {
$this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
$this->addTask('Add in Client Removed Activity Type', 'addCaseClientRemovedActivity');
}

public static function addCaseClientRemovedActivity() {
CRM_Core_BAO_OptionValue::ensureOptionValueExists([
'option_group_id' => 'activity_type',
'name' => 'Case Client Removed',
'label' => ts('Case Client was removed from Case'),
'description' => ts('Case client was removed from a case'),
'is_active' => TRUE,
'filter' => 1,
'component_id' => CRM_Core_Component::getComponentID('CiviCase'),
'icon' => 'fa-trash'
]);
return TRUE;
}

}
Loading

0 comments on commit ded1760

Please sign in to comment.