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 create PDF letter for a group of contacts or a single contact.
21 class CRM_Contact_Form_Task_PDF
extends CRM_Contact_Form_Task
{
24 * All the existing templates in the system.
28 public $_templates = NULL;
30 public $_single = NULL;
34 public $_activityId = NULL;
37 * Build all the data structures needed to build the form.
39 public function preProcess() {
41 $this->skipOnHold
= $this->skipDeceased
= FALSE;
42 CRM_Contact_Form_Task_PDFLetterCommon
::preProcess($this);
44 // store case id if present
45 $this->_caseId
= CRM_Utils_Request
::retrieve('caseid', 'CommaSeparatedIntegers', $this, FALSE);
46 if (!empty($this->_caseId
) && strpos($this->_caseId
, ',')) {
47 $this->_caseIds
= explode(',', $this->_caseId
);
48 unset($this->_caseId
);
51 // retrieve contact ID if this is 'single' mode
52 $cid = CRM_Utils_Request
::retrieve('cid', 'CommaSeparatedIntegers', $this, FALSE);
55 // this is true in non-search context / single mode
56 // in search context 'id' is the default profile id for search display
58 $this->_activityId
= CRM_Utils_Request
::retrieve('id', 'Positive', $this, FALSE);
62 CRM_Contact_Form_Task_PDFLetterCommon
::preProcessSingle($this, $cid);
63 $this->_single
= TRUE;
68 $this->assign('single', $this->_single
);
72 * Set default values for the form.
74 public function setDefaultValues() {
76 if (isset($this->_activityId
)) {
77 $params = ['id' => $this->_activityId
];
78 CRM_Activity_BAO_Activity
::retrieve($params, $defaults);
79 $defaults['html_message'] = $defaults['details'] ??
NULL;
81 $defaults = $defaults + CRM_Contact_Form_Task_PDFLetterCommon
::setDefaultValues();
86 * Build the form object.
88 public function buildQuickForm() {
90 $this->assign('suppressForm', FALSE);
91 CRM_Contact_Form_Task_PDFLetterCommon
::buildQuickForm($this);
95 * Process the form after the input has been submitted and validated.
97 public function postProcess() {
98 CRM_Contact_Form_Task_PDFLetterCommon
::postProcess($this);
102 * List available tokens for this form.
106 public function listTokens() {
107 $tokens = CRM_Core_SelectValues
::contactTokens();
108 if (isset($this->_caseId
) ||
isset($this->_caseIds
)) {
109 // For a single case, list tokens relevant for only that case type
110 $caseTypeId = isset($this->_caseId
) ? CRM_Core_DAO
::getFieldValue('CRM_Case_DAO_Case', $this->_caseId
, 'case_type_id') : NULL;
111 $tokens +
= CRM_Core_SelectValues
::caseTokens($caseTypeId);