-
-
Notifications
You must be signed in to change notification settings - Fork 814
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CRM-16734 participant tokens in participant pdf #8260
Changes from 16 commits
1ce0f28
64ea3fb
914aa69
6f515aa
6f7aa9d
328641a
8d05192
7ede346
534ad5c
1cc405e
58aa8b7
b112746
4aa283d
2d70f39
343781b
2eff8be
d6e7117
4ed5ba8
5213a98
3bf5c4c
bc7ab86
7b00c8a
727796f
24e7dd5
065bc52
1d742d8
7e1a411
a737429
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<?php | ||
|
||
/* | ||
+--------------------------------------------------------------------+ | ||
| CiviCRM version 4.6 | | ||
+--------------------------------------------------------------------+ | ||
| Copyright CiviCRM LLC (c) 2004-2015 | | ||
+--------------------------------------------------------------------+ | ||
| This file is a part of CiviCRM. | | ||
| | | ||
| CiviCRM is free software; you can copy, modify, and distribute it | | ||
| under the terms of the GNU Affero General Public License | | ||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | ||
| | | ||
| CiviCRM is distributed in the hope that it will be useful, but | | ||
| WITHOUT ANY WARRANTY; without even the implied warranty of | | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | ||
| See the GNU Affero General Public License for more details. | | ||
| | | ||
| You should have received a copy of the GNU Affero General Public | | ||
| License and the CiviCRM Licensing Exception along | | ||
| with this program; if not, contact CiviCRM LLC | | ||
| at info[AT]civicrm[DOT]org. If you have questions about the | | ||
| GNU Affero General Public License or the licensing of CiviCRM, | | ||
| see the CiviCRM license FAQ at http://civicrm.org/licensing | | ||
+--------------------------------------------------------------------+ | ||
*/ | ||
|
||
/** | ||
* | ||
* @package CRM | ||
* @copyright CiviCRM LLC (c) 2004-2015 | ||
* $Id$ | ||
* | ||
*/ | ||
|
||
/** | ||
* This class provides the common functionality for creating PDF letter for | ||
* one or a group of participant ids. | ||
*/ | ||
class CRM_Event_Form_Task_PDFLetterCommon extends CRM_Contact_Form_Task_PDFLetterCommon { | ||
/** | ||
* Process the form after the input has been submitted and validated. | ||
* @access public | ||
*/ | ||
public static function postProcess(&$form) { | ||
|
||
list($formValues, $categories, $html_message, $messageToken, $returnProperties) = self::processMessageTemplate($form); | ||
|
||
$skipOnHold = isset($form->skipOnHold) ? $form->skipOnHold : FALSE; | ||
$skipDeceased = isset($form->skipDeceased) ? $form->skipDeceased : TRUE; | ||
|
||
foreach ($form->_participantIds as $participantID) { | ||
|
||
$participant = civicrm_api3('participant', 'get', array('participant_id' => $participantID)); | ||
$participant = $participant['values'][$participantID]; | ||
$event = civicrm_api3('event', 'get', array('id' => $participant['event_id'])); | ||
$event = $event['values'][$participant['event_id']]; | ||
|
||
// get contact information | ||
// Use 'getTokenDetails' so that hook_civicrm_tokenValues is called. | ||
$contactId = $participant['contact_id']; | ||
$params = array('id' => $contactId); | ||
list($contact) = CRM_Utils_Token::getTokenDetails($params, | ||
$returnProperties, | ||
$skipOnHold, | ||
$skipDeceased, | ||
NULL, | ||
$messageToken, | ||
'CRM_Contact_Form_Task_PDFLetterCommon' | ||
); | ||
|
||
$tokenHtml = CRM_Utils_Token::replaceContactTokens($html_message, $contact[$contactId], TRUE, $messageToken); | ||
$tokenHtml = CRM_Utils_Token::replaceEntityTokens('event', $event, $tokenHtml, $messageToken); | ||
$tokenHtml = CRM_Utils_Token::replaceEntityTokens('participant', $participant, $tokenHtml, $messageToken); | ||
$tokenHtml = CRM_Utils_Token::replaceHookTokens($tokenHtml, $contact[$contactId], $categories, TRUE); | ||
|
||
if (defined('CIVICRM_MAIL_SMARTY') && CIVICRM_MAIL_SMARTY) { | ||
$smarty = CRM_Core_Smarty::singleton(); | ||
// also add the contact tokens to the template | ||
$smarty->assign_by_ref('contact', $contact); | ||
$smarty->assign_by_ref('event', $event); | ||
$smarty->assign_by_ref('participant', $participant); | ||
$tokenHtml = $smarty->fetch("string:$tokenHtml"); | ||
} | ||
|
||
$html[] = $tokenHtml; | ||
} | ||
|
||
self::createActivities($form, $html_message, $form->_contactIds); | ||
|
||
CRM_Utils_PDF_Utils::html2pdf($html, "CiviLetter.pdf", FALSE, $formValues); | ||
|
||
$form->postProcessHook(); | ||
|
||
CRM_Utils_System::civiExit(1); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -858,7 +858,6 @@ public static function getHookTokenReplacement( | |
if ($escapeSmarty) { | ||
$value = self::tokenEscapeSmarty($value); | ||
} | ||
|
||
return $value; | ||
} | ||
|
||
|
@@ -1605,6 +1604,44 @@ protected static function _buildMembershipTokens() { | |
} | ||
} | ||
|
||
/** | ||
* store event tokens on the static _tokens array | ||
*/ | ||
protected static function _buildEventTokens() { | ||
$key = 'event'; | ||
if (!isset(self::$_tokens[$key]) || self::$_tokens[$key] == NULL) { | ||
$eventTokens = array(); | ||
$tokens = CRM_Core_SelectValues::eventTokens(); | ||
foreach ($tokens as $token => $dontCare) { | ||
$eventTokens[] = substr($token, (strpos($token, '.') + 1), -1); | ||
} | ||
$customtokens = CRM_CORE_BAO_CustomField::getFields('Event'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pretty sure it needs to be |
||
foreach ($customtokens as $tokenkey => $tokenvalue) { | ||
$eventTokens[] = 'custom_' . $tokenkey; | ||
} | ||
self::$_tokens[$key] = $eventTokens; | ||
} | ||
} | ||
|
||
/** | ||
* store participant tokens on the static _tokens array | ||
*/ | ||
protected static function _buildParticipantTokens() { | ||
$key = 'participant'; | ||
if (!isset(self::$_tokens[$key]) || self::$_tokens[$key] == NULL) { | ||
$participantTokens = array(); | ||
$tokens = CRM_Core_SelectValues::participantTokens(); | ||
foreach ($tokens as $token => $dontCare) { | ||
$participantTokens[] = substr($token, (strpos($token, '.') + 1), -1); | ||
} | ||
$customtokens = CRM_CORE_BAO_CustomField::getFields('Participant'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pretty sure it needs to be |
||
foreach ($customtokens as $tokenkey => $tokenvalue) { | ||
$participantTokens[] = 'custom_' . $tokenkey; | ||
} | ||
self::$_tokens[$key] = $participantTokens; | ||
} | ||
} | ||
|
||
/** | ||
* Replace tokens for an entity. | ||
* @param string $entity | ||
|
@@ -1758,6 +1795,147 @@ public static function replaceMultipleContributionTokens($separator, $str, &$con | |
return self::replaceContributionTokens($str, $contribution, $html, $knownTokens, $escapeSmarty); | ||
} | ||
|
||
/** | ||
* Get replacement strings for any event tokens | ||
* @param string $entity - name of entity type, should be Event. | ||
* @param string $token | ||
* @param array $event an api result array for a single event | ||
* @param bool $escapeSmarty | ||
* @return string token replacement | ||
*/ | ||
public static function getEventTokenReplacement($entity, $token, $event, $escapeSmarty = FALSE) { | ||
$entity = strtolower($entity); | ||
if ($entity != 'event') { | ||
// Not sure which exception is appropriate. | ||
throw new Exception('$entity is expected to be "event".'); | ||
} | ||
|
||
self::_buildEventTokens(); | ||
|
||
$params = array('entity_id' => $event['id'], 'entity_table' => 'civicrm_event'); | ||
|
||
switch ($token) { | ||
case 'balance': | ||
$info = CRM_Contribute_BAO_Contribution::getPaymentInfo($params['participant_id'], 'event'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no key |
||
$balancePay = CRM_Utils_Array::value('balance', $info); | ||
$balancePay = CRM_Utils_Money::format($balancePay); | ||
$value = $balancePay; | ||
break; | ||
|
||
case 'title': | ||
$value = $event['event_title']; | ||
break; | ||
|
||
case 'end_date': | ||
case 'start_date': | ||
$value = CRM_Utils_Date::customFormat($event[$token], "%d/%m/%Y"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Date format should not be hard-coded |
||
break; | ||
|
||
case 'type': | ||
$params = array( | ||
'option_group_id' => 14, | ||
'value' => $event['event_type_id'], | ||
'return' => 'label', | ||
); | ||
$value = civicrm_api3('OptionValue', 'getvalue', $params); | ||
break; | ||
|
||
case 'location': | ||
$location = CRM_Core_BAO_Location::getValues($params, TRUE); | ||
foreach ($location['address'] as $address) { | ||
$value = $address['display_text']; | ||
} | ||
break; | ||
|
||
case 'info_url': | ||
$value = CIVICRM_UF_BASEURL . 'civicrm/event/info?reset=1&id=' . $event['id']; | ||
break; | ||
|
||
case 'registration_url': | ||
$value = CIVICRM_UF_BASEURL . 'civicrm/event/register?reset=1&id=' . $event['id']; | ||
break; | ||
|
||
case 'event_id': | ||
$value = $event['id']; | ||
break; | ||
|
||
case 'event_type': | ||
$value = CRM_Utils_Array::value($event['event_type_id'], CRM_Event_PseudoConstant::eventType()); | ||
break; | ||
|
||
default: | ||
if (in_array($token, self::$_tokens[$entity])) { | ||
$value = $event[$token]; | ||
} | ||
else { | ||
$value = "{$entity}.{$token}"; | ||
} | ||
break; | ||
} | ||
|
||
if ($escapeSmarty) { | ||
$value = self::tokenEscapeSmarty($value); | ||
} | ||
return $value; | ||
} | ||
|
||
/** | ||
* Get replacement strings for any participant tokens | ||
* @param string $entity - name of entity type, should be Participant. | ||
* @param string $token | ||
* @param array $participant an api result array for a single participant | ||
* @param bool $escapeSmarty | ||
* @return string token replacement | ||
*/ | ||
public static function getParticipantTokenReplacement($entity, $token, $participant, $escapeSmarty = FALSE) { | ||
$entity = strtolower($entity); | ||
if ($entity != 'participant') { | ||
// Not sure which exception is appropriate. | ||
throw new Exception('$entity is expected to be "participant".'); | ||
} | ||
|
||
self::_buildParticipantTokens(); | ||
|
||
$params = array('entity_id' => $participant['id'], 'entity_table' => 'civicrm_participant'); | ||
|
||
switch ($token) { | ||
case 'currency': | ||
$value = $participant['participant_fee_currency']; | ||
break; | ||
|
||
case 'participant_fee_level': | ||
if (is_array($participant['participant_fee_level'])) { | ||
$value = ''; | ||
foreach ($participant['participant_fee_level'] as $fee_level) { | ||
$value .= $fee_level . "<br>"; | ||
} | ||
} | ||
else { | ||
$value = $participant['participant_fee_level']; | ||
} | ||
break; | ||
|
||
case 'event_end_date': | ||
case 'event_start_date': | ||
$value = CRM_Utils_Date::customFormat($participant[$token], "%d/%m/%Y"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Date format should not be hard-coded |
||
break; | ||
|
||
default: | ||
if (in_array($token, self::$_tokens[$entity])) { | ||
$value = $participant[$token]; | ||
} | ||
else { | ||
$value = "{$entity}.{$token}"; | ||
} | ||
break; | ||
} | ||
|
||
if ($escapeSmarty) { | ||
$value = self::tokenEscapeSmarty($value); | ||
} | ||
return $value; | ||
} | ||
|
||
/** | ||
* Get replacement strings for any membership tokens (only a small number of tokens are implemnted in the first instance | ||
* - this is used by the pdfLetter task from membership search | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty sure it needs to be
CRM_Core_BAO_CustomField
(i.e.Core
in mixed case).