From: NileemaJadhav Date: Thu, 22 Jan 2015 13:15:29 +0000 (+0530) Subject: CRM-15821 PCP Improvements X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=5fe87df63e7139b857e55004771f577b6f396224;p=civicrm-core.git CRM-15821 PCP Improvements ---------------------------------------- * CRM-15821: Provide option to notify Personal Campaign Page "Owner" when someone donates via their page https://issues.civicrm.org/jira/browse/CRM-15821 --- diff --git a/CRM/Contribute/Form/Contribution/Confirm.php b/CRM/Contribute/Form/Contribution/Confirm.php index 5b33bc68ec..31ca13b77e 100644 --- a/CRM/Contribute/Form/Contribution/Confirm.php +++ b/CRM/Contribute/Form/Contribution/Confirm.php @@ -1777,20 +1777,38 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr */ public static function pcpNotifyOwner($contribution, $contributionSoft) { - $component = $contribution->_component ? $contribution->_component : 'contribute'; - $ownerNotifyID = CRM_PCP_BAO_PCP::getOwnerNotificationId($contributionSoft->pcp_id); - if ($ownerNotifyID != CRM_Core_OptionGroup::getValue('pcp_owner_notify', 'no_notifications', 'name') || - ($ownerNotifyID != CRM_Core_OptionGroup::getValue('pcp_owner_notify', 'owner_chooses', 'name') && - CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $contributionSoft->pcp_id, 'is_notify'))) { - $pcpPageTitle = CRM_PCP_BAO_PCP::getPcpPageTitle($contributionSoft->pcp_id, $component); + $params = array('id' => $contributionSoft->pcp_id); + CRM_Core_DAO::commonRetrieve('CRM_PCP_DAO_PCP', $params, $pcpInfo); + $ownerNotifyID = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCPBlock', $pcpInfo['pcp_block_id'], 'owner_notify_id'); + + if ($ownerNotifyID != CRM_Core_OptionGroup::getValue('pcp_owner_notify', 'no_notifications', 'name') && + (($ownerNotifyID == CRM_Core_OptionGroup::getValue('pcp_owner_notify', 'owner_chooses', 'name') && + CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $contributionSoft->pcp_id, 'is_notify')) || + $ownerNotifyID == CRM_Core_OptionGroup::getValue('pcp_owner_notify', 'all_owners', 'name'))) { + $pcpInfoURL = CRM_Utils_System::url('civicrm/pcp/info', + "reset=1&id={$contributionSoft->pcp_id}", + TRUE, NULL, FALSE, TRUE + ); // set email in the template here - $donorName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contribution->contact_id, 'display_name'); + // get the billing location type + $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate'); + $billingLocationTypeId = array_search('Billing', $locationTypes); + + if ($billingLocationTypeId) { + list($donorName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contribution->contact_id, FALSE, $billingLocationTypeId); + } + // get primary location email if no email exist( for billing location). + if (!$email) { + list($donorName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contribution->contact_id); + } + list($ownerName, $ownerEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contributionSoft->contact_id); $tplParams = array( - 'page_title' => $pcpPageTitle, + 'page_title' => $pcpInfo['title'], 'receive_date' => $contribution->receive_date, 'total_amount' => $contributionSoft->amount, 'donors_display_name' => $donorName, - 'donors_email' => CRM_Contact_BAO_Contact::getPrimaryEmail($contribution->contact_id), + 'donors_email' => $email, + 'pcpInfoURL' => $pcpInfoURL, 'is_honor_roll_enabled' => $contributionSoft->pcp_display_in_roll, ); $domainValues = CRM_Core_BAO_Domain::getNameAndEmail(); @@ -1798,8 +1816,8 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr 'groupName' => 'msg_tpl_workflow_contribution', 'valueName' => 'pcp_owner_notify', 'contactId' => $contributionSoft->contact_id, - 'toEmail' => CRM_Contact_BAO_Contact::getPrimaryEmail($contributionSoft->contact_id), - 'toName' => $donorName, + 'toEmail' => $ownerEmail, + 'toName' => $ownerName, 'from' => "$domainValues[0] <$domainValues[1]>", 'tplParams' => $tplParams, 'PDFFilename' => 'receipt.pdf', diff --git a/CRM/Contribute/Form/ContributionPage.php b/CRM/Contribute/Form/ContributionPage.php index c874053134..718805e7da 100644 --- a/CRM/Contribute/Form/ContributionPage.php +++ b/CRM/Contribute/Form/ContributionPage.php @@ -66,6 +66,13 @@ class CRM_Contribute_Form_ContributionPage extends CRM_Core_Form { */ protected $_first = FALSE; + /** + * Is this the last page? + * + * @var boolean + */ + protected $_last = FALSE; + /** * Store price set id. * @@ -155,31 +162,33 @@ class CRM_Contribute_Form_ContributionPage extends CRM_Core_Form { } if ($this->_single) { - $this->addButtons(array( - array( - 'type' => 'next', - 'name' => ts('Save'), - 'spacing' => '         ', - 'isDefault' => TRUE, - ), - array( - 'type' => 'upload', - 'name' => ts('Save and Done'), - 'spacing' => '         ', - 'subName' => 'done', - ), - array( - 'type' => 'submit', - 'name' => ts('Save and Next'), - 'spacing' => '                 ', - 'subName' => 'savenext', - ), - array( - 'type' => 'cancel', - 'name' => ts('Cancel'), - ), - ) + $buttons = array( + array( + 'type' => 'next', + 'name' => ts('Save'), + 'spacing' => '         ', + 'isDefault' => TRUE, + ), + array( + 'type' => 'upload', + 'name' => ts('Save and Done'), + 'spacing' => '         ', + 'subName' => 'done', + ), ); + if (!$this->_last) { + $buttons[] = array( + 'type' => 'submit', + 'name' => ts('Save and Next'), + 'spacing' => '                 ', + 'subName' => 'savenext', + ); + } + $buttons[] = array( + 'type' => 'cancel', + 'name' => ts('Cancel'), + ); + $this->addButtons($buttons); } else { $buttons = array(); diff --git a/CRM/PCP/BAO/PCP.php b/CRM/PCP/BAO/PCP.php index 754e5afd59..75923574eb 100644 --- a/CRM/PCP/BAO/PCP.php +++ b/CRM/PCP/BAO/PCP.php @@ -403,7 +403,7 @@ WHERE pcp.id = %1 AND cc.contribution_status_id =1 AND cc.is_test = 0"; //CRM-15821 - To add new option for PCP "Owner" notification $ownerNotifications = CRM_Core_OptionGroup::values('pcp_owner_notify'); - $form->addRadio('owner_notify_id', ts('Owner Notification'), $ownerNotifications, NULL, NULL, TRUE); + $form->addRadio('owner_notify_id', ts('Owner Notification'), $ownerNotifications, NULL, '
', TRUE); $form->addElement('checkbox', 'is_tellfriend_enabled', ts("Allow 'Tell a friend' functionality"), NULL, array('onclick' => "return showHideByValue('is_tellfriend_enabled',true,'tflimit','table-row','radio',false);")); @@ -431,20 +431,20 @@ WHERE pcp.id = %1 AND cc.contribution_status_id =1 AND cc.is_test = 0"; * @param CRM_Core_Page $page * @param null $elements */ - public function buildPcp($pcpId, &$page, &$elements = NULL) { + public static function buildPcp($pcpId, &$page, &$elements = NULL) { $prms = array('id' => $pcpId); CRM_Core_DAO::commonRetrieve('CRM_PCP_DAO_PCP', $prms, $pcpInfo); if ($pcpSupporter = CRM_PCP_BAO_PCP::displayName($pcpId)) { if ($pcpInfo['page_type'] == 'event') { - $pcp_supporter_text = ts('This event registration is being made thanks to effort of %1, who supports our campaign. ', array(1 => $pcpSupporter)); + $pcp_supporter_text = ts('This event registration is being made thanks to the efforts of %1, who supports our campaign. ', array(1 => $pcpSupporter)); $text = CRM_PCP_BAO_PCP::getPcpBlockStatus($pcpInfo['page_id'], 'event'); if (!empty($text)) { $pcp_supporter_text .= "You can support it as well - once you complete the registration, you will be able to create your own Personal Campaign Page!"; } } else { - $pcp_supporter_text = ts('This contribution is being made thanks to effort of %1, who supports our campaign. ', array(1 => $pcpSupporter)); + $pcp_supporter_text = ts('This contribution is being made thanks to the efforts of %1, who supports our campaign. ', array(1 => $pcpSupporter)); $text = CRM_PCP_BAO_PCP::getPcpBlockStatus($pcpInfo['page_id'], 'contribute'); if (!empty($text)) { $pcp_supporter_text .= "You can support it as well - once you complete the donation, you will be able to create your own Personal Campaign Page!"; @@ -920,19 +920,23 @@ INNER JOIN civicrm_uf_group ufgroup /** * Get owner notification id * - * @param int $pcpId + * @param int $component_id * @param $component * - * * @return int */ - public static function getOwnerNotificationId($pcpId) { + public static function getOwnerNotificationId($component_id, $component = 'contribute') { + $entity_table = self::getPcpEntityTable($component); $query = " SELECT pb.owner_notify_id FROM civicrm_pcp_block pb - LEFT JOIN civicrm_pcp pcp ON ( pb.id = pcp.pcp_block_id ) - WHERE pcp.id = %1"; - $params = array(1 => array($pcpId, 'Integer')); - return CRM_Core_DAO::singleValueQuery($query, $params); + WHERE pb.entity_id = %1 AND pb.entity_table = %2"; + $params = array(1 => array($component_id, 'Integer'), 2 => array($entity_table, 'String')); + if (!$ownerNotificationId = CRM_Core_DAO::singleValueQuery($query, $params)) { + CRM_Core_Error::fatal(ts('Owner Notification is not set for this Personal Campaign Page. Please contact the site administrator if you need assistance.')); + } + else { + return $ownerNotificationId; + } } } diff --git a/CRM/PCP/Form/Campaign.php b/CRM/PCP/Form/Campaign.php index 46e27b498f..321589e6be 100644 --- a/CRM/PCP/Form/Campaign.php +++ b/CRM/PCP/Form/Campaign.php @@ -128,8 +128,14 @@ class CRM_PCP_Form_Campaign extends CRM_Core_Form { $this->addElement('checkbox', 'is_thermometer', ts('Progress Bar')); $this->addElement('checkbox', 'is_honor_roll', ts('Honor Roll'), NULL); - - $owner_notification_option = $this->_pageId ? CRM_PCP_BAO_PCP::getOwnerNotificationId($this->_pageId) : CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCPBlock', $this->controller->get('component_page_id'), 'owner_notify_id'); + if ($this->_pageId) { + $params = array('id' => $this->_pageId); + CRM_Core_DAO::commonRetrieve('CRM_PCP_DAO_PCP', $params, $pcpInfo); + $owner_notification_option = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCPBlock', $pcpInfo['pcp_block_id'], 'owner_notify_id'); + } + else { + $owner_notification_option = CRM_PCP_BAO_PCP::getOwnerNotificationId($this->controller->get('component_page_id'), $this->_component ? $this->_component : 'contribute'); + } if ($owner_notification_option == CRM_Core_OptionGroup::getValue('pcp_owner_notify', 'owner_chooses', 'name')) { $this->assign('owner_notification_option', TRUE); $this->addElement('checkbox', 'is_notify', ts('Notify me via email when someone donates to my page'), NULL); diff --git a/CRM/PCP/Form/Contribute.php b/CRM/PCP/Form/Contribute.php index f9d45376d6..abd5243d51 100644 --- a/CRM/PCP/Form/Contribute.php +++ b/CRM/PCP/Form/Contribute.php @@ -89,6 +89,7 @@ class CRM_PCP_Form_Contribute extends CRM_Contribute_Form_ContributionPage { * @return void */ public function buildQuickForm() { + $this->_last = TRUE; CRM_PCP_BAO_PCP::buildPCPForm($this); $this->addElement('checkbox', 'pcp_active', ts('Enable Personal Campaign Pages? (for this contribution page)'), NULL, array('onclick' => "return showHideByValue('pcp_active',true,'pcpFields','table-row','radio',false);")); diff --git a/CRM/Upgrade/4.6.alpha4.msg_template/message_templates/pcp_owner_notify_html.tpl b/CRM/Upgrade/4.6.alpha4.msg_template/message_templates/pcp_owner_notify_html.tpl index 043c8dfe4c..41681f9887 100644 --- a/CRM/Upgrade/4.6.alpha4.msg_template/message_templates/pcp_owner_notify_html.tpl +++ b/CRM/Upgrade/4.6.alpha4.msg_template/message_templates/pcp_owner_notify_html.tpl @@ -11,7 +11,7 @@ {capture assign=valueStyle }style="padding: 4px; border-bottom: 1px solid #999;"{/capture} {capture assign=pcpURL }{crmURL p="civicrm/pcp/info" q="reset=1&id=`$pcpId`" h=0 a=1}{/capture} -

{ts}You have received a donation at your personal page{/ts}: {$page_title}

+

{ts}You have received a donation at your personal page{/ts}: {$page_title}

{ts}Your fundraising total has been updated.{/ts}
{ts}The donor's information is listed below. You can choose to contact them and convey your thanks if you wish.{/ts}
{if $is_honor_roll_enabled} diff --git a/CRM/Upgrade/4.6.alpha4.msg_template/message_templates/pcp_owner_notify_text.tpl b/CRM/Upgrade/4.6.alpha4.msg_template/message_templates/pcp_owner_notify_text.tpl index 365eeda55b..3edd98a62f 100644 --- a/CRM/Upgrade/4.6.alpha4.msg_template/message_templates/pcp_owner_notify_text.tpl +++ b/CRM/Upgrade/4.6.alpha4.msg_template/message_templates/pcp_owner_notify_text.tpl @@ -3,6 +3,7 @@ =========================================================== {ts}You have received a donation at your personal page{/ts}: {$page_title} +>> {$pcpInfoURL} {ts}Your fundraising total has been updated.{/ts} {ts}The donor's information is listed below. You can choose to contact them and convey your thanks if you wish.{/ts} diff --git a/templates/CRM/PCP/Form/PCP.tpl b/templates/CRM/PCP/Form/PCP.tpl index 9f8af10f60..38ea15c944 100644 --- a/templates/CRM/PCP/Form/PCP.tpl +++ b/templates/CRM/PCP/Form/PCP.tpl @@ -67,7 +67,7 @@ {$form.owner_notify_id.label} - {$form.owner_notify_id.html} {help id="id-owner_notify"} + {$form.owner_notify_id.html} {$form.is_tellfriend_enabled.label} diff --git a/xml/templates/message_templates/pcp_owner_notify_html.tpl b/xml/templates/message_templates/pcp_owner_notify_html.tpl index 043c8dfe4c..41681f9887 100644 --- a/xml/templates/message_templates/pcp_owner_notify_html.tpl +++ b/xml/templates/message_templates/pcp_owner_notify_html.tpl @@ -11,7 +11,7 @@ {capture assign=valueStyle }style="padding: 4px; border-bottom: 1px solid #999;"{/capture} {capture assign=pcpURL }{crmURL p="civicrm/pcp/info" q="reset=1&id=`$pcpId`" h=0 a=1}{/capture} -

{ts}You have received a donation at your personal page{/ts}: {$page_title}

+

{ts}You have received a donation at your personal page{/ts}: {$page_title}

{ts}Your fundraising total has been updated.{/ts}
{ts}The donor's information is listed below. You can choose to contact them and convey your thanks if you wish.{/ts}
{if $is_honor_roll_enabled} diff --git a/xml/templates/message_templates/pcp_owner_notify_text.tpl b/xml/templates/message_templates/pcp_owner_notify_text.tpl index 365eeda55b..3edd98a62f 100644 --- a/xml/templates/message_templates/pcp_owner_notify_text.tpl +++ b/xml/templates/message_templates/pcp_owner_notify_text.tpl @@ -3,6 +3,7 @@ =========================================================== {ts}You have received a donation at your personal page{/ts}: {$page_title} +>> {$pcpInfoURL} {ts}Your fundraising total has been updated.{/ts} {ts}The donor's information is listed below. You can choose to contact them and convey your thanks if you wish.{/ts}