[REF] dev/core#2790 deprecate preProcessSingle
[civicrm-core.git] / CRM / Contact / Form / Task / PDF.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17
18 /**
19 * This class provides the functionality to create PDF letter for a group of contacts or a single contact.
20 */
21 class CRM_Contact_Form_Task_PDF extends CRM_Contact_Form_Task {
22
23 use CRM_Contact_Form_Task_PDFTrait;
24
25 /**
26 * All the existing templates in the system.
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 /**
39 * Build all the data structures needed to build the form.
40 */
41 public function preProcess() {
42
43 $this->skipOnHold = $this->skipDeceased = FALSE;
44 $this->preProcessPDF();
45
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);
51 }
52
53 // retrieve contact ID if this is 'single' mode
54 $cid = CRM_Utils_Request::retrieve('cid', 'CommaSeparatedIntegers', $this, FALSE);
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 $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 }
66 $this->_single = TRUE;
67 }
68 else {
69 parent::preProcess();
70 }
71 $this->assign('single', $this->_single);
72 }
73
74 /**
75 * Set default values for the form.
76 */
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;
83 }
84 return $defaults;
85 }
86
87 /**
88 * Build the form object.
89 *
90 * @throws \CRM_Core_Exception
91 */
92 public function buildQuickForm() {
93 //enable form element
94 $this->assign('suppressForm', FALSE);
95 $this->addPDFElementsToForm();
96 }
97
98 /**
99 * Process the form after the input has been submitted and validated.
100 */
101 public function postProcess() {
102 CRM_Contact_Form_Task_PDFLetterCommon::postProcess($this);
103 }
104
105 /**
106 * List available tokens for this form.
107 *
108 * @return array
109 */
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);
116 }
117 return $tokens;
118 }
119
120 }