-
-
Notifications
You must be signed in to change notification settings - Fork 814
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
CRM-21520: Implement Search Action to Add Contacts to Case #11371
Changes from 1 commit
f1d7f28
cf0adfd
3e240fc
c47ab74
245992c
66504fe
d4739db
44ca57d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
require_once 'CRM/Core/Page.php'; | ||
|
||
class CRM_Case_Form_AddContact extends CRM_Core_Form { | ||
public function buildQuickForm() { | ||
$formBuilder = new CRM_Case_FormBuilder($this); | ||
$formBuilder->build(); | ||
} | ||
|
||
public function postProcess() { | ||
$values = $this->controller->exportValues(); | ||
|
||
$caseId = (int)$values['assign_to']; | ||
$roleTypeId = (int)$values['role_type']; | ||
$contacts = array((int)CRM_Utils_Request::retrieve('cid', 'Positive')); | ||
|
||
$clients = CRM_Case_BAO_Case::getCaseClients($caseId); | ||
|
||
$params = array( | ||
'contact_id_a' => $clients[0], | ||
'contact_id_b' => $contacts, | ||
'case_id' => $caseId, | ||
'relationship_type_id' => $roleTypeId | ||
); | ||
|
||
CRM_Contact_BAO_Relationship::createMultiple($params, 'a'); | ||
|
||
CRM_Core_Session::setStatus(ts('Contact has been added to case.'), 'Information', 'success'); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
class CRM_Case_Form_AddToCaseAsRole extends CRM_Contact_Form_Task { | ||
public function buildQuickForm() { | ||
$formBuilder = new CRM_Case_FormBuilder($this); | ||
$formBuilder->build(); | ||
} | ||
|
||
public function postProcess() { | ||
$values = $this->controller->exportValues(); | ||
|
||
$caseId = (int)$values['assign_to']; | ||
$roleTypeId = (int)$values['role_type']; | ||
$contacts = $this->_contactIds; | ||
|
||
$clients = CRM_Case_BAO_Case::getCaseClients($caseId); | ||
|
||
$params = array( | ||
'contact_id_a' => $clients[0], | ||
'contact_id_b' => $contacts, | ||
'case_id' => $caseId, | ||
'relationship_type_id' => $roleTypeId | ||
); | ||
|
||
CRM_Contact_BAO_Relationship::createMultiple($params, 'a'); | ||
|
||
$url = CRM_Utils_System::url( | ||
'civicrm/contact/view/case', | ||
sprintf('cid=%d&id=%d', $clients[0], $caseId) | ||
); | ||
CRM_Utils_System::redirect($url); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
class CRM_Case_FormBuilder { | ||
private $form; | ||
|
||
public function __construct(CRM_Core_Form $form) { | ||
$this->form = $form; | ||
} | ||
|
||
public function build() { | ||
$this->form->add('text', 'assign_to', ts('Assign to')); | ||
$roleTypes = $this->getRoleTypes(); | ||
|
||
$this->form->add( | ||
'select', | ||
'role_type', | ||
ts('Relationship Type'), | ||
array('' => ts('- select type -')) + $roleTypes, | ||
FALSE, | ||
array('class' => 'crm-select2 twenty') | ||
); | ||
|
||
$this->form->addButtons(array( | ||
array( | ||
'type' => 'submit', | ||
'name' => ts('Submit'), | ||
'isDefault' => true | ||
) | ||
)); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
private function getRoleTypes() { | ||
$relType = CRM_Contact_BAO_Relationship::getRelationType('Individual'); | ||
$roleTypes = array(); | ||
foreach ($relType as $k => $v) { | ||
$roleTypes[substr($k, 0, strpos($k, '_'))] = $v; | ||
} | ||
return $roleTypes; | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't really understand the purpose of breaking these 2 functions into a separate file. What's wrong with doing this in the |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -136,4 +136,11 @@ | |
<path>civicrm/ajax/delcaserole</path> | ||
<page_callback>CRM_Case_Page_AJAX::deleteCaseRoles</page_callback> | ||
</item> | ||
<item> | ||
<path>civicrm/case/add-contact</path> | ||
<page_callback>CRM_Case_Form_AddContact</page_callback> | ||
<title>AddContact</title> | ||
<access_arguments>access CiviCRM</access_arguments> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think access_arguments should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, what is this entry? I don't think this class exists. Can this be removed? |
||
<page_type>0</page_type> | ||
</item> | ||
</menu> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{include file="CRM/Caseroles/Form/AddToCaseAsRole.tpl"} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file seems quite useless. What's the purpose of not putting the contents of |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<div><label for="assign_to">{ts}Assign To{/ts}:</label></div> | ||
<div><input name="assign_to" data-api-entity="case" placeholder="{ts}- select case -{/ts}" class="huge" /></div> | ||
|
||
<div>{$form.role_type.label}</div> | ||
<div>{$form.role_type.html}</div><br /> | ||
|
||
<div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div> | ||
|
||
{literal} | ||
<script type="text/javascript"> | ||
(function($, CRM) { | ||
$(function() { | ||
$('[name=assign_to], [name=role]', this) | ||
.val('') | ||
.crmEntityRef({create: false}); | ||
}); | ||
})(cj, CRM); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the reason for adding a simple textfield from the formbuilder and then javascripting it into an entityref after the fact? Why not just add an entityref from the getgo? |
||
</script> | ||
{/literal} |
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.
This is missing a few arguments so the redirect doesn't quite work. IMO an array is more readable than sprintf. Recommend changing to: