[REF] dev/core#2790 deprecate preProcessSingle
[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);
972171bb
EM
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')]));
65 }
6a488035 66 $this->_single = TRUE;
6a488035
TO
67 }
68 else {
69 parent::preProcess();
70 }
71 $this->assign('single', $this->_single);
72 }
73
86538308 74 /**
00252851 75 * Set default values for the form.
86538308 76 */
00be9182 77 public function setDefaultValues() {
fc34a273 78 $defaults = $this->getPDFDefaultValues();
6a488035 79 if (isset($this->_activityId)) {
be2fb01f 80 $params = ['id' => $this->_activityId];
6a488035 81 CRM_Activity_BAO_Activity::retrieve($params, $defaults);
9c1bc317 82 $defaults['html_message'] = $defaults['details'] ?? NULL;
6a488035 83 }
6a488035
TO
84 return $defaults;
85 }
86
87 /**
fe482240 88 * Build the form object.
972171bb
EM
89 *
90 * @throws \CRM_Core_Exception
6a488035
TO
91 */
92 public function buildQuickForm() {
93 //enable form element
94 $this->assign('suppressForm', FALSE);
053c1a4b 95 $this->addPDFElementsToForm();
6a488035
TO
96 }
97
98 /**
fe482240 99 * Process the form after the input has been submitted and validated.
6a488035
TO
100 */
101 public function postProcess() {
102 CRM_Contact_Form_Task_PDFLetterCommon::postProcess($this);
103 }
96025800 104
5ec6b0ad
TM
105 /**
106 * List available tokens for this form.
107 *
108 * @return array
109 */
110 public function listTokens() {
111 $tokens = CRM_Core_SelectValues::contactTokens();
fe61faf3
CW
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;
0fe4153d 115 $tokens += CRM_Core_SelectValues::caseTokens($caseTypeId);
07945b3c 116 }
5ec6b0ad
TM
117 return $tokens;
118 }
119
6a488035 120}