CRM-13992 : handling multi-custom data listing, edit, add, view actions. reused profi...
authorPratik Joshi <pratik.joshi@webaccess.co.in>
Sat, 22 Feb 2014 15:36:46 +0000 (21:06 +0530)
committerPratik Joshi <pratik.joshi@webaccess.co.in>
Thu, 27 Feb 2014 06:15:04 +0000 (11:45 +0530)
CRM/Contact/Form/CustomData.php
CRM/Contact/Page/View/CustomData.php
CRM/Core/BAO/CustomField.php
CRM/Core/BAO/CustomGroup.php
CRM/Custom/Form/Field.php
CRM/Profile/Page/MultipleRecordFieldsListing.php
templates/CRM/Contact/Form/CustomData.tpl
templates/CRM/Contact/Page/View/CustomData.tpl
templates/CRM/Custom/Form/CustomData.tpl
templates/CRM/Custom/Page/CustomDataView.tpl
templates/CRM/Profile/Page/MultipleRecordFieldsListing.tpl

index f7931ef13e3a01088f9af10dd0fa7226a923c365..d8e9b071ec6e76b3968dbbcbf6fa2cbec91d2b56 100644 (file)
@@ -101,6 +101,7 @@ class CRM_Contact_Form_CustomData extends CRM_Core_Form {
    */
   public $_groupID;
 
+  public $_multiRecordDisplay;
   /**
    * pre processing work done here.
    *
@@ -115,13 +116,22 @@ class CRM_Contact_Form_CustomData extends CRM_Core_Form {
    */
   function preProcess() {
     $this->_cdType = CRM_Utils_Array::value('type', $_GET);
-
     $this->assign('cdType', FALSE);
-    if ($this->_cdType) {
-      $this->assign('cdType', TRUE);
-      return CRM_Custom_Form_CustomData::preProcess($this);
+    $this->_multiRecordDisplay = CRM_Utils_Request::retrieve('multiRecordDisplay', 'String', $this);
+    if ($this->_cdType || $this->_multiRecordDisplay == 'single') {
+      if ($this->_cdType) {
+        $this->assign('cdType', TRUE);
+      }
+      // NOTE : group id is not stored in session from within CRM_Custom_Form_CustomData::preProcess func
+      // this is due to some condition inside it which restricts it from saving in session
+      // so doing this for multi record edit action
+      CRM_Custom_Form_CustomData::preProcess($this);
+      if ($this->_multiRecordDisplay) {
+        $this->_groupID = CRM_Utils_Request::retrieve('groupID', 'Positive', $this);
+        $this->_tableID = $this->_entityId;
+      }
+      return;
     }
-
     $this->_groupID = CRM_Utils_Request::retrieve('groupID', 'Positive', $this, TRUE);
     $this->_tableID = CRM_Utils_Request::retrieve('tableId', 'Positive', $this, TRUE);
 
@@ -149,7 +159,29 @@ class CRM_Contact_Form_CustomData extends CRM_Core_Form {
    * @access public
    */
   public function buildQuickForm() {
-    if ($this->_cdType) {
+    if ($this->_cdType || $this->_multiRecordDisplay == 'single') {
+      // buttons display for multi-valued fields to perform independednt actions
+      if ($this->_multiRecordDisplay) {
+        $isMultiple = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup',
+          $this->_groupID,
+          'is_multiple'
+        );
+        if ($isMultiple) {
+          $this->assign('multiRecordDisplay', $this->_multiRecordDisplay);
+          $this->addButtons(array(
+              array(
+                'type' => 'upload',
+                'name' => ts('Save'),
+                'isDefault' => TRUE,
+              ),
+              array(
+                'type' => 'cancel',
+                'name' => ts('Cancel'),
+              ),
+            )
+          );
+        }
+      }
       return CRM_Custom_Form_CustomData::buildQuickForm($this);
     }
 
@@ -181,7 +213,7 @@ class CRM_Contact_Form_CustomData extends CRM_Core_Form {
    * @return array the default array reference
    */
   function setDefaultValues() {
-    if ($this->_cdType) {
+    if ($this->_cdType || $this->_multiRecordDisplay == 'single') {
       $customDefaultValue = CRM_Custom_Form_CustomData::setDefaultValues($this);
       return $customDefaultValue;
     }
@@ -230,5 +262,4 @@ class CRM_Contact_Form_CustomData extends CRM_Core_Form {
     // reset the group contact cache for this group
     CRM_Contact_BAO_GroupContactCache::remove();
   }
-}
-
+}
\ No newline at end of file
index 4c77c3f452c4f67f3eba92d5afc9b13770f30e2d..6b0bdc7a58373046a878692cee687a07f43b4036 100644 (file)
@@ -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);
   }
 
   /**
@@ -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
index 5fac6b6f60ceb9ced2a228ee3033c6be9b40fdb8..49334b14f247795e79a4aeb901d84035c22924a5 100644 (file)
@@ -273,6 +273,7 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
     $customField->copyValues($params);
     $customField->is_required = CRM_Utils_Array::value('is_required', $params, FALSE);
     $customField->is_searchable = CRM_Utils_Array::value('is_searchable', $params, FALSE);
+    $customField->in_selector = CRM_Utils_Array::value('in_selector', $params, FALSE);
     $customField->is_search_range = CRM_Utils_Array::value('is_search_range', $params, FALSE);
     $customField->is_active = CRM_Utils_Array::value('is_active', $params, FALSE);
     $customField->is_view = CRM_Utils_Array::value('is_view', $params, FALSE);
index 90654c569fe55e662a2b2b4e73f83ee5958540b4..ccb7324c7dd9841bb79544c69061f2d03874c281 100644 (file)
@@ -355,6 +355,7 @@ class CRM_Core_BAO_CustomGroup extends CRM_Core_DAO_CustomGroup {
         'date_format',
         'time_format',
         'option_group_id',
+        'in_selector'
       ),
       'civicrm_custom_group' =>
       array(
@@ -836,7 +837,7 @@ ORDER BY civicrm_custom_group.weight,
    * @static
    *
    */
-  public static function &getGroupDetail($groupId = NULL, $searchable = NULL, &$extends = NULL) {
+  public static function &getGroupDetail($groupId = NULL, $searchable = NULL, &$extends = NULL, $inSelector = NULL) {
     // create a new tree
     $groupTree = array();
     $select = $from = $where = $orderBy = '';
@@ -868,6 +869,7 @@ ORDER BY civicrm_custom_group.weight,
         'column_name',
         'is_view',
         'option_group_id',
+        'in_selector',
       ),
       'civicrm_custom_group' =>
       array(
@@ -881,6 +883,7 @@ ORDER BY civicrm_custom_group.weight,
         'extends',
         'extends_entity_column_value',
         'table_name',
+        'is_multiple',
       ),
     );
 
@@ -908,6 +911,10 @@ ORDER BY civicrm_custom_group.weight,
       $where .= " AND civicrm_custom_field.is_searchable = 1";
     }
 
+    if ($inSelector) {
+      $where .= " AND civicrm_custom_field.in_selector = 1 AND civicrm_custom_group.is_multiple = 1 ";
+    }
+
     if ($extends) {
       $clause = array();
       foreach ($extends as $e) {
@@ -979,8 +986,8 @@ ORDER BY civicrm_custom_group.weight,
     // for Group's
     $customGroupDAO = new CRM_Core_DAO_CustomGroup();
 
-    // get only 'Tab' groups
-    $customGroupDAO->whereAdd("style = 'Tab'");
+    // get 'Tab' and 'Tab with table' groups
+    $customGroupDAO->whereAdd("style IN ('Tab', 'Tab with table')");
     $customGroupDAO->whereAdd("is_active = 1");
 
     // add whereAdd for entity type
@@ -1770,9 +1777,8 @@ SELECT IF( EXISTS(SELECT name FROM civicrm_contact_type WHERE name like %1), 1,
    *  @param array   $groupTree associated array
    *  @param boolean $returnCount true if customValue count needs to be returned
    */
-  static function buildCustomDataView(&$form, &$groupTree, $returnCount = FALSE, $gID = NULL, $prefix = NULL) {
+  static function buildCustomDataView(&$form, &$groupTree, $returnCount = FALSE, $gID = NULL, $prefix = NULL, $customValueId = NULL) {
     $details = array();
-
     foreach ($groupTree as $key => $group) {
       if ($key === 'info') {
         continue;
@@ -1782,6 +1788,9 @@ SELECT IF( EXISTS(SELECT name FROM civicrm_contact_type WHERE name like %1), 1,
         $groupID = $group['id'];
         if (!empty($properties['customValue'])) {
           foreach ($properties['customValue'] as $values) {
+            if (!empty($customValueId) && $customValueId != $values['id']) {
+              continue;
+            }
             $details[$groupID][$values['id']]['title'] = CRM_Utils_Array::value('title', $group);
             $details[$groupID][$values['id']]['name'] = CRM_Utils_Array::value('name', $group);
             $details[$groupID][$values['id']]['help_pre'] = CRM_Utils_Array::value('help_pre', $group);
index 05988af601eb41e799896a01d00cc00bc75c6c2d..f919fded24566141d747f6007433ce6c35acab0c 100644 (file)
@@ -261,7 +261,8 @@ class CRM_Custom_Form_Field extends CRM_Core_Form {
     if (isset($dontShowLink)) {
       $this->assign('dontShowLink', $dontShowLink);
     }
-    if (CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_gid, 'is_multiple', 'id')) {
+    if ($this->_action & CRM_Core_Action::ADD &&
+      CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_gid, 'is_multiple', 'id')) {
       $defaults['in_selector'] = 1;
     }
 
@@ -990,7 +991,6 @@ SELECT id
     if ($this->_action & CRM_Core_Action::UPDATE) {
       $params['id'] = $this->_id;
     }
-
     $customField = CRM_Core_BAO_CustomField::create($params);
     $this->_id = $customField->id;
 
index fddc3c69d89b16367212775350655dba33ee9748..03b8b927c94ffe66200b3b2d329b4febe628b2f9 100644 (file)
@@ -49,6 +49,10 @@ class CRM_Profile_Page_MultipleRecordFieldsListing extends CRM_Core_Page_Basic {
   protected $_contactId = NULL;
 
   protected $_customGroupTitle = NULL;
+
+  protected $_pageViewType = NULL;
+
+  protected $_contactType = NULL;
   /**
    * Get BAO Name
    *
@@ -64,7 +68,7 @@ class CRM_Profile_Page_MultipleRecordFieldsListing extends CRM_Core_Page_Basic {
    * @return array (reference) of action links
    */
   function &links() {
-    if (!(self::$_links)) {
+    if (!(self::$_links[$this->_pageViewType])) {
       // helper variable for nicer formatting
       $links = array();
 
@@ -74,28 +78,47 @@ class CRM_Profile_Page_MultipleRecordFieldsListing extends CRM_Core_Page_Basic {
 
       $links[CRM_Core_Action::VIEW] = array(
         'name' => ts('View'),
-        'url' => 'civicrm/profile/view',
-        'qs' => "reset=1&id=%%id%%&recordId=%%recordId%%&gid=%%gid%%&multiRecord={$view}&snippet=1&context=multiProfileDialog&onPopupClose=%%onPopupClose%%",
         'title' => ts('View %1', array( 1 => $this->_customGroupTitle . ' record')),
       );
 
+      if ($this->_pageViewType == 'profileDataView') {
+        $links[CRM_Core_Action::VIEW]['url'] = 'civicrm/profile/view';
+        $links[CRM_Core_Action::VIEW]['qs'] = "reset=1&id=%%id%%&recordId=%%recordId%%&gid=%%gid%%&multiRecord={$view}&snippet=1&context=multiProfileDialog&onPopupClose=%%onPopupClose%%";
+      }
+      elseif ($this->_pageViewType == 'customDataView') {
+        // custom data specific view links
+        $links[CRM_Core_Action::VIEW]['url'] = 'civicrm/contact/view/cd';
+        $links[CRM_Core_Action::VIEW]['qs'] = 'reset=1&snippet=1&gid=%%gid%%&cid=%%cid%%&recId=%%recId%%&multiRecordDisplay=single';
+      }
+
       $links[CRM_Core_Action::UPDATE] = array(
         'name' => ts('Edit'),
-        'url' => 'civicrm/profile/edit',
-        'qs' => "reset=1&id=%%id%%&recordId=%%recordId%%&gid=%%gid%%&multiRecord={$update}&snippet=1&context=multiProfileDialog&onPopupClose=%%onPopupClose%%",
         'title' => ts('Edit %1', array( 1 => $this->_customGroupTitle . ' record')),
       );
 
+      if ($this->_pageViewType == 'profileDataView') {
+        $links[CRM_Core_Action::UPDATE]['url'] = 'civicrm/profile/edit';
+        $links[CRM_Core_Action::UPDATE]['qs'] = "reset=1&id=%%id%%&recordId=%%recordId%%&gid=%%gid%%&multiRecord={$update}&snippet=1&context=multiProfileDialog&onPopupClose=%%onPopupClose%%";
+      }
+      elseif ($this->_pageViewType == 'customDataView') {
+        // custom data specific update links
+        $links[CRM_Core_Action::UPDATE]['url'] = 'civicrm/contact/view/cd/edit';
+        $links[CRM_Core_Action::UPDATE]['qs'] = 'reset=1&snippet=1&type=%%type%%&groupID=%%groupID%%&entityID=%%entityID%%&cgcount=%%cgcount%%&multiRecordDisplay=single';
+      }
+
       $links[CRM_Core_Action::DELETE] = array(
         'name' => ts('Delete'),
-        'url' => 'civicrm/profile/edit',
-        'qs' => "reset=1&id=%%id%%&recordId=%%recordId%%&gid=%%gid%%&multiRecord={$delete}&snippet=1&context=multiProfileDialog&onPopupClose=%%onPopupClose%%",
         'title' => ts('Delete %1', array( 1 => $this->_customGroupTitle . ' record')),
       );
 
-      self::$_links = $links;
+      if ($this->_pageViewType == 'profileDataView') {
+        $links[CRM_Core_Action::DELETE]['url'] = 'civicrm/profile/edit';
+        $links[CRM_Core_Action::DELETE]['qs'] = "reset=1&id=%%id%%&recordId=%%recordId%%&gid=%%gid%%&multiRecord={$delete}&snippet=1&context=multiProfileDialog&onPopupClose=%%onPopupClose%%";
+      }
+
+      self::$_links[$this->_pageViewType] = $links;
     }
-    return self::$_links;
+    return self::$_links[$this->_pageViewType];
   }
 
   /**
@@ -120,13 +143,11 @@ class CRM_Profile_Page_MultipleRecordFieldsListing extends CRM_Core_Page_Basic {
     if (!is_array($profileId) && is_numeric($profileId)) {
       $this->_profileId = $profileId;
     }
-    //record id
-    $recid = CRM_Utils_Request::retrieve('recid', 'Positive', $this, FALSE, 0);
-    //custom group id
-    $groupId = CRM_Utils_Request::retrieve('groupId', 'Positive', $this, FALSE, 0);
 
     $this->_contactId = CRM_Utils_Request::retrieve('contactId', 'Positive', $this, FALSE);
-
+    $this->_pageViewType = CRM_Utils_Request::retrieve('pageViewType', 'Positive', $this, FALSE, 'profileDataView');
+    $this->_customGroupId = CRM_Utils_Request::retrieve('customGroupId', 'Positive', $this, FALSE, 0);
+    $this->_contactType = CRM_Utils_Request::retrieve('contactType', 'String', $this, FALSE);
     if ($action & CRM_Core_Action::BROWSE) {
       //browse
       $this->browse();
@@ -143,7 +164,7 @@ class CRM_Profile_Page_MultipleRecordFieldsListing extends CRM_Core_Page_Basic {
    * @access public
    */
   function browse() {
-    if ($this->_profileId) {
+    if ($this->_pageViewType == 'profileDataView' && $this->_profileId) {
       $fields = CRM_Core_BAO_UFGroup::getFields($this->_profileId, FALSE, NULL,
         NULL, NULL,
         FALSE, NULL,
@@ -169,12 +190,31 @@ class CRM_Profile_Page_MultipleRecordFieldsListing extends CRM_Core_Page_Basic {
         $fieldIDs = array_keys($multiRecordFieldsWithSummaryListing);
       }
     }
-
+    elseif ($this->_pageViewType == 'customDataView') {
+      // require custom group id for _pageViewType of customDataView
+      $customGroupId = $this->_customGroupId;
+      $reached = CRM_Core_BAO_CustomGroup::hasReachedMaxLimit($customGroupId, $this->_contactId);
+      if (!$reached) {
+        $this->assign('contactId', $this->_contactId);
+        $this->assign('customGroupId', $customGroupId);
+        $this->assign('ctype', $this->_contactType);
+      }
+      $this->assign('reachedMax', $reached);
+      // custom group info : this consists of the field title of group fields
+      $groupDetail = CRM_Core_BAO_CustomGroup::getGroupDetail($customGroupId, NULL, CRM_Core_DAO::$_nullObject, TRUE);
+      // field ids of fields in_selector for the custom group id provided
+      $fieldIDs = array_keys($groupDetail[$customGroupId]['fields']);
+      // field labels for headers
+      $fieldLabels = $groupDetail[$customGroupId]['fields'];
+
+      // from the above customGroupInfo we can get $this->_customGroupTitle
+      $this->_customGroupTitle = $groupDetail[$customGroupId]['title'];
+    }
     if ($fieldIDs && !empty($fieldIDs) && $this->_contactId) {
       $options = array( );
       $returnProperities = array('html_type', 'data_type', 'date_format', 'time_format');
       foreach ($fieldIDs as $key => $fieldID) {
-        $fieldIDs[$key] = CRM_Core_BAO_CustomField::getKeyID($fieldID);
+        $fieldIDs[$key] = !is_numeric($fieldID) ? CRM_Core_BAO_CustomField::getKeyID($fieldID) : $fieldID;
         $param = array('id' => $fieldIDs[$key]);
         $returnValues = array( );
         CRM_Core_DAO::commonRetrieve('CRM_Core_DAO_CustomField', $param, $returnValues, $returnProperities);
@@ -194,68 +234,90 @@ class CRM_Profile_Page_MultipleRecordFieldsListing extends CRM_Core_Page_Basic {
         $options[$fieldIDs[$key]]['attributes']['time_format'] = CRM_Utils_Array::value('time_format', $returnValues);
       }
 
+      // commonly used for both views i.e profile listing view (profileDataView) and custom data listing view (customDataView)
       $result = CRM_Core_BAO_CustomValueTable::getEntityValues($this->_contactId, NULL, $fieldIDs, TRUE);
 
-     if (!empty($fieldIDs)) {
-       //get the group info of multi rec fields in listing view
-       $fieldInput = $fieldIDs;
-       $fieldIdInput = $fieldIDs[0];
-     } else {
-       //if no listing fields exist, take the group title for display
-       $nonListingFieldIds = array_keys($multiRecordFields);
-       $singleField = CRM_Core_BAO_CustomField::getKeyID($nonListingFieldIds[0]);
-       $fieldIdInput = $singleField;
-       $singleField = array($singleField);
-       $fieldInput  = $singleField;
-     }
-     $customGroupInfo = CRM_Core_BAO_CustomGroup::getGroupTitles($fieldInput);
-     $this->_customGroupTitle = $customGroupInfo[$fieldIdInput]['groupTitle'];
-
-     if ($result && !empty($result)) {
-       $links = self::links();
-       $pageCheckSum = $this->get('pageCheckSum');
-       if ($pageCheckSum) {
-         foreach ($links as $key => $link) {
-           $links[$key] = $link['qs'] . "&cs=%%cs%%";
-         }
-       }
-       $linkAction = array_sum(array_keys($this->links()));
-
-       foreach ($result as $recId => &$value) {
-         foreach ($value as $fieldId => &$val) {
-           if (is_numeric($fieldId)) {
-             $customValue = &$val;
-             $customValue = CRM_Core_BAO_CustomField::getDisplayValue($customValue, $fieldId, $options);
-             if (!$customValue) {
-               $customValue = "";
-             }
-             $actionParams = array('recordId' => $recId, 'gid' => $this->_profileId,
-               'id' => $this->_contactId, 'onPopupClose' => $this->_onPopupClose);
-             if ($pageCheckSum) {
-               $actionParams['cs'] = $pageCheckSum;
-             }
-             $value['action'] = CRM_Core_Action::formLink(
-               $links,
-               $linkAction,
-               $actionParams,
-               ts('more'),
-               FALSE,
-               'profile.multiValue.row',
-               'customValue',
-               $fieldId // not ideal, but the one thing not sent in $actionParams
-             );
-           }
-         }
-       }
-     }
+      if ($this->_pageViewType == 'profileDataView') {
+        if (!empty($fieldIDs)) {
+          //get the group info of multi rec fields in listing view
+          $fieldInput = $fieldIDs;
+          $fieldIdInput = $fieldIDs[0];
+        }
+        else {
+          //if no listing fields exist, take the group title for display
+          $nonListingFieldIds = array_keys($multiRecordFields);
+          $singleField = CRM_Core_BAO_CustomField::getKeyID($nonListingFieldIds[0]);
+          $fieldIdInput = $singleField;
+          $singleField = array($singleField);
+          $fieldInput  = $singleField;
+        }
+        $customGroupInfo = CRM_Core_BAO_CustomGroup::getGroupTitles($fieldInput);
+        $this->_customGroupTitle = $customGroupInfo[$fieldIdInput]['groupTitle'];
+      }
+      // $cgcount is defined before 'if' condition as enitiy may have no record
+      // and $cgcount is used to build new record url
+      $cgcount = 1;
+      if ($result && !empty($result)) {
+        $links = self::links($this->_pageViewType);
+        if ($this->_pageViewType == 'profileDataView') {
+          $pageCheckSum = $this->get('pageCheckSum');
+          if ($pageCheckSum) {
+            foreach ($links as $key => $link) {
+              $links[$key] = $link['qs'] . "&cs=%%cs%%";
+            }
+          }
+        }
+        $linkAction = array_sum(array_keys($this->links()));
+        foreach ($result as $recId => &$value) {
+          foreach ($value as $fieldId => &$val) {
+            if (is_numeric($fieldId)) {
+              $customValue = &$val;
+              $customValue = CRM_Core_BAO_CustomField::getDisplayValue($customValue, $fieldId, $options);
+              if (!$customValue) {
+                $customValue = "";
+              }
+
+              $op = NULL;
+              if ($this->_pageViewType == 'profileDataView') {
+                $actionParams = array('recordId' => $recId, 'gid' => $this->_profileId,
+                  'id' => $this->_contactId, 'onPopupClose' => $this->_onPopupClose);
+                $op = 'profile.multiValue.row';
+              }
+              else {
+                // different set of url params
+                $actionParams['gid'] = $actionParams['groupID'] = $this->_customGroupId;
+                $actionParams['cid'] = $actionParams['entityID'] = $this->_contactId;
+                $actionParams['recId'] = $recId;
+                $actionParams['type'] = $this->_contactType;
+                $actionParams['cgcount'] = $cgcount;
+              }
+              if (!empty($pageCheckSum)) {
+                $actionParams['cs'] = $pageCheckSum;
+              }
+              $value['action'] = CRM_Core_Action::formLink(
+                $links,
+                $linkAction,
+                $actionParams,
+                ts('more'),
+                FALSE,
+                $op,
+                'customValue',
+                $fieldId // not ideal, but the one thing not sent in $actionParams
+              );
+            }
+          }
+          $cgcount++;
+        }
+      }
     }
 
     $headers = array(  );
     if (!empty($fieldIDs)) {
       foreach ($fieldIDs as $fieldID) {
-        $headers[$fieldID] = $customGroupInfo[$fieldID]['fieldLabel'];
+        $headers[$fieldID] = ($this->_pageViewType == 'profileDataView') ? $customGroupInfo[$fieldID]['fieldLabel'] : $fieldLabels[$fieldID]['label'];
       }
     }
+    $this->assign('cgcount', $cgcount);
     $this->assign('customGroupTitle', $this->_customGroupTitle);
     $this->assign('headers', $headers);
     $this->assign('records', $result);
index b044aedfde1cb1d50e720e11250016edc30094e1..b011b2bc0f3dc58a4940e6c02520ed30fa2d2654 100644 (file)
 {* this template is used for building tabbed custom data *}
 {if $cdType }
     {include file="CRM/Custom/Form/CustomData.tpl"}
+{if $multiRecordDisplay eq 'single'}
+    <div class="html-adjust">{$form.buttons.html}</div>
+{/if}
 {else}
+{debug}
     <div id="customData"></div>
     <div class="html-adjust">{$form.buttons.html}</div>
 
index 11dc71448d4ccedb12c17701b080c457c6f5d1ed..b5f53d721111996eb1c0f96fecc3d655e46e3b2b 100644 (file)
@@ -27,7 +27,9 @@
 {if $action eq 0 or $action eq 1 or $action eq 2 or $recordActivity}
   {include file="CRM/Contact/Form/CustomData.tpl" mainEdit=$mainEditForm}
 {/if}
-
+{if $displayStyle eq 'tableOriented'}
+   {include file='CRM/Profile/Page/MultipleRecordFieldsListing.tpl' showListing=1 dontShowTitle=1 pageViewType='customDataView'}
+{else}
 {strip}
   {if $action eq 16 or $action eq 4} {* Browse or View actions *}
     <div class="form-item">
@@ -52,3 +54,4 @@
     on_load_init_blocks(showBlocks, hideBlocks);
   </script>
 {/if}
+{/if}
\ No newline at end of file
index adffd911b5e8357f9fffa049284ab2c65a97805d..a9e3d7178e2c1dd0428484cb0d509c15b69ca106 100644 (file)
   {/if}
 {else}
   {foreach from=$groupTree item=cd_edit key=group_id name=custom_sets}
-    <div id="{$cd_edit.name}" class="crm-accordion-wrapper {if $cd_edit.collapse_display and !$skipTitle}collapsed{/if}">
+    {if $cd_edit.is_multiple and $multiRecordDisplay eq 'single'}
+      <div id="{$cd_edit.name}">
+        {if $cd_edit.help_pre}
+          <div class="messages help">{$cd_edit.help_pre}</div>
+        {/if}
+        <table>
+          {foreach from=$cd_edit.fields item=element key=field_id}
+            {include file="CRM/Custom/Form/CustomField.tpl"}
+          {/foreach}
+        </table>
+        <div class="spacer"></div>
+        {if $cd_edit.help_post}
+          <div class="messages help">{$cd_edit.help_post}</div>
+        {/if}
+      </div>
+    {else}
+     <div id="{$cd_edit.name}" class="crm-accordion-wrapper {if $cd_edit.collapse_display and !$skipTitle}collapsed{/if}">
       {if !$skipTitle}
       <div class="crm-accordion-header">
         {$cd_edit.title}
           <div class="messages help">{$cd_edit.help_post}</div>
         {/if}
       </div>
-    </div>
-    {if $cd_edit.is_multiple and ( ( $cd_edit.max_multiple eq '' )  or ( $cd_edit.max_multiple > 0 and $cd_edit.max_multiple >= $cgCount ) ) }
+     </div>
+     {if $cd_edit.is_multiple and ( ( $cd_edit.max_multiple eq '' )  or ( $cd_edit.max_multiple > 0 and $cd_edit.max_multiple >= $cgCount ) ) }
       {if $skipTitle}
         {* We don't yet support adding new records in inline-edit forms *}
         <div class="messages help">
           <em>{ts 1=$cd_edit.title}Click "Edit Contact" to add more %1 records{/ts}</em>
         </div>
       {else}
-        <div id="add-more-link-{$cgCount}"><a href="#" onclick="CRM.buildCustomData('{$cd_edit.extends}',{if $cd_edit.subtype}'{$cd_edit.subtype}'{else}'{$cd_edit.extends_entity_column_id}'{/if}, '', {$cgCount}, {$group_id}, true ); return false;">{ts 1=$cd_edit.title}Add another %1 record{/ts}</a></div>
+        <div id="add-more-link-{$cgCount}"><a href="#" onclick="CRM.buildCustomData('{$cd_edit.extends}',{if $cd_edit.subtype}'{$cd_edit.subtype}'{else}'{$cd_edit.extends_entity_column_id}'{/if}, '', {$cgCount}, {$group_id}, true ); return false;">{ts 1=$cd_edit.title}Add another %1 record{/ts}</a></div>       
       {/if}
     {/if}
+    {/if}
     <div id="custom_group_{$group_id}_{$cgCount}"></div>
   {/foreach}
   <script type="text/javascript">
index 24a2afac7dd0a99c8c23bc3377c3960390d50c49..0037143ae17cbda99e6a8ef652c582ec4edce6a7 100644 (file)
@@ -29,7 +29,7 @@
   {foreach from=$customValues item=cd_edit key=cvID}
     <table class="no-border">
       {assign var='index' value=$groupId|cat:"_$cvID"}
-      {if ($editOwnCustomData and $showEdit) or ($showEdit and $editCustomData and $groupId)}
+      {if $multiRecordDisplay neq 'single' and (($editOwnCustomData and $showEdit) or ($showEdit and $editCustomData and $groupId))}
         <tr>
           <td>
             <a
         </tr>
       {/if}
       {assign var="showEdit" value=0}
-      <tr id="statusmessg_{$index}" class="hiddenElement">
-        <td><span class="success-status"></span></td>
-      </tr>
+      {if $multiRecordDisplay neq 'single'}
+        <tr id="statusmessg_{$index}" class="hiddenElement">
+          <td><span class="success-status"></span></td>
+        </tr>
+      {/if}
       <tr>
         <td id="{$cd_edit.name}_{$index}" class="section-shown form-item">
-          <div class="crm-accordion-wrapper {if $cd_edit.collapse_display eq 0 or $skipTitle} {else}collapsed{/if}">
+          <div {if $multiRecordDisplay neq 'single'} class="crm-accordion-wrapper {if $cd_edit.collapse_display eq 0 or $skipTitle} {else}collapsed{/if}"{/if}>
             {if !$skipTitle}
               <div class="crm-accordion-header">
                 {$cd_edit.title}
               </div>
             {/if}
-            <div class="crm-accordion-body">
-              {if $groupId and $cvID and $editCustomData}
+            <div {if $multiRecordDisplay neq 'single'} class="crm-accordion-body" {/if}>
+              {if $groupId and $cvID and $editCustomData and $multiRecordDisplay neq 'single'}
                 <div class="crm-submit-buttons">
                   <a href="#"
                      onclick="showDelete( {$cvID}, '{$cd_edit.name}_{$index}', {$customGroupId}, {$contactId} ); return false;"
                 </div>
               {/if}
               {foreach from=$cd_edit.fields item=element key=field_id}
-                <table class="crm-info-panel">
+                <table class="crm-info-panel crm-section">
                   <tr>
                     {if $element.options_per_line != 0}
                       <td class="label">{$element.field_title}</td>
-                      <td class="html-adjust">
+                      <td class="html-adjust content">
                         {* sort by fails for option per line. Added a variable to iterate through the element array*}
                         {foreach from=$element.field_value item=val}
                           {$val}
                       <td class="label">{$element.field_title}</td>
                       {if $element.field_type == 'File'}
                         {if $element.field_value.displayURL}
-                          <td class="html-adjust">
+                          <td class="html-adjust content">
                             <a href="{$element.field_value.displayURL}" class='crm-image-popup'>
                               <img src="{$element.field_value.displayURL}" height="100" width="100">
                             </a>
                           </td>
                         {else}
-                          <td class="html-adjust">
+                          <td class="html-adjust content">
                             <a href="{$element.field_value.fileURL}">{$element.field_value.fileName}</a>
                           </td>
                         {/if}
                       {else}
                         {if $element.field_data_type == 'Money'}
                           {if $element.field_type == 'Text'}
-                            <td class="html-adjust">{$element.field_value|crmMoney}</td>
+                            <td class="html-adjust content">{$element.field_value|crmMoney}</td>
                           {else}
-                            <td class="html-adjust">{$element.field_value}</td>
+                            <td class="html-adjust content">{$element.field_value}</td>
                           {/if}
                         {else}
-                          <td class="html-adjust">
+                          <td class="html-adjust content">
                             {if $element.contact_ref_id}
                             <a href='{crmURL p="civicrm/contact/view" q="reset=1&cid=`$element.contact_ref_id`"}'>
                               {/if}
index ec210045b5004c5b16de9b25c9adb031f7cb2bc8..e79714ad0aa586f39fe909263a9e05b032a4eb3d 100644 (file)
  +--------------------------------------------------------------------+
 *}
 {if $showListing}
-  <h1>{ts}{$customGroupTitle}{/ts}</h1>
+  {if $dontShowTitle neq 1}<h1>{ts}{$customGroupTitle}{/ts}</h1>{/if}
+  {if $pageViewType eq 'customDataView'}
+     {assign var='dialogId' value='custom-record-dialog'}
+  {else}
+     {assign var='dialogId' value='profile-dialog'}
+  {/if}
   {if $records and $headers}
     {include file="CRM/common/jsortable.tpl"}
     <div id="browseValues">
         {/strip}
       </div>
     </div>
-    <div id='profile-dialog' class="hiddenElement"></div>
+    <div id='{$dialogId}' class="hiddenElement"></div>
   {elseif !$records}
     <div class="messages status no-popup">
       <div class="icon inform-icon"></div>
       &nbsp;
       {ts 1=$customGroupTitle}No records of type '%1' found.{/ts}
     </div>
-    <div id='profile-dialog' class="hiddenElement"></div>
+    <div id='{$dialogId}' class="hiddenElement"></div>
   {/if}
 
   {if !$reachedMax}
-    <a accesskey="N" href="{crmURL p='civicrm/profile/edit' q="reset=1&id=`$contactId`&multiRecord=add&gid=`$gid`&snippet=1&context=multiProfileDialog&onPopupClose=`$onPopupClose`"}"
+    {if $pageViewType eq 'customDataView'}
+      <a accesskey="N" href="{crmURL p='civicrm/contact/view/cd/edit' q="reset=1&snippet=1&type=$ctype&groupID=$customGroupId&entityID=$contactId&cgcount=$cgcount&multiRecordDisplay=single"}" 
+       class="button action-item"><span><div class="icon add-icon"></div>{ts 1=$customGroupTitle}Add %1 Record{/ts}</span></a>
+    {else}
+      <a accesskey="N" href="{crmURL p='civicrm/profile/edit' q="reset=1&id=`$contactId`&multiRecord=add&gid=`$gid`&snippet=1&context=multiProfileDialog&onPopupClose=`$onPopupClose`"}"
        class="button action-item"><span><div class="icon add-icon"></div>{ts}Add New Record{/ts}</span></a>
+    {/if}
   {/if}
 {/if}
 {literal}
   <script type='text/javascript'>
     cj(function () {
+      var dialogId = '{/literal}{$dialogId}{literal}';
+      var pageViewType = '{/literal}{$pageViewType}{literal}';
       // NOTE: Triggers two events, "profile-dialog:FOO:open" and "profile-dialog:FOO:close",
       // where "FOO" is the internal name of a profile form
       function formDialog(dialogName, dataURL, dialogTitle) {
         cj.ajax({
           url: dataURL,
           success: function (content) {
-            cj('#profile-dialog').show().html(content).dialog({
+            cj('#' + dialogId).show().html(content).dialog({
               title: dialogTitle,
               modal: true,
               width: 680,
                 background: "black"
               },
               open: function(event, ui) {
-                cj('#profile-dialog').trigger({
+                cj('#' + dialogId).trigger({
                   type: "crmFormLoad",
                   profileName: dialogName
                 });
               },
               close: function (event, ui) {
-                cj('#profile-dialog').trigger({
+                cj('#' + dialogId).trigger({
                   type: "crmFormClose",
                   profileName: dialogName
                 });
-                cj('#profile-dialog').html('');
+                cj('#' + dialogId).html('');
               }
             });
             cj('.action-link').hide();
-            cj('#profile-dialog #crm-profile-block .edit-value label').css('display', 'inline');
+            if (pageViewType != 'customDataView') {
+              cj('#profile-dialog #crm-profile-block .edit-value label').css('display', 'inline');
+            }
           }
         });
       }
         }
       });
 
-      cj(".crm-profile-name-" + profileName + " .action-item").click(function () {
+      if (pageViewType == 'customDataView') {
+        var actionItemHeirarchy = '.action-item';
+        profileName = 'customRecordView';
+      }
+      else {
+        var actionItemHeirarchy = '.crm-profile-name-' + profileName + ' .action-item';
+      }
+
+      cj(actionItemHeirarchy).click(function () {
         dataURL = cj(this).attr('jshref');
         dialogTitle = cj(this).attr('title');
         formDialog(profileName, dataURL, dialogTitle);