Index: og_views.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/og/og_views.inc,v
retrieving revision 1.12.2.27
diff -u -p -r1.12.2.27 og_views.inc
--- og_views.inc	9 Aug 2007 23:47:23 -0000	1.12.2.27
+++ og_views.inc	21 Nov 2007 03:42:14 -0000
@@ -24,38 +24,38 @@ function og_views_tables() {
       ),
       'fields' => array(
         'description' => array(
-          'name' => t('Og: Group: Description'),
+          'name' => t('OG: Group: Description'),
         ),
         'count' => array(
-          'name' => t('Og: Group: Subscriber Count'),
+          'name' => t('OG: Group: Subscriber Count'),
           'handler' => 'og_handler_field_count',
           'sortable' => FALSE,
           'notafield' => TRUE,
         ),
         'selective' => array(
-          'name' => t('Og: Group: Selective'),
+          'name' => t('OG: Group: Selective'),
         ),
         'subscribe' => array(
-          'name' => t('Og: Group: Subscribe Link'),
+          'name' => t('OG: Group: Subscribe Link'),
           'handler' => 'og_handler_field_subscribe',
           'addlfields' => array('selective'),
           'sortable' => FALSE,
           'notafield' => TRUE,
         ),
         'notification' => array(
-          'name' => t('Og: Group: Notification'),
+          'name' => t('OG: Group: Notification'),
           'handler' => 'og_handler_field_yesempty',
           'help' => t('Displays <em>yes</em> if group automatically sends email notifications to subscribers'),
         ),
         'language' => array(
-          'name' => t('Og: Group: Language'),
+          'name' => t('OG: Group: Language'),
           'help' => t('Displays the language selected for a given group'),
         ),
         
       ),
       'filters' => array(
         'directory' => array(
-          'name' => t('Og: Group: List in directory'),
+          'name' => t('OG: Group: List in directory'),
           'operator' => array('=' => 'Equals'),
           'list' => 'views_handler_operator_yesno',
           'list-type' => 'select',
@@ -76,7 +76,7 @@ function og_views_tables() {
       ),
       'filters' => array(
         'gid' => array(
-          'name' => t('Og: Post in specified group (by number)'),
+          'name' => t('OG: Post in specified group (by number)'),
           'handler' => 'og_handler_filter_gid',
           'operator' => array('=' => 'Is'),
           'help' => t('Filter for posts in specified organic groups. <em>Value</em> should be a one or more node ids (i.e. integers), separated by commas or pluses. Like taxonomy, pluses indicate that the post must appear in one of the specified groups, whereas commas indicate that the post must appear in every specified group. The page context (if View is a page) will be set to the first listed group. That means that blocks and breadcrumbs (and theme and locale, if applicable) will be based upon the first specified node id.'),
@@ -84,13 +84,13 @@ function og_views_tables() {
         'group_name_like' => array(
           // this filter does not set any context because i am delegating filtering to built
           // in views like handler. i can't easily learn which groups matched later.
-          'name' => t('Og: Post in specified groups (by name)'),
+          'name' => t('OG: Post in specified groups (by name)'),
           'handler' => 'og_handler_filter_group_name_like',
           'operator' => 'views_handler_operator_like',
           'help' => t('Filter for posts in any organic group whose name matches the string or substring entered.'),   
         ),
         'gtype' => array(
-          'name' => t('Og: Post in specified group type'),
+          'name' => t('OG: Post in specified group type'),
           'list' => variable_get('og_node_types', array('og')),
           'list-type' => 'list',
           'operator' => 'views_handler_operator_or',
@@ -117,7 +117,7 @@ function og_views_tables() {
       ),    
       'fields' => array(  
         'is_public' => array(
-          'name' => t('Og: Public'),
+          'name' => t('OG: Public'),
           'handler' => 'og_handler_field_yesempty',
           'help' => t('Displays <em>yes</em> if post is public according to OG.'),
         )  
@@ -136,7 +136,7 @@ function og_views_tables() {
       ),
       'fields' => array(
         'title' => array(
-          'name' => t('Og: Group names'),
+          'name' => t('OG: Group names'),
           'handler' => 'og_handler_field_nodelink',
           'notafield' => TRUE,
           'help' => t('Display links to any groups that are affiliated with a post.'),
@@ -159,19 +159,19 @@ function og_views_tables() {
       ),
       'fields' => array(
         'mail_type' => array(
-          'name' => t('Og: Subscription email'),
+          'name' => t('OG: Subscription email'),
           'handler' => 'og_handler_field_yesempty',
           'sortable' => false,
           'help' => t('Does subscriber receive email notifications for a group.'),
         ),
         'managelink' => array(
-          'name' => t('Og: Manage subscription link'),
+          'name' => t('OG: Manage subscription link'),
           'handler' => 'og_handler_field_managelink',
           'sortable' => FALSE,
           'notafield' => TRUE,
         ),
         'is_admin' => array(
-          'name' => t('Og: Is subscriber an admin in a group'),
+          'name' => t('OG: Is subscriber an admin in a group'),
           'handler' => 'og_handler_field_yesempty',
           'sortable' => FALSE,
         ),
@@ -179,13 +179,20 @@ function og_views_tables() {
       'filters' => array(
         'currentuidsimple' => array(
           'field' => 'uid',
-          'name' => t('Og: Group in User Subbed Groups'),
+          'name' => t('OG: Group in User Subbed Groups'),
           'operator' => 'views_handler_operator_eqneq',
           'list' => 'views_handler_filter_usercurrent',
           'list-type' => 'select',
           'help' => t('Groups are filtered to where current user is a member .'),
         ),
       ),            
+      'sorts' => array(
+        'count' => array(
+          'name' => t('OG: Group: Subscriber Count'),
+          'handler' => 'og_handler_sort_field_count',
+          'help' => t('Sort by the number of Og subscribers'),
+        ),
+      ),
     ),
     'og_uid_node' => array(
       'name' => 'og_uid',
@@ -204,7 +211,7 @@ function og_views_tables() {
       'filters' => array(
         'currentuid' => array(
           'field' => 'uid',
-          'name' => t('Og: Post in User Subbed Groups'),
+          'name' => t('OG: Post in User Subbed Groups'),
           'operator' => 'views_handler_operator_eqneq',
           'list' => 'views_handler_filter_usercurrent',
           'list-type' => 'select',
@@ -252,12 +259,12 @@ function og_views_tables() {
 function og_views_arguments() {
   $args = array(
     'gid' => array(
-      'name' => t("Og: Group nid(s)"), 
+      'name' => t("OG: Group nid(s)"), 
       'handler' => 'og_handler_argument_gid',
       'help' => t('Filter for the one or more organic groups. Groups should be specified as a comma or plus delimited list of node ids, like taxonomy URLs. '),
     ),
     'name' => array(
-      'name' => t("Og: Group name"), 
+      'name' => t("OG: Group name"), 
       'handler' => 'og_handler_argument_group_name_like',
       'option' => array(
         '#type' => 'select',
@@ -1175,6 +1182,21 @@ function og_handler_filter_picg($op, $fi
   $query->add_where("og_ancestry.group_nid = ***CURRENT_GID***");
 }
 
+/**
+ * Views handler to sort by the number subscriptions
+ */
+function og_handler_sort_field_count($op, &$query, $sortinfo, $sort) {
+  if (method_exists($query, 'add_subquery')) {
+    $sql = "SELECT ou.nid, COUNT(*) as num FROM {og_uid} ou INNER JOIN {users} u ON ou.uid = u.uid WHERE u.status > 0 GROUP BY ou.nid";
+    $join = array(
+      'left' => array('table' => 'node', 'field' => 'nid'),
+      'right' => array('field' => 'nid'),
+    );
+    $query->add_subquery($sql, array(), $join, 'og_count');
+    $query->orderby[] = 'og_count.num '. $sort['sortorder'];
+  }
+}
+
 /*
  * Simple array for current group.
  */
@@ -1226,4 +1248,4 @@ function og_views_break_phrase($string, 
     $node = node_load($gids[0]);
     og_set_group_context($node);
   }
-}
\ No newline at end of file
+}
