? .patch
? og_primary.patch
? tmp.patch
? tmp.patch.patch
? modules/og_access/tmp.patch
? modules/og_access/tmp.patch.patch
? modules/og_views/.patch
? modules/og_views/includes/.patch
Index: og.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/og/Attic/og.install,v
retrieving revision 1.71.4.5
diff -u -F^f -p -r1.71.4.5 og.install
--- og.install	15 May 2009 17:28:02 -0000	1.71.4.5
+++ og.install	29 May 2009 02:00:47 -0000
@@ -140,6 +140,13 @@ function og_schema() {
         'size'            => 'normal',
         'not null'        => TRUE,
       ),
+      'og_primary'       => array(
+        'description'     => t('Is this the primary group for this post?'),
+        'type'            => 'int',
+        'size'            => 'tiny',
+        'default'         => 0,
+        'not null'        => TRUE,
+      ),        
     ),
     'primary key'       => array('nid', 'group_nid'),
   );
@@ -432,6 +439,17 @@ function og_update_6203() {
   return $ret;
 }
 
+// Add the og_primary field. This field is used to store a 1/0 flag if the group is the primary group for a node
+function og_update_6204() {
+  $ret = array();
+  
+  $schema = drupal_get_schema_unprocessed('og', 'og_ancestry');
+  $fields = $schema['fields'];
+  db_add_field($ret, 'og_ancestry', 'og_primary', $fields['og_primary']);
+
+  return $ret;
+}
+
 // end updates //
 
 function og_uninstall() {
Index: og.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/og/Attic/og.module,v
retrieving revision 1.628.4.6
diff -u -F^f -p -r1.628.4.6 og.module
--- og.module	29 May 2009 01:00:21 -0000	1.628.4.6
+++ og.module	29 May 2009 02:00:48 -0000
@@ -595,6 +595,24 @@ function og_set_theme($group_node) {
 }
 
 /**
+ * API function for getting the primary group context of a node. 
+ *
+ * @return $primary_group node object
+ */
+function og_get_primary_group($node = NULL) {
+  static $primary_group;
+  
+  if(!isset($primary_group)){
+    $sql = 'SELECT a.group_nid FROM {og_ancestry} a WHERE a.nid = %d AND a.og_primary = 1';
+    $result = db_query($sql, $node->nid);
+    $primary_group = node_load(db_result($result, 0));
+  }
+  
+  return $primary_group;
+}
+
+
+/**
  * Low level function for managing membership
  *
  * @param $gid node ID of a group
@@ -1593,6 +1611,8 @@ function og_form_add_og_audience(&$form,
   $node = $form['#node'];
   $required = variable_get('og_audience_required', 0) && !user_access('administer nodes');
   $is_optgroup = FALSE;
+  $select_primary = variable_get('og_primary_group', FALSE);
+  $primary_group = og_get_primary_group($node);    
   
   // Determine the list of groups that are shown.
   // Start by collecting all groups that the user is a member of.
@@ -1696,6 +1716,9 @@ function og_form_add_og_audience(&$form,
       
       // this 'value' element persists the audience value during submit process
       $form['og_nodeapi']['invisible']['og_groups'] = array('#type' => 'value', '#value' => $assoc_groups);
+      
+      // persist the primary group
+      $form['og_nodeapi']['invisible']['og_primary_group'] = array('#type' => 'value', '#value' => $primary_group->nid);      
     }
   }
   elseif ($cnt = count($options, COUNT_RECURSIVE)) {
@@ -1711,6 +1734,20 @@ function og_form_add_og_audience(&$form,
       '#default_value' => $groups ? $groups : array(),
       '#required' => $required, 
       '#multiple' => TRUE);
+    
+    //specify a primary group
+    if($select_primary){
+      $form['og_nodeapi']['visible']['og_primary_group'] = array(
+        '#type' => 'select', 
+        '#title' => t('Primary Audience'), 
+        '#attributes' => array('class' => 'og-primary'),
+        '#options' => $options, 
+        '#required' => FALSE, 
+        '#description' =>  'Select a primary audience for this post. The primary audience influences how this post will be shows (e.g. its navigation breadcrumb, its side blocks, etc.)',
+        '#default_value' => $primary_group->nid,
+        '#size' => count($options) > 6 ? 6 : count($options),
+        '#multiple' => FALSE);
+    }    
   }
   else if ($required) {
     form_set_error('title', t('You must <a href="@join">join a group</a> before posting a %type.', array('@join' => url('og'), '%type' => node_get_types('name', $node->type))));
@@ -1863,6 +1900,7 @@ function og_save_ancestry($node) {
         $ancestry = array(
           'nid' => $node->nid,
           'group_nid' => $gid,
+          'og_primary' => $gid == $node->og_primary_group
         );
         drupal_write_record('og_ancestry', $ancestry);
       }
Index: includes/og.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/og/includes/Attic/og.admin.inc,v
retrieving revision 1.15
diff -u -F^f -p -r1.15 og.admin.inc
--- includes/og.admin.inc	19 Nov 2008 04:23:49 -0000	1.15
+++ includes/og.admin.inc	29 May 2009 02:00:48 -0000
@@ -85,6 +85,14 @@ function og_admin_settings() {
     '#description' => t('Do you require that all (non administrator) posts be affiliated with a group? Note that changing this setting will affect existing posts when they are edited.')
   );
   unset($options);
+  
+  // Primary Group
+  $form['og_settings']['group_details']['og_primary_group'] = array(
+    '#type' => 'checkbox', 
+    '#title' => t('Primary Audience'), 
+    '#default_value' => variable_get('og_primary_group', FALSE), 
+    '#description' => t('Allow content creators to choose a primary audience for a group post. This primary audience determines group context when viewing the post such as which blocks/languages/theme/breadcrumb are shown.'),
+  );   
 
   // Messages fieldset.
   $form['og_settings']['notifications'] = array(
