Merge pull request #13867 from jitendrapurohit/paypalpro
[civicrm-core.git] / CRM / Case / Form / AddToCaseAsRole.php
CommitLineData
f1d7f287
CR
1<?php
2
245992ca
CR
3/**
4 * Class CRM_Case_Form_AddToCaseAsRole
5 */
f1d7f287 6class CRM_Case_Form_AddToCaseAsRole extends CRM_Contact_Form_Task {
245992ca
CR
7
8 /**
9 * @inheritdoc
10 */
f1d7f287 11 public function buildQuickForm() {
245992ca 12
245992ca 13 $roleTypes = $this->getRoleTypes();
245992ca
CR
14 $this->add(
15 'select',
16 'role_type',
17 ts('Relationship Type'),
18 array('' => ts('- select type -')) + $roleTypes,
66504fe4 19 TRUE,
245992ca
CR
20 array('class' => 'crm-select2 twenty')
21 );
22
66504fe4
CR
23 $this->addEntityRef(
24 'assign_to',
25 ts('Assign to'),
af00ced5 26 array('entity' => 'Case'),
66504fe4
CR
27 TRUE
28 );
29
245992ca
CR
30 $this->addButtons(array(
31 array(
32 'type' => 'submit',
33 'name' => ts('Submit'),
34 'isDefault' => TRUE,
35 ),
66504fe4
CR
36 array(
37 'type' => 'cancel',
38 'name' => ts('Cancel'),
39 ),
245992ca
CR
40 ));
41 }
42
43 /**
44 * Returns list of configured role types for individuals.
45 *
46 * @return array
47 * List of role types
48 */
49 private function getRoleTypes() {
50 $relType = CRM_Contact_BAO_Relationship::getRelationType('Individual');
51 $roleTypes = array();
52
53 foreach ($relType as $k => $v) {
54 $roleTypes[substr($k, 0, strpos($k, '_'))] = $v;
55 }
56
57 return $roleTypes;
f1d7f287
CR
58 }
59
245992ca
CR
60 /**
61 * @inheritdoc
62 */
f1d7f287
CR
63 public function postProcess() {
64 $values = $this->controller->exportValues();
65
cf0adfdc
CR
66 $caseId = (int) $values['assign_to'];
67 $roleTypeId = (int) $values['role_type'];
f1d7f287
CR
68 $contacts = $this->_contactIds;
69
70 $clients = CRM_Case_BAO_Case::getCaseClients($caseId);
71
72 $params = array(
73 'contact_id_a' => $clients[0],
74 'contact_id_b' => $contacts,
75 'case_id' => $caseId,
cf0adfdc 76 'relationship_type_id' => $roleTypeId,
f1d7f287
CR
77 );
78
79 CRM_Contact_BAO_Relationship::createMultiple($params, 'a');
80
81 $url = CRM_Utils_System::url(
82 'civicrm/contact/view/case',
44ca57d8
CR
83 array(
84 'cid' => $clients[0],
85 'id' => $caseId,
86 'reset' => 1,
87 'action' => 'view',
88 )
f1d7f287
CR
89 );
90 CRM_Utils_System::redirect($url);
91 }
cf0adfdc 92
f1d7f287 93}