Merge pull request #1875 from mlutfy/crm13354
[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 * @access public
14 *
15 * @return None
16 */
17 static function postProcess(&$form, $membershipIDs, $skipOnHold, $skipDeceased, $contactIDs) {
18
19 list($formValues, $categories, $html_message, $messageToken, $returnProperties) = self::processMessageTemplate($form);
20
21 $html = self::generateHTML($membershipIDs, $returnProperties, $skipOnHold, $skipDeceased, $messageToken, $html_message, $categories);
22 self::createActivities($form, $html_message, $contactIDs);
23
24 CRM_Utils_PDF_Utils::html2pdf($html, "CiviLetter.pdf", FALSE, $formValues);
25
26 $form->postProcessHook();
27
28 CRM_Utils_System::civiExit(1);
29 }
30 //end of function
31
32 /**
33 * generate htmlfor pdf letters
34 * @param unknown_type $membershipIDs
35 * @param unknown_type $returnProperties
36 * @param unknown_type $skipOnHold
37 * @param unknown_type $skipDeceased
38 * @param unknown_type $messageToken
39 * @return unknown
40 */
41 static function generateHTML($membershipIDs, $returnProperties, $skipOnHold, $skipDeceased, $messageToken, $html_message, $categories) {
42 $memberships = CRM_Utils_Token::getMembershipTokenDetails($membershipIDs);
43
44 foreach ($membershipIDs as $membershipID) {
45 $membership = $memberships[$membershipID];
46 // get contact information
47 $contactId = $membership['contact_id'];
48 $params = array('contact_id' => $contactId);
49 //getTokenDetails is much like calling the api contact.get function - but - with some minor
50 // special handlings. It preceeds the existance of the api
51 list($contacts) = CRM_Utils_Token::getTokenDetails(
52 $params,
53 $returnProperties,
54 $skipOnHold,
55 $skipDeceased,
56 NULL,
57 $messageToken,
58 'CRM_Contribution_Form_Task_PDFLetterCommon'
59 );
60
61 $tokenHtml = CRM_Utils_Token::replaceContactTokens($html_message, $contacts[$contactId], TRUE, $messageToken);
62 $tokenHtml = CRM_Utils_Token::replaceEntityTokens('membership', $membership, $tokenHtml, $messageToken);
63 $tokenHtml = CRM_Utils_Token::replaceHookTokens($tokenHtml, $contacts[$contactId], $categories, TRUE);
64 $tokenHtml = CRM_Utils_Token::parseThroughSmarty($tokenHtml, $contacts[$contactId]);
65
66 $html[] = $tokenHtml;
67
68 }
69 return $html;
70 }
71 }
72