CRM-15821 PCP Improvements
authorNileemaJadhav <nileema.jadhav@webaccess.co.in>
Thu, 22 Jan 2015 13:15:29 +0000 (18:45 +0530)
committerNileemaJadhav <nileema.jadhav@webaccess.co.in>
Thu, 22 Jan 2015 13:16:17 +0000 (18:46 +0530)
----------------------------------------
* CRM-15821: Provide option to notify Personal Campaign Page "Owner" when someone donates via their page
  https://issues.civicrm.org/jira/browse/CRM-15821

CRM/Contribute/Form/Contribution/Confirm.php
CRM/Contribute/Form/ContributionPage.php
CRM/PCP/BAO/PCP.php
CRM/PCP/Form/Campaign.php
CRM/PCP/Form/Contribute.php
CRM/Upgrade/4.6.alpha4.msg_template/message_templates/pcp_owner_notify_html.tpl
CRM/Upgrade/4.6.alpha4.msg_template/message_templates/pcp_owner_notify_text.tpl
templates/CRM/PCP/Form/PCP.tpl
xml/templates/message_templates/pcp_owner_notify_html.tpl
xml/templates/message_templates/pcp_owner_notify_text.tpl

index 5b33bc68ec2df194ac257ea223921b6285fe7e35..31ca13b77efe23b1de3f5eb95787c75041a9ed6f 100644 (file)
@@ -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',
index c8740531342bc0d0166269ca3c87396bd585e29b..718805e7dabc70bec7f615da9e1574632b1bf2cd 100644 (file)
@@ -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' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
-            'isDefault' => TRUE,
-          ),
-          array(
-            'type' => 'upload',
-            'name' => ts('Save and Done'),
-            'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
-            'subName' => 'done',
-          ),
-          array(
-            'type' => 'submit',
-            'name' => ts('Save and Next'),
-            'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
-            'subName' => 'savenext',
-          ),
-          array(
-            'type' => 'cancel',
-            'name' => ts('Cancel'),
-          ),
-        )
+      $buttons = array(
+        array(
+          'type' => 'next',
+          'name' => ts('Save'),
+          'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
+          'isDefault' => TRUE,
+        ),
+        array(
+          'type' => 'upload',
+          'name' => ts('Save and Done'),
+          'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
+          'subName' => 'done',
+        ),
       );
+      if (!$this->_last) {
+        $buttons[] = array(
+          'type' => 'submit',
+          'name' => ts('Save and Next'),
+          'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
+          'subName' => 'savenext',
+        );
+      }
+      $buttons[] = array(
+        'type' => 'cancel',
+        'name' => ts('Cancel'),
+      );
+      $this->addButtons($buttons);
     }
     else {
       $buttons = array();
index 754e5afd59046aa00703f6c6e83affce30629323..75923574eba302eac9a736f169ddd9cb4b456e11 100644 (file)
@@ -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, '<br/>', 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 <strong>%1</strong>, who supports our campaign. ', array(1 => $pcpSupporter));
+        $pcp_supporter_text = ts('This event registration is being made thanks to the efforts of <strong>%1</strong>, 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 <strong>%1</strong>, who supports our campaign. ', array(1 => $pcpSupporter));
+        $pcp_supporter_text = ts('This contribution is being made thanks to the efforts of <strong>%1</strong>, 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;
+    }
   }
 }
index 46e27b498f91603d22b5db2b45e277161ba5c8df..321589e6be2aa79de83562153f53f21bf1b78ff7 100644 (file)
@@ -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);
index f9d45376d6c228ce7694f59c9a07c78179fb277b..abd5243d513688ee978019277263a7d75c7f1c96 100644 (file)
@@ -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);"));
index 043c8dfe4c04b49bfb341db4b00bdf15adfd87b4..41681f9887c1617e71da48f1d60bf137d538e752 100644 (file)
@@ -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}
 
-  <p>{ts}You have received a donation at your personal page{/ts}: {$page_title}</p>
+  <p>{ts}You have received a donation at your personal page{/ts}: <a href="{$pcpInfoURL}">{$page_title}</a></p>
   <p>{ts}Your fundraising total has been updated.{/ts}<br/>
     {ts}The donor's information is listed below.  You can choose to contact them and convey your thanks if you wish.{/ts} <br/>
     {if $is_honor_roll_enabled}
index 365eeda55bf883ddf9c3a36a24a73b28acadc63b..3edd98a62f637a849e9fb8322374b21c72174caa 100644 (file)
@@ -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}
index 9f8af10f60d17ff60aae1b671bd8a699842c6e55..38ea15c9449229034916995cacd02ae37c4e54bd 100644 (file)
@@ -67,7 +67,7 @@
      </tr>
      <tr class="crm-contribution-contributionpage-pcp-form-block-owner_notify_id">
         <td class="label">{$form.owner_notify_id.label}</td>
-        <td>{$form.owner_notify_id.html} {help id="id-owner_notify"}</td>
+        <td>{$form.owner_notify_id.html}</td>
      </tr>
      <tr class="crm-contribution-contributionpage-pcp-form-block-is_tellfriend_enabled">
         <td class="label">{$form.is_tellfriend_enabled.label}</td>
index 043c8dfe4c04b49bfb341db4b00bdf15adfd87b4..41681f9887c1617e71da48f1d60bf137d538e752 100644 (file)
@@ -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}
 
-  <p>{ts}You have received a donation at your personal page{/ts}: {$page_title}</p>
+  <p>{ts}You have received a donation at your personal page{/ts}: <a href="{$pcpInfoURL}">{$page_title}</a></p>
   <p>{ts}Your fundraising total has been updated.{/ts}<br/>
     {ts}The donor's information is listed below.  You can choose to contact them and convey your thanks if you wish.{/ts} <br/>
     {if $is_honor_roll_enabled}
index 365eeda55bf883ddf9c3a36a24a73b28acadc63b..3edd98a62f637a849e9fb8322374b21c72174caa 100644 (file)
@@ -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}