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