CRM-17606 - Case token fixes
[civicrm-core.git] / CRM / Contact / Form / Task / PDF.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
7e9e8871 4 | CiviCRM version 4.7 |
6a488035 5 +--------------------------------------------------------------------+
e7112fa7 6 | Copyright CiviCRM LLC (c) 2004-2015 |
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
e7112fa7 31 * @copyright CiviCRM LLC (c) 2004-2015
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 */
37class 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
61 $this->_caseId = CRM_Utils_Request::retrieve('caseid', 'Positive', $this, FALSE);
62
63 // retrieve contact ID if this is 'single' mode
64 $cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this, FALSE);
65
66 if ($cid) {
67 // this is true in non-search context / single mode
68 // in search context 'id' is the default profile id for search display
69 // CRM-11227
70 $this->_activityId = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE);
71 }
72
73 if ($cid) {
74 CRM_Contact_Form_Task_PDFLetterCommon::preProcessSingle($this, $cid);
75 $this->_single = TRUE;
76 $this->_cid = $cid;
77 }
78 else {
79 parent::preProcess();
80 }
81 $this->assign('single', $this->_single);
82 }
83
86538308 84 /**
00252851 85 * Set default values for the form.
86538308 86 */
00be9182 87 public function setDefaultValues() {
6a488035
TO
88 $defaults = array();
89 if (isset($this->_activityId)) {
90 $params = array('id' => $this->_activityId);
91 CRM_Activity_BAO_Activity::retrieve($params, $defaults);
92 $defaults['html_message'] = CRM_Utils_Array::value('details', $defaults);
93 }
94 $defaults = $defaults + CRM_Contact_Form_Task_PDFLetterCommon::setDefaultValues();
95 return $defaults;
96 }
97
98 /**
fe482240 99 * Build the form object.
6a488035
TO
100 */
101 public function buildQuickForm() {
102 //enable form element
103 $this->assign('suppressForm', FALSE);
104 CRM_Contact_Form_Task_PDFLetterCommon::buildQuickForm($this);
105 }
106
107 /**
fe482240 108 * Process the form after the input has been submitted and validated.
6a488035
TO
109 */
110 public function postProcess() {
111 CRM_Contact_Form_Task_PDFLetterCommon::postProcess($this);
112 }
96025800 113
5ec6b0ad
TM
114 /**
115 * List available tokens for this form.
116 *
117 * @return array
118 */
119 public function listTokens() {
120 $tokens = CRM_Core_SelectValues::contactTokens();
07945b3c
CW
121 if (isset($this->_caseId)) {
122 $tokens += CRM_Core_SelectValues::caseTokens();
123 }
5ec6b0ad
TM
124 return $tokens;
125 }
126
6a488035 127}