CRM-15107 - Show count instead of id in 'manage groups' table
authorColeman Watts <coleman@civicrm.org>
Wed, 13 Aug 2014 14:58:42 +0000 (15:58 +0100)
committerColeman Watts <coleman@civicrm.org>
Wed, 13 Aug 2014 14:58:42 +0000 (15:58 +0100)
CRM/Contact/BAO/Group.php
CRM/Group/Page/AJAX.php
templates/CRM/Group/Form/Search.tpl

index cc484a25271404f88653ae10b3efb7264d67bc7b..411c4003df338c379c5cb31e1f69f1d1b8e266be 100644 (file)
@@ -750,8 +750,8 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group {
     if (!empty($groups)) {
       foreach ($groups as $id => $value) {
         $groupList[$id]['group_id'] = $value['id'];
+        $groupList[$id]['members'] = $value['members'];
         $groupList[$id]['group_name'] = $value['title'];
-        $groupList[$id]['class'] = implode(' ', $value['class']);
 
         // append parent names if in search mode
         if (empty($params['parent_id']) && !empty($value['parents'])) {
@@ -761,8 +761,10 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group {
             $title[] = $allGroups[$gId];
           }
           $groupList[$id]['group_name'] .= '<div class="crm-row-parent-name"><em>'.ts('Child of').'</em>: ' . implode(', ', $title) . '</div>';
-          $groupList[$id]['class'] = in_array('disabled', $value['class']) ? 'disabled' : '';
+          $value['class'] = array_diff($value['class'], array('crm-row-parent'));
         }
+        $value['class'][] = 'crm-entity';
+        $groupList[$id]['class'] = $value['id'] . ',' . implode(' ', $value['class']);
 
         $groupList[$id]['group_description'] = CRM_Utils_Array::value('description', $value);
         if (!empty($value['group_type'])) {
@@ -829,12 +831,17 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group {
     }
 
     $query = "
-        SELECT groups.*, createdBy.sort_name as created_by {$select}
+        SELECT groups.*, createdBy.sort_name as created_by, IF(groups.saved_search_id, COUNT(smart_members.id), COUNT(members.id)) as members {$select}
         FROM  civicrm_group groups
-              LEFT JOIN civicrm_contact createdBy
-                     ON createdBy.id = groups.created_id
-              {$from}
+        LEFT JOIN civicrm_group_contact members
+          ON members.group_id = groups.id AND members.status = 'Added'
+        LEFT JOIN civicrm_group_contact_cache smart_members
+          ON smart_members.group_id = groups.id
+        LEFT JOIN civicrm_contact createdBy
+          ON createdBy.id = groups.created_id
+        {$from}
         WHERE $whereClause {$where}
+        GROUP BY groups.id
         {$orderBy}
         {$limit}";
 
@@ -910,6 +917,8 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group {
 
         $values[$object->id]['visibility'] = $visibility[$values[$object->id]['visibility']];
 
+        $values[$object->id]['members'] = $object->members;
+
         if (isset($values[$object->id]['group_type'])) {
           $groupTypes = explode(CRM_Core_DAO::VALUE_SEPARATOR,
             substr($values[$object->id]['group_type'], 1, -1)
index fef31e7fe3637e5b6a8a82ba569ef76cc1aeb6bf..b34b0f3838b99067a0b643dfeb8ed1fa8490fd56 100644 (file)
@@ -84,7 +84,7 @@ class CRM_Group_Page_AJAX {
 
       $iFilteredTotal = $iTotal = $params['total'];
       $selectorElements = array(
-        'group_name', 'group_id', 'created_by', 'group_description',
+        'group_name', 'members', 'created_by', 'group_description',
         'group_type', 'visibility', 'org_info', 'links', 'class',
       );
 
index 97737872094f38c7d5b2b177b8caad3968d8e0af..d3bbee5a598c54fbfa001f9f1615edbf35516770 100644 (file)
@@ -71,7 +71,7 @@
   <thead>
     <tr>
       <th class='crm-group-name'>{ts}Name{/ts}</th>
-      <th class='crm-group-group_id'>{ts}ID{/ts}</th>
+      <th class='crm-group-members'>{ts}Members{/ts}</th>
       <th class='crm-group-created_by'>{ts}Created By{/ts}</th>
       <th class='crm-group-description'>{ts}Description{/ts}</th>
       <th class='crm-group-group_type'>{ts}Group Type{/ts}</th>
@@ -137,7 +137,7 @@ CRM.$(function($) {
         "aaSorting"  : [],
         "aoColumns"  : [
                         {sClass:'crm-group-name'},
-                        {sClass:'crm-group-group_id'},
+                        {sClass:'crm-group-members'},
                         {sClass:'crm-group-created_by'},
                         {sClass:'crm-group-description', bSortable:false},
                         {sClass:'crm-group-group_type'},
@@ -171,14 +171,19 @@ CRM.$(function($) {
                         }
                     },
         "fnRowCallback": function(nRow, aData, iDisplayIndex, iDisplayIndexFull) {
-          var id = $('td:eq(1)', nRow).text();
-          $(nRow).addClass('crm-entity').attr('data-entity', 'group').attr('data-id', id);
+          var id = $('td:last', nRow).text().split(',')[0];
+          var cl = $('td:last', nRow).text().split(',')[1];
+          $(nRow).addClass(cl).attr({id: 'row_' + id, 'data-id': id, 'data-entity': 'group'});
           $('td:eq(0)', nRow).wrapInner('<span class="crm-editable crmf-name" />');
           $('td:eq(3)', nRow).wrapInner('<span class="crm-editable crmf-description" data-type="textarea" />');
+          if (parentsOnly) {
+            if ($(nRow).hasClass('crm-group-parent')) {
+              $(nRow).find('td:first').prepend('{/literal}<span class="collapsed show-children" title="{ts}show child groups{/ts}"/></span>{literal}');
+            }
+          }
           return nRow;
         },
         "fnDrawCallback": function() {
-          setSelectorClass( parentsOnly, showOrgInfo );
           $('.crm-editable').crmEditable();
         },
         "fnServerData": function ( sSource, aoData, fnCallback ) {
@@ -230,20 +235,6 @@ CRM.$(function($) {
     });
   }
 
-  function setSelectorClass( parentsOnly, showOrgInfo ) {
-    var $context = $('#crm-main-content-wrapper');
-    $('table.crm-group-selector tr', $context).each( function( ) {
-      var className = $(this).find('td:last-child').text();
-      $(this).addClass( className );
-      var rowID = $(this).find('td:nth-child(2)').text();
-      $(this).prop( 'id', 'row_' + rowID );
-      if (parentsOnly) {
-        if ( $(this).hasClass('crm-group-parent') ) {
-          $(this).find('td:first').prepend('{/literal}<span class="collapsed show-children" title="{ts}show child groups{/ts}"/></span>{literal}');
-        }
-      }
-    });
-  }
   // show hide children
   var $context = $('#crm-main-content-wrapper');
   $('table.crm-group-selector', $context).on( 'click', 'span.show-children', function(){
@@ -292,14 +283,14 @@ CRM.$(function($) {
           "success": function(response){
             var appendHTML = '';
             $.each( response, function( i, val ) {
-              appendHTML += '<tr id="row_'+ val.group_id +'_'+parent_id+'" data-entity="group" data-id="'+ val.group_id +'" class="crm-entity parent_is_' + parent_id + ' crm-row-child ' + val.class + '">';
+              appendHTML += '<tr id="row_'+ val.group_id +'_'+parent_id+'" data-entity="group" data-id="'+ val.group_id +'" class="parent_is_' + parent_id + ' crm-row-child ' + val.class.split(',')[1] + '">';
               if ( val.is_parent ) {
                 appendHTML += '<td class="crm-group-name ' + levelClass + '">' + '{/literal}<span class="collapsed show-children" title="{ts}show child groups{/ts}"/></span>{literal}<span class="crm-editable crmf-name">' + val.group_name + '</span></td>';
               }
               else {
                 appendHTML += '<td class="crm-group-name ' + levelClass + '"><span class="crm-no-children"></span><span class="crm-editable crmf-name">' + val.group_name + '</span></td>';
               }
-              appendHTML += "<td>" + val.group_id + "</td>";
+              appendHTML += "<td>" + val.members + "</td>";
               appendHTML += "<td>" + val.created_by + "</td>";
               appendHTML += '<td><span class="crm-editable crmf-description" data-type="textarea">' + (val.group_description || '') + "</span></td>";
               appendHTML += "<td>" + val.group_type + "</td>";