A group invite is only mailed to another user but not saved. If it would be saved we could add facebook-like information, e.g. a message on the profile "You are invited to *group name*".

Comments

Jakob Stoeck’s picture

I just coded something for my project. What do you think of it? Important parts like deleting a pending invite are missing, yet.

Should it be a module or should I submit a patch for og.pages.inc (which holds the form handler I extend)?

; $Id$
name = OG Invite
description = Saves OG invites persistently to use them e.g. the profile
dependencies[] = og
core = 6.x
package = "Organic groups"
// $ID$
// og_invite.module

function og_invite_form_og_invite_form_alter(&$form, &$form_state) {
	$form['#submit'][] = 'og_invite_og_invite_form_submit';
}

function og_invite_og_invite_form_submit(&$form, &$form_state) {
	global $user;

	foreach($form_state['valid_emails'] as $email) {
		$account = user_load(array('mail' => $email));

		$invite = array(
			'email' => $email,
			'uid' => $account->uid,
			'gid' => $form_state['values']['gid'],
			'invitee' => $user->uid,
			'pmessage' => $form_state['values']['pmessage'],
			'created' => time()
		);

		drupal_write_record('og_invite', $invite);
	}
} 
// og_invite.install

function og_invite_install() {
  drupal_install_schema('og_invite');
}

function og_invite_schema() {
  $schema['og_invite'] = array(
    'description' => t('The base table for og invites.'),
    'fields' => array(
	  'email' => array(
        'description' => t('Stores the e-mail the invite has been addressed to.'),
        'type' => 'varchar',
        'length' => 100,
        'not null' => TRUE,
        'default' => '',
      ),
      'uid' => array(
        'description' => t('Stores the user id of the inviter.'),
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'gid' => array(
        'description' => t('Stores the node id of the invited group.'),
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'invitee' => array(
        'description' => t('Stores the user id of the invitee.'),
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'pmessage' => array(
        'description' => t('Stores the message of the invite.'),
        'type' => 'text',
        'not null' => FALSE,
        'default' => NULL,
      ),
      'created' => array(
        'description' => t('Stores the creation time of the invite.'),
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array('email', 'gid'),
    'indexes' => array(
      'email' => array('email'),
      'uid'   => array('uid'),
    ),
  );

  return $schema;
}

/**
 * Implementation of hook_uninstall().
 */
function og_invite_uninstall() {
  // Drop database schema.
  drupal_uninstall_schema('og_invite');
} 
amitaibu’s picture

Category: feature » support
Status: Active » Fixed

This is a good idea - that should live in contrib. But before you should probably add the part where the user registers and gets automatically registered to the inviting group(s).

Status: Fixed » Closed (fixed)

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

Jakob Stoeck’s picture

Assigned: Unassigned » Jakob Stoeck

I finished the og_invite module and requested CVS access.