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 | * | |
77b97be7 EM |
15 | * @param $form |
16 | * @param $membershipIDs | |
17 | * @param $skipOnHold | |
18 | * @param $skipDeceased | |
19 | * @param $contactIDs | |
20 | * | |
355ba699 | 21 | * @return void |
2d3e3c7b | 22 | */ |
1c6af218 | 23 | static function postProcessMembers(&$form, $membershipIDs, $skipOnHold, $skipDeceased, $contactIDs) { |
2d3e3c7b | 24 | |
53e258d3 DL |
25 | list($formValues, $categories, $html_message, $messageToken, $returnProperties) = |
26 | self::processMessageTemplate($form); | |
27 | ||
28 | $html = | |
29 | self::generateHTML( | |
30 | $membershipIDs, | |
31 | $returnProperties, | |
32 | $skipOnHold, | |
33 | $skipDeceased, | |
34 | $messageToken, | |
35 | $html_message, | |
36 | $categories | |
37 | ); | |
2d3e3c7b | 38 | self::createActivities($form, $html_message, $contactIDs); |
39 | ||
40 | CRM_Utils_PDF_Utils::html2pdf($html, "CiviLetter.pdf", FALSE, $formValues); | |
41 | ||
42 | $form->postProcessHook(); | |
43 | ||
44 | CRM_Utils_System::civiExit(1); | |
45 | } | |
46 | //end of function | |
47 | ||
48 | /** | |
49 | * generate htmlfor pdf letters | |
fd31fa4c | 50 | * |
e3946c7f EM |
51 | * @param array $membershipIDs |
52 | * @param array $returnProperties | |
53 | * @param bool $skipOnHold | |
54 | * @param bool $skipDeceased | |
2d3e3c7b | 55 | * @param unknown_type $messageToken |
fd31fa4c EM |
56 | * @param $html_message |
57 | * @param $categories | |
58 | * | |
2d3e3c7b | 59 | * @return unknown |
60 | */ | |
0cc4a61d | 61 | static function generateHTML($membershipIDs, $returnProperties, $skipOnHold, $skipDeceased, $messageToken, $html_message, $categories) { |
2d3e3c7b | 62 | $memberships = CRM_Utils_Token::getMembershipTokenDetails($membershipIDs); |
63 | ||
995fc677 E |
64 | foreach ($membershipIDs as $membershipID) { |
65 | $membership = $memberships[$membershipID]; | |
2d3e3c7b | 66 | // get contact information |
67 | $contactId = $membership['contact_id']; | |
68 | $params = array('contact_id' => $contactId); | |
69 | //getTokenDetails is much like calling the api contact.get function - but - with some minor | |
e3946c7f | 70 | // special handlings. It preceeds the existence of the api |
2d3e3c7b | 71 | list($contacts) = CRM_Utils_Token::getTokenDetails( |
72 | $params, | |
73 | $returnProperties, | |
74 | $skipOnHold, | |
75 | $skipDeceased, | |
76 | NULL, | |
77 | $messageToken, | |
78 | 'CRM_Contribution_Form_Task_PDFLetterCommon' | |
79 | ); | |
80 | ||
81 | $tokenHtml = CRM_Utils_Token::replaceContactTokens($html_message, $contacts[$contactId], TRUE, $messageToken); | |
82 | $tokenHtml = CRM_Utils_Token::replaceEntityTokens('membership', $membership, $tokenHtml, $messageToken); | |
0cc4a61d | 83 | $tokenHtml = CRM_Utils_Token::replaceHookTokens($tokenHtml, $contacts[$contactId], $categories, TRUE); |
84 | $tokenHtml = CRM_Utils_Token::parseThroughSmarty($tokenHtml, $contacts[$contactId]); | |
2d3e3c7b | 85 | |
86 | $html[] = $tokenHtml; | |
87 | ||
88 | } | |
89 | return $html; | |
90 | } | |
91 | } | |
92 |