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 // store case id if present
33 $this->_caseId
= CRM_Utils_Request
::retrieve('caseid', 'String', $this, FALSE);
34 $this->_context
= CRM_Utils_Request
::retrieve('context', 'Alphanumeric', $this);
36 $cid = CRM_Utils_Request
::retrieve('cid', 'String', $this, FALSE);
38 // Allow request to specify email id rather than contact id
39 $toEmailId = CRM_Utils_Request
::retrieve('email_id', 'String', $this);
41 $toEmail = civicrm_api('email', 'getsingle', ['version' => 3, 'id' => $toEmailId]);
42 if (!empty($toEmail['email']) && !empty($toEmail['contact_id'])) {
43 $this->_toEmail
= $toEmail;
46 $cid = $toEmail['contact_id'];
47 $this->set('cid', $cid);
52 $cid = explode(',', $cid);
55 foreach ($cid as $val) {
56 $displayName[] = CRM_Contact_BAO_Contact
::displayName($val);
59 CRM_Utils_System
::setTitle(implode(',', $displayName) . ' - ' . ts('Email'));
62 CRM_Utils_System
::setTitle(ts('New Email'));
64 if ($this->_context
=== 'search') {
65 $this->_single
= TRUE;
67 CRM_Contact_Form_Task_EmailCommon
::preProcessFromAddress($this);
69 if (!$cid && $this->_context
!== 'standalone') {
73 $this->assign('single', $this->_single
);
74 if (CRM_Core_Permission
::check('administer CiviCRM')) {
75 $this->assign('isAdmin', 1);
80 * List available tokens for this form.
84 public function listTokens() {
85 $tokens = CRM_Core_SelectValues
::contactTokens();
87 if (isset($this->_caseId
) ||
isset($this->_caseIds
)) {
88 // For a single case, list tokens relevant for only that case type
89 $caseTypeId = isset($this->_caseId
) ? CRM_Core_DAO
::getFieldValue('CRM_Case_DAO_Case', $this->_caseId
, 'case_type_id') : NULL;
90 $tokens +
= CRM_Core_SelectValues
::caseTokens($caseTypeId);