4 * Class CRM_Case_Form_AddToCaseAsRole
6 class CRM_Case_Form_AddToCaseAsRole
extends CRM_Contact_Form_Task
{
11 public function buildQuickForm() {
13 $roleTypes = $this->getRoleTypes();
17 ts('Relationship Type'),
18 array('' => ts('- select type -')) +
$roleTypes,
20 array('class' => 'crm-select2 twenty')
26 array('entity' => 'Case'),
30 $this->addButtons(array(
33 'name' => ts('Submit'),
38 'name' => ts('Cancel'),
44 * Returns list of configured role types for individuals.
49 private function getRoleTypes() {
50 $relType = CRM_Contact_BAO_Relationship
::getRelationType('Individual');
53 foreach ($relType as $k => $v) {
54 $roleTypes[substr($k, 0, strpos($k, '_'))] = $v;
63 public function postProcess() {
64 $values = $this->controller
->exportValues();
66 $caseId = (int) $values['assign_to'];
67 $roleTypeId = (int) $values['role_type'];
68 $contacts = $this->_contactIds
;
70 $clients = CRM_Case_BAO_Case
::getCaseClients($caseId);
73 'contact_id_a' => $clients[0],
74 'contact_id_b' => $contacts,
76 'relationship_type_id' => $roleTypeId,
79 CRM_Contact_BAO_Relationship
::createMultiple($params, 'a');
81 $url = CRM_Utils_System
::url(
82 'civicrm/contact/view/case',
90 CRM_Utils_System
::redirect($url);