Merge pull request #18143 from mattwire/membertabbuttons
[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
23 /**
fe482240 24 * All the existing templates in the system.
6a488035
TO
25 *
26 * @var array
27 */
28 public $_templates = NULL;
29
30 public $_single = NULL;
31
32 public $_cid = NULL;
33
34 public $_activityId = NULL;
35
36 /**
fe482240 37 * Build all the data structures needed to build the form.
6a488035 38 */
00be9182 39 public function preProcess() {
6a488035
TO
40
41 $this->skipOnHold = $this->skipDeceased = FALSE;
42 CRM_Contact_Form_Task_PDFLetterCommon::preProcess($this);
43
44 // store case id if present
fe61faf3
CW
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);
49 }
6a488035
TO
50
51 // retrieve contact ID if this is 'single' mode
fe61faf3 52 $cid = CRM_Utils_Request::retrieve('cid', 'CommaSeparatedIntegers', $this, FALSE);
6a488035
TO
53
54 if ($cid) {
55 // this is true in non-search context / single mode
56 // in search context 'id' is the default profile id for search display
57 // CRM-11227
58 $this->_activityId = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE);
59 }
60
61 if ($cid) {
62 CRM_Contact_Form_Task_PDFLetterCommon::preProcessSingle($this, $cid);
63 $this->_single = TRUE;
6a488035
TO
64 }
65 else {
66 parent::preProcess();
67 }
68 $this->assign('single', $this->_single);
69 }
70
86538308 71 /**
00252851 72 * Set default values for the form.
86538308 73 */
00be9182 74 public function setDefaultValues() {
be2fb01f 75 $defaults = [];
6a488035 76 if (isset($this->_activityId)) {
be2fb01f 77 $params = ['id' => $this->_activityId];
6a488035 78 CRM_Activity_BAO_Activity::retrieve($params, $defaults);
9c1bc317 79 $defaults['html_message'] = $defaults['details'] ?? NULL;
6a488035
TO
80 }
81 $defaults = $defaults + CRM_Contact_Form_Task_PDFLetterCommon::setDefaultValues();
82 return $defaults;
83 }
84
85 /**
fe482240 86 * Build the form object.
6a488035
TO
87 */
88 public function buildQuickForm() {
89 //enable form element
90 $this->assign('suppressForm', FALSE);
91 CRM_Contact_Form_Task_PDFLetterCommon::buildQuickForm($this);
92 }
93
94 /**
fe482240 95 * Process the form after the input has been submitted and validated.
6a488035
TO
96 */
97 public function postProcess() {
98 CRM_Contact_Form_Task_PDFLetterCommon::postProcess($this);
99 }
96025800 100
5ec6b0ad
TM
101 /**
102 * List available tokens for this form.
103 *
104 * @return array
105 */
106 public function listTokens() {
107 $tokens = CRM_Core_SelectValues::contactTokens();
fe61faf3
CW
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;
0fe4153d 111 $tokens += CRM_Core_SelectValues::caseTokens($caseTypeId);
07945b3c 112 }
5ec6b0ad
TM
113 return $tokens;
114 }
115
6a488035 116}