CRM-13992 : handling multi-custom data listing, edit, add, view actions. reused profi...
[civicrm-core.git] / CRM / Contact / Page / View / CustomData.php
index 50411420d86a9b465471952974ef3b8ed45abcbe..6b0bdc7a58373046a878692cee687a07f43b4036 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
+ | CiviCRM version 4.4                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2013                                |
  +--------------------------------------------------------------------+
@@ -75,6 +75,10 @@ class CRM_Contact_Page_View_CustomData extends CRM_Core_Page {
 
     $this->_groupId = CRM_Utils_Request::retrieve('gid', 'Positive', $this, TRUE);
     $this->assign('groupId', $this->_groupId);
+
+    $this->_multiRecordDisplay = CRM_Utils_Request::retrieve('multiRecordDisplay', 'String', $this, FALSE);
+    $this->_cgcount = CRM_Utils_Request::retrieve('cgcount', 'Positive', $this, FALSE);
+    $this->_recId = CRM_Utils_Request::retrieve('recId', 'Positive', $this, FALSE);
   }
 
   /**
@@ -87,7 +91,7 @@ class CRM_Contact_Page_View_CustomData extends CRM_Core_Page {
    *
    * @param object $page - the view page which created this one
    *
-   * @return none
+   * @return void
    * @static
    *
    */
@@ -119,7 +123,39 @@ class CRM_Contact_Page_View_CustomData extends CRM_Core_Page {
       $groupTree     = &CRM_Core_BAO_CustomGroup::getTree($entityType, $this, $this->_contactId,
         $this->_groupId, $entitySubType
       );
-      CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree);
+
+      $displayStyle = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup',
+        $this->_groupId,
+        'style'
+      );
+
+      if ($displayStyle === 'Tab with table' && $this->_multiRecordDisplay != 'single') {
+        $ctype = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact',
+          $this->_contactId,
+          'contact_type'
+        );
+
+        $this->assign('displayStyle', 'tableOriented');
+        // here the multi custom data listing code will go
+        $multiRecordFieldListing = TRUE;
+        $page = new CRM_Profile_Page_MultipleRecordFieldsListing();
+        $page->set('contactId', $this->_contactId);
+        $page->set('customGroupId', $this->_groupId);
+        $page->set('action', CRM_Core_Action::BROWSE);
+        $page->set('multiRecordFieldListing', $multiRecordFieldListing);
+        $page->set('pageViewType', 'customDataView');
+        $page->set('contactType', $ctype);
+        $page->run();
+      }
+      else {
+        $recId = NULL;
+        if ($this->_multiRecordDisplay == 'single') {
+          $recId = $this->_recId;
+          $this->assign('multiRecordDisplay', $this->_multiRecordDisplay);
+          $this->assign('skipTitle', 1);
+        }
+        CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, $recId);
+      }
     }
     else {
 
@@ -138,5 +174,4 @@ class CRM_Contact_Page_View_CustomData extends CRM_Core_Page {
     }
     return parent::run();
   }
-}
-
+}
\ No newline at end of file