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
{
23 use CRM_Contact_Form_Task_PDFTrait
;
26 * All the existing templates in the system.
30 public $_templates = NULL;
32 public $_single = NULL;
36 public $_activityId = NULL;
39 * Build all the data structures needed to build the form.
41 public function preProcess() {
43 $this->skipOnHold
= $this->skipDeceased
= FALSE;
44 $this->preProcessPDF();
46 // store case id if present
47 $this->_caseId
= CRM_Utils_Request
::retrieve('caseid', 'CommaSeparatedIntegers', $this, FALSE);
48 if (!empty($this->_caseId
) && strpos($this->_caseId
, ',')) {
49 $this->_caseIds
= explode(',', $this->_caseId
);
50 unset($this->_caseId
);
53 // retrieve contact ID if this is 'single' mode
54 $cid = CRM_Utils_Request
::retrieve('cid', 'CommaSeparatedIntegers', $this, FALSE);
57 // this is true in non-search context / single mode
58 // in search context 'id' is the default profile id for search display
60 $this->_activityId
= CRM_Utils_Request
::retrieve('id', 'Positive', $this, FALSE);
61 $this->_contactIds
= explode(',', $cid);
62 // put contact display name in title for single contact mode
63 if (count($this->_contactIds
) === 1) {
64 CRM_Utils_System
::setTitle(ts('Print/Merge Document for %1', [1 => CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $cid, 'display_name')]));
66 $this->_single
= TRUE;
71 $this->assign('single', $this->_single
);
75 * Set default values for the form.
77 public function setDefaultValues() {
78 $defaults = $this->getPDFDefaultValues();
79 if (isset($this->_activityId
)) {
80 $params = ['id' => $this->_activityId
];
81 CRM_Activity_BAO_Activity
::retrieve($params, $defaults);
82 $defaults['html_message'] = $defaults['details'] ??
NULL;
88 * Build the form object.
90 * @throws \CRM_Core_Exception
92 public function buildQuickForm() {
94 $this->assign('suppressForm', FALSE);
95 $this->addPDFElementsToForm();
99 * Process the form after the input has been submitted and validated.
101 public function postProcess() {
102 CRM_Contact_Form_Task_PDFLetterCommon
::postProcess($this);
106 * List available tokens for this form.
110 public function listTokens() {
111 $tokens = CRM_Core_SelectValues
::contactTokens();
112 if (isset($this->_caseId
) ||
isset($this->_caseIds
)) {
113 // For a single case, list tokens relevant for only that case type
114 $caseTypeId = isset($this->_caseId
) ? CRM_Core_DAO
::getFieldValue('CRM_Case_DAO_Case', $this->_caseId
, 'case_type_id') : NULL;
115 $tokens +
= CRM_Core_SelectValues
::caseTokens($caseTypeId);