3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * This class provides the functionality to email a group of contacts.
21 class CRM_Contact_Form_Task_Email
extends CRM_Contact_Form_Task
{
23 use CRM_Contact_Form_Task_EmailTrait
;
26 * Build all the data structures needed to build the form.
28 * @throws \CiviCRM_API3_Exception
29 * @throws \CRM_Core_Exception
31 public function preProcess() {
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.
34 // store case id if present
35 $this->_caseId
= CRM_Utils_Request
::retrieve('caseid', 'String', $this, FALSE);
36 $this->_context
= CRM_Utils_Request
::retrieve('context', 'Alphanumeric', $this);
38 $cid = CRM_Utils_Request
::retrieve('cid', 'String', $this, FALSE);
40 // Allow request to specify email id rather than contact id
41 $toEmailId = CRM_Utils_Request
::retrieve('email_id', 'String', $this);
43 $toEmail = civicrm_api('email', 'getsingle', ['version' => 3, 'id' => $toEmailId]);
44 if (!empty($toEmail['email']) && !empty($toEmail['contact_id'])) {
45 $this->_toEmail
= $toEmail;
48 $cid = $toEmail['contact_id'];
49 $this->set('cid', $cid);
54 $cid = explode(',', $cid);
57 foreach ($cid as $val) {
58 $displayName[] = CRM_Contact_BAO_Contact
::displayName($val);
61 CRM_Utils_System
::setTitle(implode(',', $displayName) . ' - ' . ts('Email'));
64 CRM_Utils_System
::setTitle(ts('New Email'));
66 if ($this->_context
=== 'search') {
67 $this->_single
= TRUE;
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);
75 $this->traitPreProcess();
79 * Stub function as EmailTrait calls this.
81 * @todo move some code from preProcess into here.
83 public function setContactIDs() {}
86 * List available tokens for this form.
89 * @throws \CRM_Core_Exception
91 public function listTokens() {
92 $tokens = CRM_Core_SelectValues
::contactTokens();
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);