Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | ||
3 | /** | |
4 | * This class provides the common functionality for creating PDF letter for | |
5 | * one or a group of contact ids. | |
6 | */ | |
7 | class CRM_Contribute_Form_Task_PDFLetterCommon extends CRM_Contact_Form_Task_PDFLetterCommon { | |
8 | ||
9 | /** | |
10 | * process the form after the input has been submitted and validated | |
11 | * | |
12 | * @access public | |
13 | * | |
14 | * @return None | |
15 | */ | |
16 | static function postProcess(&$form) { | |
17 | ||
18 | list($formValues, $categories, $html_message, $messageToken, $returnProperties) = self::processMessageTemplate($form); | |
19 | ||
20 | // update dates ? | |
21 | $receipt_update = isset($formValues['receipt_update']) ? $formValues['receipt_update'] : FALSE; | |
22 | $thankyou_update = isset($formValues['thankyou_update']) ? $formValues['thankyou_update'] : FALSE; | |
23 | $nowDate = date('YmdHis'); | |
24 | $receipts = 0; | |
25 | $thanks = 0; | |
26 | $updateStatus = ''; | |
27 | ||
28 | // skip some contacts ? | |
29 | $skipOnHold = isset($form->skipOnHold) ? $form->skipOnHold : FALSE; | |
30 | $skipDeceased = isset($form->skipDeceased) ? $form->skipDeceased : TRUE; | |
31 | ||
32 | foreach ($form->getVar('_contributionIds') as $item => $contributionId) { | |
33 | ||
34 | // get contact information | |
35 | $contactId = civicrm_api("Contribution", "getvalue", array('version' => '3', 'id' => $contributionId, 'return' => 'contact_id')); | |
36 | $params = array('contact_id' => $contactId); | |
37 | ||
38 | list($contact) = CRM_Utils_Token::getTokenDetails($params, | |
39 | $returnProperties, | |
40 | $skipOnHold, | |
41 | $skipDeceased, | |
42 | NULL, | |
43 | $messageToken, | |
44 | 'CRM_Contribution_Form_Task_PDFLetterCommon' | |
45 | ); | |
46 | if (civicrm_error($contact)) { | |
47 | $notSent[] = $contributionId; | |
48 | continue; | |
49 | } | |
50 | ||
51 | // get contribution information | |
52 | $params = array('contribution_id' => $contributionId); | |
53 | $contribution = CRM_Utils_Token::getContributionTokenDetails($params, | |
54 | $returnProperties, | |
55 | NULL, | |
56 | $messageToken, | |
57 | 'CRM_Contribution_Form_Task_PDFLetterCommon' | |
58 | ); | |
59 | if (civicrm_error($contribution)) { | |
60 | $notSent[] = $contributionId; | |
61 | continue; | |
62 | } | |
63 | ||
64 | $tokenHtml = CRM_Utils_Token::replaceContactTokens($html_message, $contact[$contactId], TRUE, $messageToken); | |
65 | $tokenHtml = CRM_Utils_Token::replaceContributionTokens($tokenHtml, $contribution[$contributionId], TRUE, $messageToken); | |
66 | $tokenHtml = CRM_Utils_Token::replaceHookTokens($tokenHtml, $contact[$contactId], $categories, TRUE); | |
67 | ||
68 | if (defined('CIVICRM_MAIL_SMARTY') && CIVICRM_MAIL_SMARTY) { | |
69 | $smarty = CRM_Core_Smarty::singleton(); | |
70 | // also add the tokens to the template | |
71 | $smarty->assign_by_ref('contact', $contact); | |
72 | $tokenHtml = $smarty->fetch("string:$tokenHtml"); | |
73 | } | |
74 | ||
75 | $html[] = $tokenHtml; | |
76 | ||
77 | // update dates (do it for each contribution including grouped recurring contribution) | |
78 | if ($receipt_update) { | |
79 | $result = CRM_Core_DAO::setFieldValue('CRM_Contribute_DAO_Contribution', $contributionId, 'receipt_date', $nowDate); | |
80 | // We can't use CRM_Core_Error::fatal here because the api error elevates the exception level. FIXME. dgg | |
81 | if ($result) { | |
82 | $receipts++; | |
83 | } | |
84 | } | |
85 | if ($thankyou_update) { | |
86 | $result = CRM_Core_DAO::setFieldValue('CRM_Contribute_DAO_Contribution', $contributionId, 'thankyou_date', $nowDate); | |
87 | // We can't use CRM_Core_Error::fatal here because the api error elevates the exception level. FIXME. dgg | |
88 | if ($result) { | |
89 | $thanks++; | |
90 | } | |
91 | } | |
92 | } | |
93 | ||
94 | self::createActivities($form, $html_message, $form->_contactIds); | |
95 | ||
96 | CRM_Utils_PDF_Utils::html2pdf($html, "CiviLetter.pdf", FALSE, $formValues); | |
97 | ||
98 | $form->postProcessHook(); | |
99 | ||
100 | if ($receipts) { | |
101 | $updateStatus = ts('Receipt date has been updated for %1 contributions.', array(1 => $receipts)); | |
102 | } | |
103 | if ($thanks) { | |
104 | $updateStatus .= ' ' . ts('Thank-you date has been updated for %1 contributions.', array(1 => $thanks)); | |
105 | } | |
106 | ||
107 | if ($updateStatus) { | |
108 | CRM_Core_Session::setStatus($updateStatus); | |
109 | } | |
110 | ||
111 | CRM_Utils_System::civiExit(1); | |
112 | } | |
113 | //end of function | |
114 | } | |
115 |