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 | /** | |
00252851 | 19 | * This class provides the functionality to email a group of contacts. |
6a488035 TO |
20 | */ |
21 | class CRM_Contact_Form_Task_Email extends CRM_Contact_Form_Task { | |
22 | ||
8a432af6 | 23 | use CRM_Contact_Form_Task_EmailTrait; |
6a488035 TO |
24 | |
25 | /** | |
fe482240 | 26 | * Build all the data structures needed to build the form. |
a1b37126 | 27 | * |
28 | * @throws \CiviCRM_API3_Exception | |
29 | * @throws \CRM_Core_Exception | |
bbe69194 | 30 | */ |
00be9182 | 31 | public function preProcess() { |
e94f3011 | 32 | // @todo - more of the handling in this function should be move to the trait. Notably the title part is |
33 | // not set on other forms that share the trait. | |
6a488035 | 34 | // store case id if present |
9cb404b4 | 35 | $this->_caseId = CRM_Utils_Request::retrieve('caseid', 'String', $this, FALSE); |
edc80cda | 36 | $this->_context = CRM_Utils_Request::retrieve('context', 'Alphanumeric', $this); |
6a488035 | 37 | |
9cb404b4 | 38 | $cid = CRM_Utils_Request::retrieve('cid', 'String', $this, FALSE); |
8e4aa90c CW |
39 | |
40 | // Allow request to specify email id rather than contact id | |
41 | $toEmailId = CRM_Utils_Request::retrieve('email_id', 'String', $this); | |
42 | if ($toEmailId) { | |
be2fb01f | 43 | $toEmail = civicrm_api('email', 'getsingle', ['version' => 3, 'id' => $toEmailId]); |
8e4aa90c CW |
44 | if (!empty($toEmail['email']) && !empty($toEmail['contact_id'])) { |
45 | $this->_toEmail = $toEmail; | |
46 | } | |
47 | if (!$cid) { | |
48 | $cid = $toEmail['contact_id']; | |
49 | $this->set('cid', $cid); | |
50 | } | |
51 | } | |
52 | ||
53 | if ($cid) { | |
353ffa53 | 54 | $cid = explode(',', $cid); |
be2fb01f | 55 | $displayName = []; |
9cb404b4 | 56 | |
b3dbca23 | 57 | foreach ($cid as $val) { |
515f739d M |
58 | $displayName[] = CRM_Contact_BAO_Contact::displayName($val); |
59 | } | |
6a488035 | 60 | |
b3dbca23 | 61 | CRM_Utils_System::setTitle(implode(',', $displayName) . ' - ' . ts('Email')); |
515f739d | 62 | } |
b3dbca23 | 63 | else { |
d75f2f47 | 64 | CRM_Utils_System::setTitle(ts('New Email')); |
515f739d | 65 | } |
a1b37126 | 66 | if ($this->_context === 'search') { |
67 | $this->_single = TRUE; | |
68 | } | |
e94f3011 | 69 | if ($cid || $this->_context === 'standalone') { |
70 | // When search context is false the parent pre-process is not set. That avoids it changing the | |
71 | // redirect url & attempting to set the search params of the form. It may have only | |
72 | // historical significance. | |
73 | $this->setIsSearchContext(FALSE); | |
6a488035 | 74 | } |
e94f3011 | 75 | $this->traitPreProcess(); |
6a488035 TO |
76 | } |
77 | ||
e94f3011 | 78 | /** |
79 | * Stub function as EmailTrait calls this. | |
80 | * | |
81 | * @todo move some code from preProcess into here. | |
82 | */ | |
83 | public function setContactIDs() {} | |
84 | ||
5ec6b0ad TM |
85 | /** |
86 | * List available tokens for this form. | |
87 | * | |
88 | * @return array | |
b61322fd | 89 | * @throws \CRM_Core_Exception |
5ec6b0ad TM |
90 | */ |
91 | public function listTokens() { | |
92 | $tokens = CRM_Core_SelectValues::contactTokens(); | |
d7e297be DB |
93 | |
94 | if (isset($this->_caseId) || isset($this->_caseIds)) { | |
95 | // For a single case, list tokens relevant for only that case type | |
96 | $caseTypeId = isset($this->_caseId) ? CRM_Core_DAO::getFieldValue('CRM_Case_DAO_Case', $this->_caseId, 'case_type_id') : NULL; | |
97 | $tokens += CRM_Core_SelectValues::caseTokens($caseTypeId); | |
98 | } | |
99 | ||
5ec6b0ad TM |
100 | return $tokens; |
101 | } | |
102 | ||
6a488035 | 103 | } |