worked on CRM-12463, more fixes
authorKurund Jalmi <kurund@civicrm.org>
Thu, 2 May 2013 07:26:57 +0000 (00:26 -0700)
committerKurund Jalmi <kurund@civicrm.org>
Thu, 2 May 2013 07:26:57 +0000 (00:26 -0700)
CRM/Contribute/BAO/ContributionSoft.php
CRM/Contribute/Form/Contribution.php
CRM/Contribute/Form/ContributionView.php
CRM/Contribute/Form/SoftCredit.php
templates/CRM/Contribute/Form/Contribution.tpl
templates/CRM/Contribute/Form/ContributionView.tpl
templates/CRM/Contribute/Form/SoftCredit.js
templates/CRM/Contribute/Form/SoftCredit.tpl

index ff9f5ed431f26c95b613ba2d52c78d045efbe13f..115d1640e839e15da681154c88f19e13b7a47738 100644 (file)
@@ -147,22 +147,28 @@ class CRM_Contribute_BAO_ContributionSoft extends CRM_Contribute_DAO_Contributio
    *  @static
    */
   static function getSoftContribution($params, $all = FALSE) {
+    $pcpFields = array(
+      'pcp_id',
+      'pcp_display_in_roll',
+      'pcp_roll_nickname',
+      'pcp_personal_note',
+    );
+
     $cs = new CRM_Contribute_DAO_ContributionSoft();
     $cs->copyValues($params);
     $softContribution = array();
     $cs->find();
+
     if ($cs->N > 0) {
       while ($cs->fetch()) {
-
         if ($all) {
-          foreach (array(
-                     'pcp_id', 'pcp_display_in_roll', 'pcp_roll_nickname', 'pcp_personal_note') as $key => $val) {
-            $softContribution[$val] = $cs->$val;
+          foreach ($pcpFields as $val) {
+            $softContribution['pcp'][$val] = $cs->$val;
           }
         }
-        $softContribution[$cs->id]['soft_credit_to'] = $cs->contact_id;
-        $softContribution[$cs->id]['soft_credit_id'] = $cs->id;
-        $softContribution[$cs->id]['soft_credit_amount'] = $cs->amount;
+        $softContribution['soft_credit'][$cs->id]['soft_credit_to'] = $cs->contact_id;
+        $softContribution['soft_credit'][$cs->id]['soft_credit_id'] = $cs->id;
+        $softContribution['soft_credit'][$cs->id]['soft_credit_amount'] = $cs->amount;
       }
     }
     return $softContribution;
index fb4eaecfc3eb4d3379ba3e0e5f921516acdd6916..459cd53e15927b63232113cf9538cfab7a76f8f8 100644 (file)
@@ -140,6 +140,11 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
    */
   public $_lineItems;
 
+  /**
+   * @var soft credit info
+   */
+  public $_softCreditInfo;
+
   protected $_formType;
   protected $_cdType;
 
@@ -296,7 +301,7 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
     }
 
     // set soft credit defaults
-    CRM_Contribute_Form_SoftCredit::setDefaultValues($defaults);
+    CRM_Contribute_Form_SoftCredit::setDefaultValues($defaults, $this);
 
     if ($this->_mode) {
       $config = CRM_Core_Config::singleton();
@@ -491,7 +496,6 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
 
     $showAdditionalInfo = FALSE;
 
-
     $defaults = $this->_values;
     $additionalDetailFields = array(
       'note',
index d8ab2223ac1dbffed907025a1d8318e805fc7c53..e909556b9c769b0cc590a1d2b99a0b25d3ed51c8 100644 (file)
@@ -132,7 +132,7 @@ class CRM_Contribute_Form_ContributionView extends CRM_Core_Form {
     $softParams = array('contribution_id' => CRM_Utils_Array::value('contribution_id', $values));
     $softContribution = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($softParams);
     if (!empty($softContribution)) {
-      foreach($softContribution as &$individualSoftContribution) {
+      foreach($softContribution['soft_credit'] as &$individualSoftContribution) {
         $individualSoftContribution['softCreditToName'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact',
           $individualSoftContribution['soft_credit_to'], 'display_name'
         );
index a672e788c0d686349ec1f3af6f240a346b1ce148..d6bd8fd1cd93f195b0d8f975125def4f3637bb3b 100644 (file)
@@ -49,15 +49,27 @@ class CRM_Contribute_Form_SoftCredit {
   static function buildQuickForm(&$form) {
     $prefix = 'soft_credit_';
     // by default generate 5 blocks
-    $form->_softCredit['item_count'] = 6;
-    for ($rowNumber = 1; $rowNumber <= $form->_softCredit['item_count']; $rowNumber++) {
+    $item_count = 6;
+
+    if ($form->_action & CRM_Core_Action::UPDATE) {
+      $csParams = array('contribution_id' => $form->_id);
+      $form->_softCreditInfo = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($csParams, TRUE);
+      $showSoftCreditRow = count($form->_softCreditInfo['soft_credit']);
+      $showSoftCreditRow++;
+    }
+    else {
+      $showSoftCreditRow = 2;
+    }
+
+    for ($rowNumber = 1; $rowNumber <= $item_count; $rowNumber++) {
       CRM_Contact_Form_NewContact::buildQuickForm($form, $rowNumber, NULL, FALSE, $prefix);
       $form->addMoney("{$prefix}amount[{$rowNumber}]", ts('Amount'));
     }
 
-    $form->assign('rowCount', $form->_softCredit['item_count']);
+    $form->assign('showSoftCreditRow', $showSoftCreditRow);
+    $form->assign('rowCount', $item_count);
 
-    // Tell tpl to hide Soft Credit field if contribution is linked directly to a PCP Page
+    // Tell tpl to hide soft credit field if contribution is linked directly to a PCP Page
     if (CRM_Utils_Array::value('pcp_made_through_id', $form->_values)) {
       $form->assign('pcpLinked', 1);
     }
@@ -67,10 +79,12 @@ class CRM_Contribute_Form_SoftCredit {
   /**
    * Function used to set defaults for soft credit block
    */
-  static function setDefaultValues(&$defaults) {
-    $csParams = array('contribution_id' => $defaults['id']);
-    $softCredit = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($csParams, TRUE);
+  static function setDefaultValues(&$defaults, &$form) {
+
+    //crm_core_error::debug('$form->_softCreditInfo', $form->_softCreditInfo);
+    //exit;
 
+    /*
     if (CRM_Utils_Array::value('soft_credit_to', $softCredit)) {
       $softCredit['sort_name'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact',
         $softCredit['soft_credit_to'], 'sort_name'
@@ -79,16 +93,18 @@ class CRM_Contribute_Form_SoftCredit {
     $values['soft_credit_to'] = CRM_Utils_Array::value('sort_name', $softCredit);
     $values['softID'] = CRM_Utils_Array::value('soft_credit_id', $softCredit);
     $values['soft_contact_id'] = CRM_Utils_Array::value('soft_credit_to', $softCredit);
+    */
 
-    if (CRM_Utils_Array::value('pcp_id', $softCredit)) {
-      $pcpId = CRM_Utils_Array::value('pcp_id', $softCredit);
+    if (CRM_Utils_Array::value('pcp_id', $form->_softCreditInfo['pcp'])) {
+      $pcpInfo = $form->_softCreditInfo['pcp'];
+      $pcpId = CRM_Utils_Array::value('pcp_id', $pcpInfo);
       $pcpTitle = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $pcpId, 'title');
       $contributionPageTitle = CRM_PCP_BAO_PCP::getPcpPageTitle($pcpId, 'contribute');
-      $values['pcp_made_through'] = CRM_Utils_Array::value('sort_name', $softCredit) . " :: " . $pcpTitle . " :: " . $contributionPageTitle;
-      $values['pcp_made_through_id'] = CRM_Utils_Array::value('pcp_id', $softCredit);
-      $values['pcp_display_in_roll'] = CRM_Utils_Array::value('pcp_display_in_roll', $softCredit);
-      $values['pcp_roll_nickname'] = CRM_Utils_Array::value('pcp_roll_nickname', $softCredit);
-      $values['pcp_personal_note'] = CRM_Utils_Array::value('pcp_personal_note', $softCredit);
+      $values['pcp_made_through'] = CRM_Utils_Array::value('sort_name', $pcpInfo) . " :: " . $pcpTitle . " :: " . $contributionPageTitle;
+      $values['pcp_made_through_id'] = CRM_Utils_Array::value('pcp_id', $pcpInfo);
+      $values['pcp_display_in_roll'] = CRM_Utils_Array::value('pcp_display_in_roll', $pcpInfo);
+      $values['pcp_roll_nickname'] = CRM_Utils_Array::value('pcp_roll_nickname', $pcpInfo);
+      $values['pcp_personal_note'] = CRM_Utils_Array::value('pcp_personal_note', $pcpInfo);
     }
 
   }
index aa8e405a29ac9902f8fd500bdb4581cf6ef34f6c..9d55936693cc9d7de08a098c263f445e11ac8037 100644 (file)
                                  {if $siteHasPCPs}
                                          <tr class="crm-contribution-pcp-block-link">
                                                  <td colspan="2">
-                                                         <div id="showPCP"><a
-                                                                         href='#'>{ts}credit this contribution to a personal campaign page{/ts}</a>{help id="id-link_pcp"}
+                                                         <div id="showPCP">
+                  <a href='#'>{ts}credit this contribution to a personal campaign page{/ts}</a>
                                                          </div>
                                                  </td>
                                          </tr>
-                                         <tr class="crm-contribution-pcp-block crm-contribution-form-block-pcp_made_through_id">
+                                         <tr class="crm-contribution-pcp-block crm-contribution-form-block-pcp_made_through_id hiddenElement">
                                                  <td class="label">{$form.pcp_made_through.label}</td>
                                                  <td>
                                                          {$form.pcp_made_through.html} &nbsp;
index 4b218284a8af4a0a0c0f3129975a508465394263..cb23e46dc094f6063fc77d85442893160b63d6be 100644 (file)
     </div>
     <div class="crm-accordion-body">
       <table class="crm-info-panel">
-        {foreach from=$softContributions item="softCont"}
+        {foreach from=$softContributions.soft_credit item="softCont"}
           {if $softCont }
             <tr>
               <td class="label">{ts}Soft Credit To{/ts}</td>
index 548c4bcb956519f591a6ed463ebea4cbc17dd220..ae8ac9a9a0525a4eab6bf20e328db2ab5db7e1e1 100644 (file)
@@ -1,6 +1,5 @@
 // http://civicrm.org/licensing
 cj(function($) {
-  $('.crm-contribution-pcp-block').hide();
   $('#showPCP, #showSoftCredit').click(function(){
     return showHideSoftCreditAndPCP();
   });
index 53ac6fadc47a3ae766c544d39263b3f812c4ffd7..eb8d237158c337059709919f255da930fa0ea308 100644 (file)
@@ -28,7 +28,7 @@
 <table class="form-layout-compressed crm-soft-credit-block">
 {section name='i' start=1 loop=$rowCount}
 {assign var='rowNumber' value=$smarty.section.i.index}
-  <tr id="soft-credit-row-{$rowNumber}" class="crm-contribution-form-block-soft_credit_to {if $rowNumber gt 1}hiddenElement{/if}">
+  <tr id="soft-credit-row-{$rowNumber}" class="crm-contribution-form-block-soft_credit_to {if $rowNumber gte $showSoftCreditRow}hiddenElement{/if}">
     <td class="label">{ts}Soft Credit To{/ts}</td>
     <td>
       {include file="CRM/Contact/Form/NewContact.tpl" noLabel=true skipBreak=true blockNo=$rowNumber