I have og, og_forum, views and category modules installed. I wish to replace the individual group home pages with Views (or, a view that will take the group node id as an argument).

The blub I found here http://drupal.org/node/59846 seems to indicate it's possible, but does not point to how it might be done.

Anyone done this? Have any ideas how to do it?

Thanks!

-ron

Comments

somebodysysop’s picture

The og function that creates the default group home page is

theme_og_view($node, $teaser = FALSE, $page = FALSE)

and, it is themeable. You can replace this part of the function:

      $exempt = array_merge(variable_get('og_node_types', array('og')), variable_get('og_omitted', array()));
      foreach ($types as $type => $val) {
        if (!in_array($type, $exempt)) {
          if ($table = og_list_og($node->nid, $type, $mode)) {
            $output .= $table;
          }
        }
      }

with the code to call a view:

		$view_args = array('Your View Arguments');
		$view = views_get_view("Your View Name");
		$output = views_build_view('embed', $view, $view_args, $view->use_pager, $view->nodes_per_page);

That will do it.

My issue is that once you are looking at content from the view, you lose the og group navigation menu. So, my new question is: is there a way to tell og that when you are in a particular view (like, view/group/groupNumber), that you are still in group content and to maintain the group navigation menu?

Thanks!

discursives’s picture

Depending on the URL I would 'think' it's possible to call a group menu (specific group menu).

somebodysysop’s picture

What I really wanted to do was maintain my group context while in the view. I found a way to do it with the og_tracker contribution discussed here: http://drupal.org/node/66145

markusH’s picture

I just had to tackle the same issue and simply put this bit of code as Argument Handling Code into the view:

if (($args[0])) 
{
  $node = node_load(intval($args[0]));
    og_set_group_context($node);
}
return $args;

The only argument of the view is the node id of the group you're looking at. The group block shows up when viewing the page. But I haven't tested it much. Does anyone have experience with that?

Here's the rest of the view:

  $view = new stdClass();
  $view->name = 'Gruppenbeitraege';
  $view->description = 'all discussion item in a group';
  $view->access = array (
  0 => '1',
  1 => '2',
);
  $view->view_args_php = 'if (($args[0])) 
{
  $node = node_load(intval($args[0]));
    og_set_group_context($node);
}
return $args;';
  $view->page = TRUE;
  $view->page_title = 'Gruppenbeiträge';
  $view->page_header = "";
  $view->page_header_format = '2';
  $view->page_footer = "";
  $view->page_footer_format = '4';
  $view->page_empty = "";
  $view->page_empty_format = '4';
  $view->page_type = 'teaser';
  $view->url = 'gruppenbeitraege';
  $view->use_pager = TRUE;
  $view->nodes_per_page = '10';
  $view->sort = array (
  );
  $view->argument = array (
    array (
      'type' => 'gid',
      'argdefault' => '7',
      'title' => '',
      'options' => '',
      'wildcard' => '',
      'wildcard_substitution' => '',
    ),
  );
  $view->field = array (
  );
  $view->filter = array (
    array (
      'tablename' => 'node',
      'field' => 'status',
      'operator' => '=',
      'options' => '',
      'value' => '1',
    ),
    array (
      'tablename' => 'og_uid_node',
      'field' => 'currentuid',
      'operator' => '=',
      'options' => '',
      'value' => '***CURRENT_USER***',
    ),
    array (
      'tablename' => 'node',
      'field' => 'type',
      'operator' => 'OR',
      'options' => '',
      'value' => array (
  0 => 'content_group_discussion',
),
    ),
  );
  $view->exposed_filter = array (
  );
  $view->requires = array(node, og_uid_node);
  $views[$view->name] = $view;

content_group_discussion is a cck content type similar to the build in blog content type.

mojobaer’s picture

I had the same problem - I want to have the group blocks available on my view pages. That node_load and og_set_group_context in the argument handler worked beautifully!

Thanks again.

Patrick Nelson’s picture

Thanks for posting this, SomebodySysop.

Can you help me with regards to the code above? I have a view called group_home and the url networking_group/$arg where the arg is the og nid. So, to get that to appear in place of the default group home page, what exactly do I replace the code with? I have tried this, but it doesn't seem to work:

 $view_args = array('');
$view = views_get_view("group_home");
$output = views_build_view('embed', $view, $view_args, $view->use_pager, $view->nodes_per_page);

Regards

Patrick

somebodysysop’s picture

I haven't looked at this in quite a while, but I went to my template.php file and pulled this out of my theme_og_view() function.

		$view_args = array($node->nid);
		$view = views_get_view("GroupHomePrimary");
		$output = views_build_view('embed', $view, $view_args, $view->use_pager, $view->nodes_per_page);

So, it looks like you should try using $node->nid.

If this doesn't solve it, then I'll post the whole function.

Patrick Nelson’s picture

Thanks SomebodySysop,

Would you mind posting the whole function? I'm not a 100% clear on what to name the function in template.php and I don't want to get this wrong!

Sorry to be a pain.

Regards

Patrick Nelson
www.vcommunity.org.uk

somebodysysop’s picture

I'm using channel_nine theme, so in my template.php here is the code I use:

// if you want a totally different group home page, you may redefine this function in your theme
// if you just want to change the presentation of a group home page section, redefine theme_og_list_generic()
function channel_nine_og_view($node, $teaser = FALSE, $page = FALSE) {
  if ($teaser || !$page) {
    $node->teaser = $node->og_description;
  }
  else {
    $bc[] = array('path' => "og", 'title' => t('groups'));
    $bc[] = array('path' => "node/$node->nid", 'title' => $node->title);
    menu_set_location($bc);
    drupal_add_link(array(
                        'rel' => 'alternate',
                        'type' => 'application/rss+xml',
                        'title' => $node->title. t(' RSS feed'),
                        'href' => url("og/feed/$node->nid")));
    $output = '';

    // 2 views. 'segregate each content type' or 'a river of news'
    if (variable_get('og_home_page_presentation', 'gbct') == 'ron') {
      $sql = og_get_home_nodes_sql();
      $num = variable_get('og_max_posts', 10);
      $result = pager_query(db_rewrite_sql($sql, 'n', 'nid', array('og_nid' => $node->nid)), $num);
      while ($onenode = db_fetch_object($result)) {
        $output .= node_view(node_load($onenode->nid), TRUE, FALSE);
      }
      $output .= theme('pager', NULL, $num);
    }
    else {
      $mode = 'all';
      $ntype = $_GET['ntype'];
      if (!isset($ntype)) {
        $types = node_get_types();
        $mode = 'brief';
      }
      else {
        $types[$ntype] = $ntype;
      }
      $exempt = array_merge(variable_get('og_node_types', array('og')), variable_get('og_omitted', array()));

	//
	// Get the GroupHomePrimary view instead of default og home page
	//
		$view_args = array($node->nid);
		$view = views_get_view("GroupHomePrimary");
		$output = views_build_view('embed', $view, $view_args, $view->use_pager, $view->nodes_per_page);
	//
	// Default og home page
	//
//      foreach ($types as $type => $val) {
//        if (!in_array($type, $exempt)) {
//          if ($table = og_list_og($node->nid, $type, $mode)) {
//            $output .= $table;
//          }
//        }
//      }
	// 
	//
    }
    $url = url("og/feed/$node->nid");
    $node->og_xml_icon = theme('xml_icon', $url);
    
    if (!$output) {
      global $user;
      if (in_array($node->nid, array_keys($user->og_groups))) {
        drupal_set_message(t('No posts in this group.'));
      }
      else {
        drupal_set_message(t('No public posts in this group. Consider subscribing to this group in order to view its posts.'));
      }
    }
  }
  // save the homepage nodes in an array element for use by themes if desired
  $node->homepage_nodes = $output;
  
  if ($node->body) {
    // save the mission in an array element for use by themes if desired
    $node->og_mission = theme('og_mission', $node);
  }
  $node->body = $node->og_mission. $output. $node->og_xml_icon;
  return $node;
}
pjo’s picture

Hi, could someone please export their group views settings? (or send detailed instructions of how to create it)
thanks
/petter

somebodysysop’s picture

Please note that this particular view has a lot of embedded views in it (which I expunged from the header below to avoid posting errors here). Also, I'm doing some fancy filtering with categories. But, with the theme_og_view() code above, this is what I use as my group home page:

  $view = new stdClass();
  $view->name = 'GroupHomePrimary';
  $view->description = 'Group Home Primary Page';
  $view->access = array (
  0 => '2',
);
  $view->view_args_php = '';
  $view->page = TRUE;
  $view->page_title = 'Group Home Page Calendar';
  $view->page_header = "";
  $view->page_header_format = '2';
  $view->page_footer = "<hr>";
  $view->page_footer_format = '2';
  $view->page_empty = "";
  $view->page_empty_format = '3';
  $view->page_type = 'list';
  $view->url = 'og/view/grouphomeprimary';
  $view->use_pager = TRUE;
  $view->nodes_per_page = '10';
  $view->sort = array (
  );
  $view->argument = array (
  );
  $view->field = array (
    array (
      'tablename' => 'node',
      'field' => 'title',
      'label' => '',
      'handler' => 'views_handler_field_nodelink',
      'sortable' => '1',
      'options' => 'link',
    ),
  );
  $view->filter = array (
    array (
      'tablename' => 'category',
      'field' => 'cid',
      'operator' => '=',
      'options' => '',
      'value' => '136',
    ),
  );
  $view->exposed_filter = array (
  );
  $view->requires = array(node, category);
  $views[$view->name] = $view;