I'm looking at using organic groups as a general mechanism for permissions on my site, as per:
http://www.telecentre.org/en-tc/using_organic_groups

As an example, I'm implementing "contests" as an organic group, where the organic group node is a custom node type called 'contest' (flexinode-4, technically), and the specific functionality of the contest is all encapsulated in the themeing.

This seems to be working well, but there are a few generalizations of the module code at the themeing level that would make the code a little more straighforward. As an example - an og themeing function convention that would just allow the theme overrides to add in node type to the name to make that theme function only apply to og node types of that type (e.g. i define phptemplate_contest_og_view to override theme_og_view whenever the node->type is of type 'contest').

In the meantime, I'm just posting this here in case anyone else has already been working in this direction or has some ideas.

As a general observation - the idea of allowing organic groups to have any node type seems like a nice idea, but in my experience so far, the functionality I'm looking for resides mostly in the og themeing. Of course, I could write a custom module that would compete with og via the nodeapi hook, but that seems like a lot of work, and hell to debug.

CommentFileSizeAuthor
#4 ogtheme.patch_0.txt3.41 KBadixon
#3 ogtheme.patch.txt3.33 KBadixon

Comments

moshe weitzman’s picture

Status: Active » Closed (won't fix)

i prefer that the theme override functin have the switches on node type. no other actionable issue here so i close it. feel free to keep talking here though.

adixon’s picture

thanks moshe, here's my next example - I want to have different contests that allow users to upload different kinds of content (in contest #1, they're uploading images, blog postings and audio). Future contests will allow other kinds of content.

So I want to filter the allowed postings based on the gid (group page node->nid). I've done this by modifying the calls in the block generating code from
theme('item_list',$links)
to
theme('og_item_list',array('gid'=>$node->nid,'type'=>$node->type,'region' => 'block_description'),$links)
and then I've defined

function theme_og_item_list($context,$links) {
  return theme_item_list($links);
}

This allows me to then have a
phptemplate_og_item_list($context,$links)
function that can selectively mangle the available types in each og gid/type/block. Yeah, i didn't need 'type' in my context array, but maybe I will...

This appears to work, but the code would be much cleaner we introduce some themeing abstractions further up the code (e.g. directly in the block code). The other problem with this solution is that it's only mangling the display in the block, and doesn't actually prevent someone from posting other types of content if they figure out the url. Not a big deal in this case.

Any ideas?

adixon’s picture

Assigned: adixon » Unassigned
Status: Closed (won't fix) » Needs review
StatusFileSize
new3.33 KB

okay, i've been working on this some more and here's a patch that includes the change describe in my previous posting (i.e., themeing the og details block), as well as some customization of the node posting message.

Re: customization of the node posting message - this adds some more information for the poster, telling them which groups they've posted to, (using the drupal_set_message mechanism). This message by default says "Posted to ", and will appear before the standard node insert message (which is "Your was created."). But I've also put in a themeing hook of theme_og_post_message, so you can customize the exact message (in my case, I wanted it to say "thanks for posting to the contest").

My example theming override function is below:

/* intercept the usual group messages on posting and replace with contest message */

function phptemplate_og_post_message($node,$groups) {
  if (!count($groups)) return;
  $contest_nids = array(ES_TELECENTRE_BOOKLAUNCH_CONTEST_NID, EN_TELECENTRE_BOOKLAUNCH_CONTEST_NID, FR_TELECENTRE_BOOKLAUNCH_CONTEST_NID);
  foreach($groups as $group) {
    if (in_array($group->nid,$contest_nids)) {
      $msg = t('Your %post has been submitted to the contest. Thanks for your submission!',array('%post' => node_get_name($node)));
      $msg .= '<br />'.l('Return to the contest page to see your submissions.','node/'.$group->nid,array('class' => 'contest-page'));
      return $msg;
    }
  }
  # otherwise default to the usual ...
  return theme_og_post_message($node,$groups);
}
adixon’s picture

StatusFileSize
new3.41 KB

I've just updated my version of og to the current cvs (june 14, 11:32) and reran the diff, attached.

moshe weitzman’s picture

Status: Needs review » Closed (won't fix)

this is a undrupalish. we don't customize status messages anywhere. also code stytle is off. don't use if() on single line ... there are good ideas here, but i'm ont inclined to take this patch, unless others argue for it.

adixon’s picture

Status: Closed (won't fix) » Active

This doesn't seem like a very serious reply. I apologize for the two (very small) coding style slips, but the "we don't customize status messages" seems odd. In my other work, i've found that providing more helpful and context specific status messages makes drupal much more useable, which is one of our goals, yes? When posting to a group, providing that feedback in a nice clear way seems like a good thing, and allowing themes to customize that message is the whole point of my work here - to extend organic groups to a more general tool for managing permissions in a flexible way, in this case, to use it as a 'contest' type module.

Of course, I could just go off and write another custom module, but one of the arguments for extending organic groups is the whole problem of modules with conflicting use of the node_access table. In addition, since you had extended the module to make use of arbitrary node types, it seemed like you were encouraging this direction. If not, tell me and I won't waste more time trying to contribute my work back. Or if you think there is a better way to accomplish this within organic groups, tell me that.

adixon’s picture

Status: Active » Closed (won't fix)