Skip to content

Commit

Permalink
Merge pull request #14960 from eileenmcnaughton/event_test
Browse files Browse the repository at this point in the history
dev/drupal#72 Ensure front end profile title is used in event confirmation emails
  • Loading branch information
eileenmcnaughton authored Aug 7, 2019
2 parents 35e61ac + e1a29ba commit e94e024
Show file tree
Hide file tree
Showing 8 changed files with 277 additions and 115 deletions.
188 changes: 102 additions & 86 deletions CRM/Contribute/BAO/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -2913,6 +2913,7 @@ public function composeMessageArray(&$input, &$ids, &$values, $returnMessageText
* The set of ids related to the input.
*
* @return array
* @throws \CRM_Core_Exception
*/
public function _gatherMessageValues($input, &$values, $ids = []) {
// set display address of contributor
Expand Down Expand Up @@ -2994,92 +2995,7 @@ public function _gatherMessageValues($input, &$values, $ids = []) {
}
}
else {
// event
$eventParams = [
'id' => $this->_relatedObjects['event']->id,
];
$values['event'] = [];

CRM_Event_BAO_Event::retrieve($eventParams, $values['event']);
// add custom fields for event
$eventGroupTree = CRM_Core_BAO_CustomGroup::getTree('Event', NULL, $this->_relatedObjects['event']->id);

$eventCustomGroup = [];
foreach ($eventGroupTree as $key => $group) {
if ($key === 'info') {
continue;
}

foreach ($group['fields'] as $k => $customField) {
$groupLabel = $group['title'];
if (!empty($customField['customValue'])) {
foreach ($customField['customValue'] as $customFieldValues) {
$eventCustomGroup[$groupLabel][$customField['label']] = CRM_Utils_Array::value('data', $customFieldValues);
}
}
}
}
$values['event']['customGroup'] = $eventCustomGroup;

//get participant details
$participantParams = [
'id' => $this->_relatedObjects['participant']->id,
];

$values['participant'] = [];

CRM_Event_BAO_Participant::getValues($participantParams, $values['participant'], $participantIds);
// add custom fields for event
$participantGroupTree = CRM_Core_BAO_CustomGroup::getTree('Participant', NULL, $this->_relatedObjects['participant']->id);
$participantCustomGroup = [];
foreach ($participantGroupTree as $key => $group) {
if ($key === 'info') {
continue;
}

foreach ($group['fields'] as $k => $customField) {
$groupLabel = $group['title'];
if (!empty($customField['customValue'])) {
foreach ($customField['customValue'] as $customFieldValues) {
$participantCustomGroup[$groupLabel][$customField['label']] = CRM_Utils_Array::value('data', $customFieldValues);
}
}
}
}
$values['participant']['customGroup'] = $participantCustomGroup;

//get location details
$locationParams = [
'entity_id' => $this->_relatedObjects['event']->id,
'entity_table' => 'civicrm_event',
];
$values['location'] = CRM_Core_BAO_Location::getValues($locationParams);

$ufJoinParams = [
'entity_table' => 'civicrm_event',
'entity_id' => $ids['event'],
'module' => 'CiviEvent',
];

list($custom_pre_id,
$custom_post_ids
) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);

$values['custom_pre_id'] = $custom_pre_id;
$values['custom_post_id'] = $custom_post_ids;

// set lineItem for event contribution
if ($this->id) {
$participantIds = CRM_Event_BAO_Participant::getParticipantIds($this->id);
if (!empty($participantIds)) {
foreach ($participantIds as $pIDs) {
$lineItem = CRM_Price_BAO_LineItem::getLineItems($pIDs);
if (!CRM_Utils_System::isNull($lineItem)) {
$values['lineItem'][] = $lineItem;
}
}
}
}
$values = array_merge($values, $this->loadEventMessageTemplateParams((int) $ids['event'], (int) $this->_relatedObjects['participant']->id, $this->id));
}

$groupTree = CRM_Core_BAO_CustomGroup::getTree('Contribution', NULL, $this->id);
Expand Down Expand Up @@ -5959,4 +5875,104 @@ public static function getInvoiceNumber($contributionID) {
return NULL;
}

/**
* Load the values needed for the event message.
*
* @param int $eventID
* @param int $participantID
* @param int|null $contributionID
*
* @return array
* @throws \CRM_Core_Exception
*/
protected function loadEventMessageTemplateParams(int $eventID, int $participantID, $contributionID): array {

$eventParams = [
'id' => $eventID,
];
$values = ['event' => []];

CRM_Event_BAO_Event::retrieve($eventParams, $values['event']);
// add custom fields for event
$eventGroupTree = CRM_Core_BAO_CustomGroup::getTree('Event', NULL, $eventID);

$eventCustomGroup = [];
foreach ($eventGroupTree as $key => $group) {
if ($key === 'info') {
continue;
}

foreach ($group['fields'] as $k => $customField) {
$groupLabel = $group['title'];
if (!empty($customField['customValue'])) {
foreach ($customField['customValue'] as $customFieldValues) {
$eventCustomGroup[$groupLabel][$customField['label']] = CRM_Utils_Array::value('data', $customFieldValues);
}
}
}
}
$values['event']['customGroup'] = $eventCustomGroup;

//get participant details
$participantParams = [
'id' => $participantID,
];

$values['participant'] = [];

CRM_Event_BAO_Participant::getValues($participantParams, $values['participant'], $participantIds);
// add custom fields for event
$participantGroupTree = CRM_Core_BAO_CustomGroup::getTree('Participant', NULL, $participantID);
$participantCustomGroup = [];
foreach ($participantGroupTree as $key => $group) {
if ($key === 'info') {
continue;
}

foreach ($group['fields'] as $k => $customField) {
$groupLabel = $group['title'];
if (!empty($customField['customValue'])) {
foreach ($customField['customValue'] as $customFieldValues) {
$participantCustomGroup[$groupLabel][$customField['label']] = CRM_Utils_Array::value('data', $customFieldValues);
}
}
}
}
$values['participant']['customGroup'] = $participantCustomGroup;

//get location details
$locationParams = [
'entity_id' => $eventID,
'entity_table' => 'civicrm_event',
];
$values['location'] = CRM_Core_BAO_Location::getValues($locationParams);

$ufJoinParams = [
'entity_table' => 'civicrm_event',
'entity_id' => $eventID,
'module' => 'CiviEvent',
];

list($custom_pre_id,
$custom_post_ids
) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);

$values['custom_pre_id'] = $custom_pre_id;
$values['custom_post_id'] = $custom_post_ids;

// set lineItem for event contribution
if ($contributionID) {
$participantIds = CRM_Event_BAO_Participant::getParticipantIds($contributionID);
if (!empty($participantIds)) {
foreach ($participantIds as $pIDs) {
$lineItem = CRM_Price_BAO_LineItem::getLineItems($pIDs);
if (!CRM_Utils_System::isNull($lineItem)) {
$values['lineItem'][] = $lineItem;
}
}
}
}
return $values;
}

}
19 changes: 17 additions & 2 deletions CRM/Core/BAO/UFGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,8 @@ public static function getListingFields(
*
* @return array
* The fields that belong to this ufgroup(s)
* @throws \Exception
*
* @throws \CRM_Core_Exception
*/
public static function getFields(
$id,
Expand Down Expand Up @@ -366,7 +367,7 @@ public static function getFields(
}

if (empty($fields) && !$validGroup) {
CRM_Core_Error::fatal(ts('The requested Profile (gid=%1) is disabled OR it is not configured to be used for \'Profile\' listings in its Settings OR there is no Profile with that ID OR you do not have permission to access this profile. Please contact the site administrator if you need assistance.',
throw new CRM_Core_Exception(ts('The requested Profile (gid=%1) is disabled OR it is not configured to be used for \'Profile\' listings in its Settings OR there is no Profile with that ID OR you do not have permission to access this profile. Please contact the site administrator if you need assistance.',
[1 => implode(',', $profileIds)]
));
}
Expand Down Expand Up @@ -3626,4 +3627,18 @@ public static function reformatProfileFields(&$fields) {
}
}

/**
* Get the frontend_title for the profile, falling back on 'title' if none.
*
* @param int $profileID
*
* @return string
*
* @throws \CiviCRM_API3_Exception
*/
public static function getFrontEndTitle(int $profileID) {
$profile = civicrm_api3('UFGroup', 'getsingle', ['id' => $profileID, 'return' => ['title', 'frontend_title']]);
return $profile['frontend_title'] ?? $profile['title'];
}

}
43 changes: 24 additions & 19 deletions CRM/Event/BAO/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,9 @@ public static function usesPriceSet($id) {
* @param int $participantId
* @param bool $isTest
* @param bool $returnMessageText
*
* @return array|null
* @throws \CiviCRM_API3_Exception
*/
public static function sendMail($contactID, &$values, $participantId, $isTest = FALSE, $returnMessageText = FALSE) {

Expand Down Expand Up @@ -1110,43 +1112,44 @@ public static function sendMail($contactID, &$values, $participantId, $isTest =
$postProfileID = CRM_Utils_Array::value('additional_custom_post_id', $values, $postProfileID);
}

self::buildCustomDisplay($preProfileID,
$profilePre = self::buildCustomDisplay($preProfileID,
'customPre',
$contactID,
$template,
$participantId,
$isTest,
NULL,
TRUE,
$participantParams
);

self::buildCustomDisplay($postProfileID,
$profilePost = self::buildCustomDisplay($postProfileID,
'customPost',
$contactID,
$template,
$participantId,
$isTest,
NULL,
TRUE,
$participantParams
);

$sessions = CRM_Event_Cart_BAO_Conference::get_participant_sessions($participantId);

// @todo - the goal is that all params available to the message template are explicitly defined here rather than
// 'in a smattering of places'. Note that leakage can happen between mailings when not explicitly defined.
$tplParams = array_merge($values, $participantParams, [
'email' => $email,
'confirm_email_text' => CRM_Utils_Array::value('confirm_email_text', $values['event']),
'isShowLocation' => CRM_Utils_Array::value('is_show_location', $values['event']),
// The concept of contributeMode is deprecated.
'contributeMode' => CRM_Utils_Array::value('contributeMode', $template->_tpl_vars),
'customPre' => $profilePre[0],
'customPre_grouptitle' => empty($profilePre[1]) ? NULL : [CRM_Core_BAO_UFGroup::getFrontEndTitle((int) $preProfileID)],
'customPost' => $profilePost[0],
'customPost_grouptitle' => empty($profilePost[1]) ? NULL : [CRM_Core_BAO_UFGroup::getFrontEndTitle((int) $postProfileID)],
'participantID' => $participantId,
'conference_sessions' => $sessions,
'credit_card_number' =>
CRM_Utils_System::mungeCreditCard(
CRM_Utils_Array::value('credit_card_number', $participantParams)),
'credit_card_exp_date' =>
CRM_Utils_Date::mysqlToIso(
CRM_Utils_Date::format(
CRM_Utils_Array::value('credit_card_exp_date', $participantParams))),
'credit_card_number' => CRM_Utils_System::mungeCreditCard(CRM_Utils_Array::value('credit_card_number', $participantParams)),
'credit_card_exp_date' => CRM_Utils_Date::mysqlToIso(CRM_Utils_Date::format(CRM_Utils_Array::value('credit_card_exp_date', $participantParams))),
]);

// CRM-13890 : NOTE wait list condition need to be given so that
Expand Down Expand Up @@ -1242,10 +1245,11 @@ public static function sendMail($contactID, &$values, $participantId, $isTest =
* @param string $template
* @param int $participantId
* @param bool $isTest
* @param bool $isCustomProfile
* @param bool $returnResults
* @param array $participantParams
*
* @return array|null
* @throws \CRM_Core_Exception
*/
public static function buildCustomDisplay(
$id,
Expand All @@ -1254,7 +1258,7 @@ public static function buildCustomDisplay(
&$template,
$participantId,
$isTest,
$isCustomProfile = FALSE,
$returnResults = FALSE,
$participantParams = []
) {
if (!$id) {
Expand Down Expand Up @@ -1408,7 +1412,7 @@ public static function buildCustomDisplay(
}

//return if we only require array of participant's info.
if ($isCustomProfile) {
if ($returnResults) {
if (count($val)) {
return [$val, $groupTitles];
}
Expand All @@ -1431,6 +1435,10 @@ public static function buildCustomDisplay(
* Formatted array of key value.
*
* @param array $profileFields
*
* @throws \CRM_Core_Exception
* @throws \API_Exception
* @throws \CiviCRM_API3_Exception
*/
public static function displayProfile(&$params, $gid, &$groupTitle, &$values, &$profileFields = []) {
if ($gid) {
Expand All @@ -1446,11 +1454,8 @@ public static function displayProfile(&$params, $gid, &$groupTitle, &$values, &$
$fields = CRM_Core_BAO_UFGroup::getFields($gid, FALSE, CRM_Core_Action::ADD);
}

foreach ($fields as $v) {
if (!empty($v['groupTitle'])) {
$groupTitle['groupTitle'] = $v['groupTitle'];
break;
}
if (!empty($fields)) {
$groupTitle['groupTitle'] = CRM_Core_BAO_UFGroup::getFrontEndTitle((int) $gid);
}

$imProviders = CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id');
Expand Down
10 changes: 6 additions & 4 deletions CRM/Event/Form/Registration/Confirm.php
Original file line number Diff line number Diff line change
Expand Up @@ -1210,11 +1210,13 @@ public static function updateContactFields($contactID, $params, $fields, &$form)
}

/**
* Assign Profiles.
* Assign Profiles to the template.
*
* @param CRM_Core_Form $form
* @param CRM_Event_Form_Registration_Confirm $form
*
* @throws \Exception
*/
public static function assignProfiles(&$form) {
public static function assignProfiles($form) {
$participantParams = $form->_params;
$formattedValues = $profileFields = [];
$count = 1;
Expand All @@ -1227,7 +1229,7 @@ public static function assignProfiles(&$form) {
$prefix1 = '';
$prefix2 = '';
}
if ($participantValue != 'skip') {
if ($participantValue !== 'skip') {
//get the customPre profile info
if (!empty($form->_values[$prefix2 . 'custom_pre_id'])) {
$values = $groupName = [];
Expand Down
Loading

0 comments on commit e94e024

Please sign in to comment.