3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2020 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2020
35 * This class provides the functionality to create PDF letter for a group of contacts or a single contact.
37 class CRM_Contact_Form_Task_PDF
extends CRM_Contact_Form_Task
{
40 * All the existing templates in the system.
44 public $_templates = NULL;
46 public $_single = NULL;
50 public $_activityId = NULL;
53 * Build all the data structures needed to build the form.
55 public function preProcess() {
57 $this->skipOnHold
= $this->skipDeceased
= FALSE;
58 CRM_Contact_Form_Task_PDFLetterCommon
::preProcess($this);
60 // store case id if present
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
);
67 // retrieve contact ID if this is 'single' mode
68 $cid = CRM_Utils_Request
::retrieve('cid', 'CommaSeparatedIntegers', $this, FALSE);
71 // this is true in non-search context / single mode
72 // in search context 'id' is the default profile id for search display
74 $this->_activityId
= CRM_Utils_Request
::retrieve('id', 'Positive', $this, FALSE);
78 CRM_Contact_Form_Task_PDFLetterCommon
::preProcessSingle($this, $cid);
79 $this->_single
= TRUE;
84 $this->assign('single', $this->_single
);
88 * Set default values for the form.
90 public function setDefaultValues() {
92 if (isset($this->_activityId
)) {
93 $params = ['id' => $this->_activityId
];
94 CRM_Activity_BAO_Activity
::retrieve($params, $defaults);
95 $defaults['html_message'] = CRM_Utils_Array
::value('details', $defaults);
97 $defaults = $defaults + CRM_Contact_Form_Task_PDFLetterCommon
::setDefaultValues();
102 * Build the form object.
104 public function buildQuickForm() {
105 //enable form element
106 $this->assign('suppressForm', FALSE);
107 CRM_Contact_Form_Task_PDFLetterCommon
::buildQuickForm($this);
111 * Process the form after the input has been submitted and validated.
113 public function postProcess() {
114 CRM_Contact_Form_Task_PDFLetterCommon
::postProcess($this);
118 * List available tokens for this form.
122 public function listTokens() {
123 $tokens = CRM_Core_SelectValues
::contactTokens();
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;
127 $tokens +
= CRM_Core_SelectValues
::caseTokens($caseTypeId);