[REF] dev/core#2790 move preProcess static to the trait
[civicrm-core.git] / CRM / Contact / Form / Task / PDF.php
CommitLineData
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 create PDF letter for a group of contacts or a single contact.
6a488035
TO
20 */
21class CRM_Contact_Form_Task_PDF extends CRM_Contact_Form_Task {
22
fc34a273
EM
23 use CRM_Contact_Form_Task_PDFTrait;
24
6a488035 25 /**
fe482240 26 * All the existing templates in the system.
6a488035
TO
27 *
28 * @var array
29 */
30 public $_templates = NULL;
31
32 public $_single = NULL;
33
34 public $_cid = NULL;
35
36 public $_activityId = NULL;
37
38 /**
fe482240 39 * Build all the data structures needed to build the form.
6a488035 40 */
00be9182 41 public function preProcess() {
6a488035
TO
42
43 $this->skipOnHold = $this->skipDeceased = FALSE;
c97bfeff 44 $this->preProcessPDF();
6a488035
TO
45
46 // store case id if present
fe61faf3
CW
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);
51 }
6a488035
TO
52
53 // retrieve contact ID if this is 'single' mode
fe61faf3 54 $cid = CRM_Utils_Request::retrieve('cid', 'CommaSeparatedIntegers', $this, FALSE);
6a488035
TO
55
56 if ($cid) {
57 // this is true in non-search context / single mode
58 // in search context 'id' is the default profile id for search display
59 // CRM-11227
60 $this->_activityId = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE);
61 }
62
63 if ($cid) {
64 CRM_Contact_Form_Task_PDFLetterCommon::preProcessSingle($this, $cid);
65 $this->_single = TRUE;
6a488035
TO
66 }
67 else {
68 parent::preProcess();
69 }
70 $this->assign('single', $this->_single);
71 }
72
86538308 73 /**
00252851 74 * Set default values for the form.
86538308 75 */
00be9182 76 public function setDefaultValues() {
fc34a273 77 $defaults = $this->getPDFDefaultValues();
6a488035 78 if (isset($this->_activityId)) {
be2fb01f 79 $params = ['id' => $this->_activityId];
6a488035 80 CRM_Activity_BAO_Activity::retrieve($params, $defaults);
9c1bc317 81 $defaults['html_message'] = $defaults['details'] ?? NULL;
6a488035 82 }
6a488035
TO
83 return $defaults;
84 }
85
86 /**
fe482240 87 * Build the form object.
6a488035
TO
88 */
89 public function buildQuickForm() {
90 //enable form element
91 $this->assign('suppressForm', FALSE);
053c1a4b 92 $this->addPDFElementsToForm();
6a488035
TO
93 }
94
95 /**
fe482240 96 * Process the form after the input has been submitted and validated.
6a488035
TO
97 */
98 public function postProcess() {
99 CRM_Contact_Form_Task_PDFLetterCommon::postProcess($this);
100 }
96025800 101
5ec6b0ad
TM
102 /**
103 * List available tokens for this form.
104 *
105 * @return array
106 */
107 public function listTokens() {
108 $tokens = CRM_Core_SelectValues::contactTokens();
fe61faf3
CW
109 if (isset($this->_caseId) || isset($this->_caseIds)) {
110 // For a single case, list tokens relevant for only that case type
111 $caseTypeId = isset($this->_caseId) ? CRM_Core_DAO::getFieldValue('CRM_Case_DAO_Case', $this->_caseId, 'case_type_id') : NULL;
0fe4153d 112 $tokens += CRM_Core_SelectValues::caseTokens($caseTypeId);
07945b3c 113 }
5ec6b0ad
TM
114 return $tokens;
115 }
116
6a488035 117}