If I post content inside of a subgroup, that content does not appear on the homepage of a the subgroup's parent.

For example:

I post a blog entry in node B. Node B is a subgroup of node A. My blog entry should show up on the Node A group homepage.

It seems like there are to ways to accomplish this:

1) When saving any node that is a post inside of a subgroup, create a second entry in the og_acestry table that references the subgroup's parent node (node A in the above example)
2) On group homepages, perform some kind of aggregation and check for posts of all subgroups of the current group.

Any thoughts on those options?

Comments

ezra-g’s picture

Title: Posts inside of a subgroup should display on Parent Group's Homepage, Notifications » Posts inside of a subgroup should display on Grandparent Group's Homepage, Notifications

I think saving the grandparents of a node makes the most sense. In thinking about how to do this, I came up with two new functions and thought it better to discuss before submitting a patch.
og_subgroups_save_grandparents() runs when a node is updated and is similar to og_save_ancestry(). og_subgroups_save_grandparents() gets an array of the parent and grandparent groups for a node. Note that this depends in part on my proposed patch http://drupal.org/node/143530#comment-246297 that helps to provide a $node->og_groups array for subgroup nodes.

The challenge with the og_subgroups_save_grandparents() function is that it does not delete previous grandparent records from the og_ancestry table. It has no way of determining which record(pair of nid and group_nid) refer to a grandparent relationship. Perhaps it would make the most sense to save parent and grandparent information in a single function. This would require og_subgroups to override the og_save_ancestry function. Perhaps a bold step ;-)? This is up to the maintainer of og_subgroups.

function og_subgroups_save_grandparents($this_node) {
  $tree = og_subgroups_get_ancestry($this_node);
  drupal_set_message(dprint_r($tree, TRUE));
  //drupal_set_message(dprint_r($tree, TRUE));
  foreach ($tree as $this_tree) {
    foreach ($this_tree['parents'] as $parent){
      $this_parent = node_load($parent['nid']);
      if (!og_is_omitted_type($this_parent->type)) {
        //$sql = "DELETE FROM {og_ancestry} WHERE nid = %d";
        //db_query($sql, $this_parent->nid);
        $gid = $parent['nid'];
        $sql = "INSERT INTO {og_ancestry} (nid, group_nid, is_public) VALUES (%d, %d, %d)";
        drupal_set_message("sql:" .$this_node->nid . " " . $gid);
        db_query($sql, $this_node->nid, $gid, $this_node->is_public);
      }
    }
  }
}
function og_subgroups_get_ancestry($node){
  $tree = array();
  foreach($node->og_groups as $key => $value) { 
    $tree[$value]['nid'] = $value;
    $tree[$value]['title'] = $node->og_groups_names[$key];
    $tree[$value]['parents'] = og_subgroups_get_parents($value);
  }
  return $tree;
}
ezra-g’s picture

I've cleaned those two up a bit -- og_subgroups_get_ancestry will no longer return redundant values.

function og_subgroups_save_grandparents($this_node) {
  $tree = og_subgroups_get_ancestry($this_node);

  foreach ($tree as $this_tree) {
    foreach ($this_tree['parents'] as $parent){
      $this_parent = node_load($parent['nid']);
      if (!og_is_omitted_type($this_parent->type)) {
        //$sql = "DELETE FROM {og_ancestry} WHERE nid = %d";
        //db_query($sql, $this_parent->nid);
        $gid = $parent['nid'];
        $sql = "INSERT INTO {og_ancestry} (nid, group_nid, is_public) VALUES (%d, %d, %d)";
        drupal_set_message("sql:" .$this_node->nid . " " . $gid);
        db_query($sql, $this_node->nid, $gid, $this_node->is_public);
      }
    }
  }
}
function og_subgroups_get_ancestry($node){
  $tree = array();
  foreach($node->og_groups as $key => $value) { 
    $tree[$value]['nid'] = $value;
    $tree[$value]['title'] = $node->og_groups_names[$key];
    $tree[$value]['parents'] = og_subgroups_get_parents($value);
    foreach ($tree[$value]['parents'] as $parents) {
      unset($tree[$parents['nid']]);
    }
  }
  return $tree;
}

Also, here's some example output from og_subgroups_get_ancestry() :

Array
(
    [44] => Array
        (
            [nid] => 44
            [title] => Example Event
            [parents] => Array
                (
                    [43] => Array
                        (
                            [title] => Drupal Stadium
                            [type] => venue
                            [status] => 1
                            [nid] => 43
                            [is_active] => 1
                        )

                    [41] => Array
                        (
                            [title] => Leo Kottke
                            [type] => artist
                            [status] => 1
                            [nid] => 41
                            [is_active] => 1
                        )

                )

        )

)
ezra-g’s picture

At http://drupal.org/node/143530#comment-249724 swood writes:

I'm working on incorporating your changes into the current version. I hope to have something in the next few days for a release.

One question though: In your previous comment you stated: "In creating this patch I discovered that posts inside of a subgroup do not show on the homepage of the parent group and aren't included in parent group new content notifications. This is something I'd like to add. I'll create an issue for it."

Isn't this backwards? I would think that posts created in the parent would be visible within the children, but not the other way around. A subgroup is subset of a larger whole. I wouldn't think that posts within a subgroup would be visible by the entire group. If so, then there wouldn't be any privacy within a subgroup.

I believe that there are two rules that should work here:
1. Members of a subgroup are automatically members of the parent.
2. Posts within the parent are visible within the subgroup(s)

I think the propagation of posts from subgroups to groups or vice versa should be a configurable option because either might be totally appropriate (or inappropriate) for a given site.

In my case, Events can be sub-groups of of Speaker and Venue. I would like a post that discusses a particular event to show up in the Group for both the speaker and the venue.

Does this help clarify?

vikingew’s picture

With reservation that I am quite new to Drupal and og/og_subgroups, I am doubtful if you are using the right tools for what you want to achieve... why would you need this "event" to be a subgroup at all? maybe you should look at og_vocab instead and simply created adopted content types for these events - seem more logical to me at least. It's possible uses of og_vocabs still are more limited the main thing, but the right way to go then would be to integrate it with other modules that extends taxamony functionality.

The only usefulness I can see with subgroup content being available on the main group, is in a "container" like a block with e.g. links visible only for members of the subgroup - unless it's something public. So you can blend it in with main content of the group, but still to view and use it you should really visit the subgroup. Or the subgroup simply is a view of main and sub, and you kinda bypass visiting the main group.

So -1 for "backward" propagation, it will only make things become messy I believe. Well that's my view.

ezra-g’s picture

The point of my post was that it could make sense for propogation to go up or down the ancestry tree depending on the use of the website. That is why it should be a user-configurable option. Using a view of parents + subgroup on a subgroup page would not achieve the same functionality as it would not provide the subscription to content -- an essential feature of OG.

I don't follow how OG_Taxonomy would make sense for this application.

vikingew’s picture

It's possible I haven't fully understood what you want to do, but I still think it doesn't really belong to subgroups as it kinda "removes" the sub part. Maybe this rather is a seed for a new og sub module then?

I still can't see the point and in what way it has to do with subscriptions, you didn't mentioning this before? If subscription of the content are the important thing, why then display it in the main group area?

My point is just that you can't have 1 module to serve every need, then it gets messy and I think this kind of functionality in subgroups tend to at least start such a mess, which lead to bugs etc.. I haven't said it cannot be achieved with another module though :-)

ezra-g’s picture

Title: Posts inside of a subgroup should display on Grandparent Group's Homepage, Notifications » Propogation of Posts Up or Down an Ancestry Tree
Version: 5.x-1.x-dev » 5.x-3.x-dev
Assigned: Unassigned » ezra-g
Status: Active » Needs review
StatusFileSize
new2.86 KB

This patch adds a configuration option to select whether posts created in side of a group\subgroup propagate up or down the ancestry tree.

Let's say I have 2 Groups: A and B, that are parents of subgroup C. When propagating up the tree, a post inside group C would also be a post inside of A and B. When propagating down, a post inside of A would become a post inside of B.

Note that this now includes an .install file. Current users of OG_Subgroups should run update.php after applying this patch.

ezra-g’s picture

StatusFileSize
new499 bytes

Rename this to .install. Is there any better way to add a .install file to an issue?

ezra-g’s picture

Forgot to mention: If you review the contents of the patch, you'll see that I've re-written the example functions. Still, we're able to handle propagating in either direction using the same 2 functions.

ezra-g’s picture

Title: Propogation of Posts Up or Down an Ancestry Tree » Propagation of Posts Up or Down an Ancestry Tree
StatusFileSize
new2.86 KB

...modified the patch to spell 'propagation' correctly ;-).

vikingew’s picture

Let's say I have 2 Groups: A and B, that are parents of subgroup C. When propagating up the tree, a post inside group C would also be a post inside of A and B. When propagating down, a post inside of A would become a post inside of B.

Do you mean A and B is children of C? I can't see how both A and B can be parents of C, that's possibly for humans... but how can a code object have more then 1 parent?

I must say I find this rather confusing and would rather not see it go into the module - but that's my opinion and it's quite possible I have missed something.

greggles’s picture

@yettyn - multiple inheritance is a very common concept in object oriented programming, so yes, code can have multiple parents.

The concept of "parent" isn't really all that important aside from what it generally expresses to people. The important thing is what changes functionally when a "parent" or "child" is assigned.

To me, it's very logical that posts in a child group are (optionally) shown on the homepage of the parent group (or vice versa).

So, without reviewing the code, I give a +1 to the concepts of ezra's patch. In fact, before I had used og_subgroups I assumed that it already did what Ezra is trying to add.

vikingew’s picture

@yettyn - multiple inheritance is a very common concept in object oriented programming, so yes, code can have multiple parents.

well well you learn something new every day... I wasn't really aware of that, so then I rest my case ;-) and will review this later and see if I can get it to make sense.

I want to add a thing to look out for here though. There is a patch which possibly/probably will go into OG allowing for private groups ( http://drupal.org/node/83005 ). I think it would be wise to follow that development and adjust this patch accordingly before commit.

vikingew’s picture

And ezra-g, I am sorry if I have sounded negative, so I want to stress I appreciate your efforts to contribute with improvements to the module. I hope to be able doing so as well later, but my php is a bit rusty and it will take some time until I feel refreshed enough to contribute code.

ezra-g’s picture

I'll need to re-roll this patch as I've found a bug. og_subgroups_get_family() function should verify that a node has parents before looping over the parents, otherwise creating a node that is not a member of a group will result in an invalid foreach error.

I hope to re-roll this evening.

The modified function will look like this:

function og_subgroups_get_family($node, $relationship_type) {
  $func = og_subgroups_get_ . $relationship_type;
  $tree = array();
  if (is_array($node->parents)) {
    $parents = $node->parents;
  }
  else {
    $parents = $node->og_groups;
  }
  if ($parents) {
    foreach ($parents as $key => $value) {
      $tree[$value]['nid'] = $value;
      $tree[$value]['title'] = $node->og_groups_names[$key];
      $tree[$value][$relationship_type] = $func($value);
      foreach ($tree[$value][$relationship_type] as $this_member) {
        unset($tree[$this_member['nid']]);
      }
    }
  }
  return $tree;
}
ezra-g’s picture

StatusFileSize
new2.86 KB

I've re-rolled the patch against head. This should work now! Don't forget the install file!

ezra-g’s picture

Ack. This patch applied successfully but put code from the settings form into the wrong function. CVS never mistakes, so it must be human error.

I'll re-roll again.

ezra-g’s picture

StatusFileSize
new3.4 KB

This works for me. Your feedback is appreciated!

ezra-g’s picture

Status: Needs review » Needs work

This patch has a slight flaw that does not preserve the public\private status of groups. I will post a correction.

Nijip’s picture

Hi folks... your patch looks great... is there any chance of getting a Dev version of subgroups released with this patch... only because i can't patch....

ezra-g’s picture

Status: Needs work » Needs review
StatusFileSize
new3.41 KB

My apologies for the unfortunate delay re-posting this. Could someone please review?

dkoffler’s picture

I applied the patch and it produce the following output:

[root@drupal og_subgroups]# patch og_subgroups.module < 145333-redux-1.patch
patching file og_subgroups.module
Hunk #1 FAILED at 113.
Hunk #2 FAILED at 200.
Hunk #4 FAILED at 208.
Hunk #6 FAILED at 488.
Hunk #8 FAILED at 515.
5 out of 9 hunks FAILED -- saving rejects to file og_subgroups.module.rej

ezra-g’s picture

Please make sure that you're applying this against CVS revision 1.12. Is that the case?

dkoffler’s picture

D'oh! Sorry, my first time patching a module. Now that I have the latest CVS version installed the patch applied beautifully and appears to be working correctly.

Posts are propagating as expected, and I've even been able to set things up to mirror all content between two OG groups by setting them as subgroups of each other. This is a brilliant fix to the multilingual problems involved in using OGs with the i18 / Internationalization module. With this patch, two groups can be sub groups of each other which allows all content to be replicated between them and each group can be designated as a different language translation of each other.

However, I have found one bug with this particular configuration. When two groups are subgroups of each other and you navigate to one of their node pages and click on the "members" tab, Drupal returns an empty page and Apache logs a segmentation fault like this:

[notice] child pid 3868 exit signal Segmentation fault (11)

That being said, if you click the "edit" tab, you will see the full list of members displayed.

This error only seems to occur when the groups are "looped" (subgroups of each other) as in the config described above. When I make one a true parent and the other a subgroup, the error disappears.

Brilliant work on the patch all around! I've been trying to tackle the organic group/internationalization integration problem for a while. Great work!

greggles’s picture

That segmentation fault sounds like an infinite loop. If it's not easy to fix the loop, I think this module might need to prevent two groups from being subgroups of each other - that just sounds like an abuse of the system to me.

pivica’s picture

Just to inform that revision 1.12 from CVS and proposed patch works excellent. If I stumble on some bugs I will report it. Many thanks :)

ezra-g’s picture

Status: Needs review » Fixed

Committed. Catch the changes when the dev version is repackaged. If anyone wants to contribute a patch to prevent circular\impossible\nonsensical parent\child relationships, I'd be happy to take a look at it.

ezra-g’s picture

This patch is now part of the latest release, 5.x.3.0-dev, released today.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.