CRM-13981 handling SC on Gift Membership minor fix
[civicrm-core.git] / CRM / Member / Page / Tab.php
index 1e5f56fe0ac3b025cb7a6faa31f0603d67814560..412850068e140b01cfc1247c2885e55d9bb8c781 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.4                                                |
+ | CiviCRM version 4.5                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2013
+ * @copyright CiviCRM LLC (c) 2004-2014
  * $Id$
  *
  */
@@ -92,7 +92,7 @@ class CRM_Member_Page_Tab extends CRM_Core_Page {
       foreach (array('status', 'membership_type') as $fld) {
         $membership[$dao->id][$fld] = CRM_Utils_Array::value($fld, $statusANDType[$dao->id]);
       }
-      if (CRM_Utils_Array::value('is_current_member', $statusANDType[$dao->id])) {
+      if (!empty($statusANDType[$dao->id]['is_current_member'])) {
         $membership[$dao->id]['active'] = TRUE;
       }
       if (empty($dao->owner_membership_id)) {
@@ -122,7 +122,12 @@ class CRM_Member_Page_Tab extends CRM_Core_Page {
           array(
             'id' => $dao->id,
             'cid' => $this->_contactId,
-          )
+          ),
+          ts('more'),
+          FALSE,
+          'membership.tab.row',
+          'Membership',
+          $dao->id
         );
       }
       else {
@@ -131,12 +136,17 @@ class CRM_Member_Page_Tab extends CRM_Core_Page {
           array(
             'id' => $dao->id,
             'cid' => $this->_contactId,
-          )
+          ),
+          ts('more'),
+          FALSE,
+          'membership.tab.row',
+          'Membership',
+          $dao->id
         );
       }
 
       //does membership have auto renew CRM-7137.
-      if (CRM_Utils_Array::value('contribution_recur_id', $membership[$dao->id]) &&
+      if (!empty($membership[$dao->id]['contribution_recur_id']) &&
         !CRM_Member_BAO_Membership::isSubscriptionCancelled($membership[$dao->id]['membership_id'])
       ) {
         $membership[$dao->id]['auto_renew'] = 1;
@@ -177,7 +187,12 @@ class CRM_Member_Page_Tab extends CRM_Core_Page {
         array(
           'id' => $value['id'],
           'cid' => $this->_contactId,
-        )
+        ),
+        ts('more'),
+        FALSE,
+        'membershipType.organization.action',
+        'MembershipType',
+        $value['id']
       );
     }
 
@@ -190,6 +205,13 @@ class CRM_Member_Page_Tab extends CRM_Core_Page {
     if ($this->_contactId) {
       $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactId);
       $this->assign('displayName', $displayName);
+      $this->ajaxResponse['tabCount'] = CRM_Contact_BAO_Contact::getCountComponent('membership', $this->_contactId);
+      // Refresh other tabs with related data
+      $this->ajaxResponse['updateTabs'] = array(
+        '#tab_contribute' => CRM_Contact_BAO_Contact::getCountComponent('contribution', $this->_contactId),
+        '#tab_activity' => CRM_Contact_BAO_Contact::getCountComponent('activity', $this->_contactId),
+        '#tab_rel' => CRM_Contact_BAO_Contact::getCountComponent('rel', $this->_contactId),
+      );
     }
   }
 
@@ -301,10 +323,21 @@ class CRM_Member_Page_Tab extends CRM_Core_Page {
     if (CRM_Core_Permission::access('CiviContribute')) {
       $this->_accessContribution = TRUE;
       $this->assign('accessContribution', TRUE);
+
+      //show associated soft credit when contribution payment is paid by different person
+      if ($this->_id && $this->_contactId) {
+        $filter = " AND cc.id IN (SELECT contribution_id FROM civicrm_membership_payment WHERE membership_id = {$this->_id})";
+        $softCreditList = CRM_Contribute_BAO_ContributionSoft::getSoftContributionList($this->_contactId, $filter);
+        if (!empty($softCreditList)) {
+          $this->assign('softCredit', TRUE);
+          $this->assign('softCreditRows', $softCreditList);
+        }
+      }
     }
     else {
       $this->_accessContribution = FALSE;
       $this->assign('accessContribution', FALSE);
+      $this->assign('softCredit', FALSE);
     }
 
     if ($this->_action & CRM_Core_Action::VIEW) {
@@ -327,6 +360,9 @@ class CRM_Member_Page_Tab extends CRM_Core_Page {
     $context = CRM_Utils_Request::retrieve('context', 'String', $form, FALSE, 'search' );
 
     $qfKey = CRM_Utils_Request::retrieve('key', 'String', $form);
+
+    $searchContext = CRM_Utils_Request::retrieve('searchContext', 'String', $this);
+
     //validate the qfKey
     if (!CRM_Utils_Rule::qfKey($qfKey)) {
       $qfKey = NULL;
@@ -352,7 +388,12 @@ class CRM_Member_Page_Tab extends CRM_Core_Page {
         }
         $form->assign('searchKey', $qfKey);
 
-        $url = CRM_Utils_System::url('civicrm/member/search', $urlParams);
+        if ($searchContext) {
+          $url = CRM_Utils_System::url("civicrm/$searchContext/search", $urlParams);
+        }
+        else {
+          $url = CRM_Utils_System::url('civicrm/member/search', $urlParams);
+        }
         break;
 
       case 'home':
@@ -376,7 +417,7 @@ class CRM_Member_Page_Tab extends CRM_Core_Page {
         $urlString = 'civicrm/contact/search/custom';
         if ($action == CRM_Core_Action::UPDATE) {
           if ($form->_contactId) {
-            $urlParams .= '&cid=' . $this->_contactId;
+            $urlParams .= '&cid=' . $form->_contactId;
           }
           $keyName = '&key';
           $urlParams .= '&context=fulltext&action=view';
@@ -405,6 +446,12 @@ class CRM_Member_Page_Tab extends CRM_Core_Page {
   /**
    * Get action links
    *
+   * @param string $status
+   * @param null $isPaymentProcessor
+   * @param null $accessContribution
+   * @param bool $isCancelSupported
+   * @param bool $isUpdateBilling
+   *
    * @return array (reference) of action links
    * @static
    */