Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
6b83d5bd | 6 | | Copyright CiviCRM LLC (c) 2004-2019 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
6b83d5bd | 31 | * @copyright CiviCRM LLC (c) 2004-2019 |
6a488035 TO |
32 | */ |
33 | ||
34 | /** | |
00252851 | 35 | * This class provides the functionality to create PDF letter for a group of contacts or a single contact. |
6a488035 TO |
36 | */ |
37 | class CRM_Contact_Form_Task_PDF extends CRM_Contact_Form_Task { | |
38 | ||
39 | /** | |
fe482240 | 40 | * All the existing templates in the system. |
6a488035 TO |
41 | * |
42 | * @var array | |
43 | */ | |
44 | public $_templates = NULL; | |
45 | ||
46 | public $_single = NULL; | |
47 | ||
48 | public $_cid = NULL; | |
49 | ||
50 | public $_activityId = NULL; | |
51 | ||
52 | /** | |
fe482240 | 53 | * Build all the data structures needed to build the form. |
6a488035 | 54 | */ |
00be9182 | 55 | public function preProcess() { |
6a488035 TO |
56 | |
57 | $this->skipOnHold = $this->skipDeceased = FALSE; | |
58 | CRM_Contact_Form_Task_PDFLetterCommon::preProcess($this); | |
59 | ||
60 | // store case id if present | |
fe61faf3 CW |
61 | $this->_caseId = CRM_Utils_Request::retrieve('caseid', 'CommaSeparatedIntegers', $this, FALSE); |
62 | if (!empty($this->_caseId) && strpos($this->_caseId, ',')) { | |
63 | $this->_caseIds = explode(',', $this->_caseId); | |
64 | unset($this->_caseId); | |
65 | } | |
6a488035 TO |
66 | |
67 | // retrieve contact ID if this is 'single' mode | |
fe61faf3 | 68 | $cid = CRM_Utils_Request::retrieve('cid', 'CommaSeparatedIntegers', $this, FALSE); |
6a488035 TO |
69 | |
70 | if ($cid) { | |
71 | // this is true in non-search context / single mode | |
72 | // in search context 'id' is the default profile id for search display | |
73 | // CRM-11227 | |
74 | $this->_activityId = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE); | |
75 | } | |
76 | ||
77 | if ($cid) { | |
78 | CRM_Contact_Form_Task_PDFLetterCommon::preProcessSingle($this, $cid); | |
79 | $this->_single = TRUE; | |
6a488035 TO |
80 | } |
81 | else { | |
82 | parent::preProcess(); | |
83 | } | |
84 | $this->assign('single', $this->_single); | |
85 | } | |
86 | ||
86538308 | 87 | /** |
00252851 | 88 | * Set default values for the form. |
86538308 | 89 | */ |
00be9182 | 90 | public function setDefaultValues() { |
be2fb01f | 91 | $defaults = []; |
6a488035 | 92 | if (isset($this->_activityId)) { |
be2fb01f | 93 | $params = ['id' => $this->_activityId]; |
6a488035 TO |
94 | CRM_Activity_BAO_Activity::retrieve($params, $defaults); |
95 | $defaults['html_message'] = CRM_Utils_Array::value('details', $defaults); | |
96 | } | |
97 | $defaults = $defaults + CRM_Contact_Form_Task_PDFLetterCommon::setDefaultValues(); | |
98 | return $defaults; | |
99 | } | |
100 | ||
101 | /** | |
fe482240 | 102 | * Build the form object. |
6a488035 TO |
103 | */ |
104 | public function buildQuickForm() { | |
105 | //enable form element | |
106 | $this->assign('suppressForm', FALSE); | |
107 | CRM_Contact_Form_Task_PDFLetterCommon::buildQuickForm($this); | |
108 | } | |
109 | ||
110 | /** | |
fe482240 | 111 | * Process the form after the input has been submitted and validated. |
6a488035 TO |
112 | */ |
113 | public function postProcess() { | |
114 | CRM_Contact_Form_Task_PDFLetterCommon::postProcess($this); | |
115 | } | |
96025800 | 116 | |
5ec6b0ad TM |
117 | /** |
118 | * List available tokens for this form. | |
119 | * | |
120 | * @return array | |
121 | */ | |
122 | public function listTokens() { | |
123 | $tokens = CRM_Core_SelectValues::contactTokens(); | |
fe61faf3 CW |
124 | if (isset($this->_caseId) || isset($this->_caseIds)) { |
125 | // For a single case, list tokens relevant for only that case type | |
126 | $caseTypeId = isset($this->_caseId) ? CRM_Core_DAO::getFieldValue('CRM_Case_DAO_Case', $this->_caseId, 'case_type_id') : NULL; | |
0fe4153d | 127 | $tokens += CRM_Core_SelectValues::caseTokens($caseTypeId); |
07945b3c | 128 | } |
5ec6b0ad TM |
129 | return $tokens; |
130 | } | |
131 | ||
6a488035 | 132 | } |