Default mode
scedwar - November 26, 2007 - 16:57
| Project: | OG Contact |
| Version: | 5.x-1.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | gnat |
| Status: | closed |
Jump to:
Description
This is an incredibly useful module, thanks!
Would it be possible to create a default mode so that the contact form appears on all groups by default? My use case makes it difficult to require an admin to switch on the mode or even require the user to select this?
Thanks, Stephen

#1
I will have to think about exactly how to go about doing this, but I think it shouldn't be that hard, and would definitely be handy in a bunch of different use cases.
#2
Hallo
This isn't the more useful 'default to contacts for new groups' option, but I've a quick and dirty hack that helps a little. It provides an 'add all' button to give all groups currently sans contact form their own form.
Really, it needs an 'are you sure?' check, but it'll do for now. Remember to clear cache_menu or you won't see the new button.
Two chunks: add this into implementation of hook_menu (minus the php tags - they're just here for formatting...):
<?php
$items[] = array('path' => 'admin/og/contact/addall',
'title' => t('Add all groups'),
'callback' => 'og_contact_addall',
'access' => user_access('administer og contact form'),
'type' => MENU_LOCAL_TASK,
'weight' => 3,
);?>
and add this function somewhere else:
<?php
function og_contact_addall() {
//Things we need to do:
//1. Get a list of all current groups from table og, indexed by nid
//2. Find out which ones already have a contact form from og_contact, indexed by gid (should match nid from og)
//3. If it doesn't, add to the og_contact table
$query = "SELECT nid FROM {og}";
$queryResult = db_query($query);
$grpno = 0;
$alteredno = 0;
while ($row = db_fetch_object($queryResult)) {
//Check if group doesn't already have a contact form
if (!og_contact_group_has_form($row->nid)) {
//It doesn't, so add it to the og_contact table
db_query("INSERT INTO {og_contact} (gid, reply) VALUES ('%d','%s')", $row->nid, "");
$alteredno++;
}
$grpno++;
}//end while
$page_content = 'Total number of groups: '.$grpno.'<br />';
$page_content .= 'Number of groups given a new contact form: '.$alteredno;
print theme("page", $page_content);
} //end function addall
?>
#3
Thanks for the code!
It had occurred to me that retroactively enabling forms for all groups that existed prior to installing the module would be essential for this feature to be helpful to anyone that wasn't starting from scratch. So thanks for writing the code that was next on my to do list.
I have the basics of the original feature request in place. Its a checkbox on the settings page that allows you to enable Contact forms for all organic groups, and creates them at time of group (node) creation.
I also realized that the module wasn't deleting forms when groups were deleted, so that is now in there as well.
Once I merge this code into my new version of the module, I will package another dev release. Hopefully that will happen within the next week, but definitely within the next two.
#4
The latest dev snapshot contains both the requested feature, as well as a version of the additional suggested code.