-
-
Notifications
You must be signed in to change notification settings - Fork 827
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[REF] Be able to remove clients whom are not the primary client of th… #24841
Closed
+5,197
−5,002
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@seamuslee001 If I understand the previous note correctly, I think you need to do something a bit more nuanced. The above will prevent the activity type from being created if CiviCase is not enabled, which addresses the immediate concern. But if a person enables CiviCase at a later time, we need to make sure this activity is created. So perhaps we need to also add this code to the CiviCase enabling process?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In a stock install without civicase the case-y stuff is still always inserted into the db at install time, so we should always insert this one too. How about without the
if
and set it like:'component_id' => CRM_Core_DAO::singleValueQuery("SELECT id FROM civicrm_component WHERE name='CiviCase'"),