Commit | Line | Data |
---|---|---|
2d3e3c7b | 1 | <?php |
2 | ||
3 | /** | |
4 | * This class provides the common functionality for creating PDF letter for | |
5 | * members | |
6 | */ | |
7 | class CRM_Member_Form_Task_PDFLetterCommon extends CRM_Contact_Form_Task_PDFLetterCommon { | |
8 | ||
9 | /** | |
10 | * process the form after the input has been submitted and validated | |
11 | * @todo this is horrible copy & paste code because there is so much risk of breakage | |
12 | * in fixing the existing pdfLetter classes to be suitably generic | |
13 | * @access public | |
14 | * | |
355ba699 | 15 | * @return void |
2d3e3c7b | 16 | */ |
1c6af218 | 17 | static function postProcessMembers(&$form, $membershipIDs, $skipOnHold, $skipDeceased, $contactIDs) { |
2d3e3c7b | 18 | |
53e258d3 DL |
19 | list($formValues, $categories, $html_message, $messageToken, $returnProperties) = |
20 | self::processMessageTemplate($form); | |
21 | ||
22 | $html = | |
23 | self::generateHTML( | |
24 | $membershipIDs, | |
25 | $returnProperties, | |
26 | $skipOnHold, | |
27 | $skipDeceased, | |
28 | $messageToken, | |
29 | $html_message, | |
30 | $categories | |
31 | ); | |
2d3e3c7b | 32 | self::createActivities($form, $html_message, $contactIDs); |
33 | ||
34 | CRM_Utils_PDF_Utils::html2pdf($html, "CiviLetter.pdf", FALSE, $formValues); | |
35 | ||
36 | $form->postProcessHook(); | |
37 | ||
38 | CRM_Utils_System::civiExit(1); | |
39 | } | |
40 | //end of function | |
41 | ||
42 | /** | |
43 | * generate htmlfor pdf letters | |
44 | * @param unknown_type $membershipIDs | |
45 | * @param unknown_type $returnProperties | |
46 | * @param unknown_type $skipOnHold | |
47 | * @param unknown_type $skipDeceased | |
48 | * @param unknown_type $messageToken | |
49 | * @return unknown | |
50 | */ | |
0cc4a61d | 51 | static function generateHTML($membershipIDs, $returnProperties, $skipOnHold, $skipDeceased, $messageToken, $html_message, $categories) { |
2d3e3c7b | 52 | $memberships = CRM_Utils_Token::getMembershipTokenDetails($membershipIDs); |
53 | ||
995fc677 E |
54 | foreach ($membershipIDs as $membershipID) { |
55 | $membership = $memberships[$membershipID]; | |
2d3e3c7b | 56 | // get contact information |
57 | $contactId = $membership['contact_id']; | |
58 | $params = array('contact_id' => $contactId); | |
59 | //getTokenDetails is much like calling the api contact.get function - but - with some minor | |
60 | // special handlings. It preceeds the existance of the api | |
61 | list($contacts) = CRM_Utils_Token::getTokenDetails( | |
62 | $params, | |
63 | $returnProperties, | |
64 | $skipOnHold, | |
65 | $skipDeceased, | |
66 | NULL, | |
67 | $messageToken, | |
68 | 'CRM_Contribution_Form_Task_PDFLetterCommon' | |
69 | ); | |
70 | ||
71 | $tokenHtml = CRM_Utils_Token::replaceContactTokens($html_message, $contacts[$contactId], TRUE, $messageToken); | |
72 | $tokenHtml = CRM_Utils_Token::replaceEntityTokens('membership', $membership, $tokenHtml, $messageToken); | |
0cc4a61d | 73 | $tokenHtml = CRM_Utils_Token::replaceHookTokens($tokenHtml, $contacts[$contactId], $categories, TRUE); |
74 | $tokenHtml = CRM_Utils_Token::parseThroughSmarty($tokenHtml, $contacts[$contactId]); | |
2d3e3c7b | 75 | |
76 | $html[] = $tokenHtml; | |
77 | ||
78 | } | |
79 | return $html; | |
80 | } | |
81 | } | |
82 |