Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
6 | | This work is published under the GNU AGPLv3 license with some | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | */ |
17 | ||
18 | /** | |
df371444 | 19 | * This class generates form components for building activity to a case. |
6a488035 TO |
20 | */ |
21 | class CRM_Case_Form_ActivityToCase extends CRM_Core_Form { | |
22 | ||
23 | /** | |
100fef9d | 24 | * Build all the data structures needed to build the form. |
6a488035 | 25 | */ |
00be9182 | 26 | public function preProcess() { |
a3d827a7 | 27 | $this->_activityId = CRM_Utils_Request::retrieve('activityId', 'Positive'); |
6a488035 TO |
28 | if (!$this->_activityId) { |
29 | CRM_Core_Error::fatal('required activity id is missing.'); | |
30 | } | |
31 | ||
a3d827a7 | 32 | $this->_currentCaseId = CRM_Utils_Request::retrieve('caseId', 'Positive'); |
6a488035 TO |
33 | $this->assign('currentCaseId', $this->_currentCaseId); |
34 | $this->assign('buildCaseActivityForm', TRUE); | |
6a1e5601 MWMC |
35 | |
36 | switch (CRM_Utils_Request::retrieve('fileOnCaseAction', 'String')) { | |
37 | case 'move': | |
38 | CRM_Utils_System::setTitle(ts('Move to Case')); | |
39 | break; | |
40 | ||
41 | case 'copy': | |
42 | CRM_Utils_System::setTitle(ts('Copy to Case')); | |
43 | break; | |
44 | ||
45 | } | |
6a488035 TO |
46 | } |
47 | ||
48 | /** | |
c490a46a | 49 | * Set default values for the form. For edit/view mode |
6a488035 TO |
50 | * the default values are retrieved from the database |
51 | * | |
6a488035 | 52 | * |
f72119d9 | 53 | * @return array |
6a488035 | 54 | */ |
00be9182 | 55 | public function setDefaultValues() { |
be2fb01f CW |
56 | $defaults = []; |
57 | $params = ['id' => $this->_activityId]; | |
6a488035 TO |
58 | |
59 | CRM_Activity_BAO_Activity::retrieve($params, $defaults); | |
050fc124 CW |
60 | $defaults['file_on_case_activity_subject'] = $defaults['subject']; |
61 | $defaults['file_on_case_target_contact_id'] = $defaults['target_contact']; | |
6a488035 | 62 | |
7359cdbc | 63 | // If this contact has an open case, supply it as a default |
bd343dcc | 64 | $cid = CRM_Utils_Request::retrieve('cid', 'Integer'); |
5ff596c0 | 65 | if (!$cid) { |
be2fb01f | 66 | $act = civicrm_api3('Activity', 'getsingle', ['id' => $this->_activityId, 'return' => 'target_contact_id']); |
5ff596c0 CW |
67 | if (!empty($act['target_contact_id'])) { |
68 | $cid = $act['target_contact_id'][0]; | |
69 | } | |
70 | } | |
bd343dcc | 71 | if ($cid) { |
be2fb01f | 72 | $cases = civicrm_api3('CaseContact', 'get', [ |
abd06efc | 73 | 'contact_id' => $cid, |
be2fb01f CW |
74 | 'case_id' => ['!=' => $this->_currentCaseId], |
75 | 'case_id.status_id' => ['!=' => "Closed"], | |
abd06efc | 76 | 'case_id.is_deleted' => 0, |
be2fb01f CW |
77 | 'case_id.end_date' => ['IS NULL' => 1], |
78 | 'options' => ['limit' => 1], | |
abd06efc | 79 | 'return' => 'case_id', |
be2fb01f | 80 | ]); |
abd06efc CW |
81 | foreach ($cases['values'] as $record) { |
82 | $defaults['file_on_case_unclosed_case_id'] = $record['case_id']; | |
bd343dcc CW |
83 | break; |
84 | } | |
85 | } | |
6a488035 TO |
86 | return $defaults; |
87 | } | |
88 | ||
89 | /** | |
fe482240 | 90 | * Build the form object. |
6a488035 TO |
91 | */ |
92 | public function buildQuickForm() { | |
be2fb01f | 93 | $this->addEntityRef('file_on_case_unclosed_case_id', ts('Select Case'), [ |
abd06efc | 94 | 'entity' => 'Case', |
be2fb01f CW |
95 | 'api' => [ |
96 | 'extra' => ['contact_id'], | |
97 | 'params' => [ | |
98 | 'case_id' => ['!=' => $this->_currentCaseId], | |
abd06efc | 99 | 'case_id.is_deleted' => 0, |
be2fb01f CW |
100 | 'case_id.status_id' => ['!=' => "Closed"], |
101 | 'case_id.end_date' => ['IS NULL' => 1], | |
102 | ], | |
103 | ], | |
104 | ], TRUE); | |
105 | $this->addEntityRef('file_on_case_target_contact_id', ts('With Contact(s)'), ['multiple' => TRUE]); | |
106 | $this->add('text', 'file_on_case_activity_subject', ts('Subject'), ['size' => 50]); | |
6a488035 | 107 | } |
96025800 | 108 | |
6a488035 | 109 | } |