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