User login

Automatically putting a user's post into an organic group

The final result is in the (as yet unreleased, but if you want the code we'll send it) special treatment module.

Some test ouput and discovery of key function along the way:

<?php
'og_groups' =>
  array (
    11054 =>
    array (
      'title' => 'A Center for Development and Entrepreneurship',
      'type' => 'partner',
      'status' => '1',
      'nid' => '11054',
      'og_role' => '0',
      'is_active' => '1',
      'is_admin' => '1',
      'uid' => '1',
      'mail_type' => NULL,
      'created' => '1222100233',
      'changed' => '1222280936',
    ),
  ),
   'og_email' => '2',

'og_groups' => array ( ), 'og_email' => '1', ))
?>

For user #1, editing an existing form:

<?php
  'og_initial_groups' =>
  array (
    '#type' => 'value',
    '#value' => NULL,
  ),
  'og_nodeapi' =>
  array (
    'visible' =>
    array (
      'og_groups' =>
      array (
        '#type' => 'checkboxes',
        '#title' => 'Audience',
        '#attributes' =>
        array (
          'class' => 'og-audience',
        ),
        '#options' =>
        array (
          11054 => 'A Center for Development and Entrepreneurship',
        ),
        '#required' => false,
        '#description' => 'Show this post in this group.',
        '#default_value' => NULL,
        '#multiple' => true,
      ),
    ),
  ),
?>

When there's a value:

<?php
  'og_initial_groups' =>
  array (
    '#type' => 'value',
    '#value' =>
    array (
      0 => 11054,
    ),
  ),
?>

For a regular user:

<?php
  'og_invisible' =>
  array (
    'og_groups_inaccessible' =>
    array (
      '#type' => 'value',
      '#value' =>
      array (
      ),
    ),
  ),
  'og_initial_groups' =>
  array (
    '#type' => 'value',
    '#value' => NULL,
  ),
?>

Agaric's new friend, organic groups' save ancestry function:

<?php
function og_save_ancestry($node) {
  if (og_is_group_post_type($node->type)) {
    $sql = "DELETE FROM {og_ancestry} WHERE nid = %d";
    db_query($sql, $node->nid);
    if (is_array($node->og_groups)) {
      $node->og_groups = array_unique($node->og_groups);
      foreach ($node->og_groups as $gid) {
        $sql = "INSERT INTO {og_ancestry} (nid, group_nid, is_public) VALUES (%d, %d, %d)";
        db_query($sql, $node->nid, $gid, $node->og_public);
      }
    }
  }
}
?>

<?php
  'og_initial_groups' =>
  array (
    '#type' => 'value',
    '#value' =>
    array (
      0 => 11054,
    ),
  ),
  'og_nodeapi' =>
  array (
    'visible' =>
    array (
      'og_groups' =>
      array (
        '#type' => 'checkboxes',
        '#title' => 'Audience',
        '#attributes' =>
        array (
          'class' => 'og-audience',
        ),
        '#options' =>
        array (
          11054 => 'A Center for Development and Entrepreneurship',
        ),
        '#required' => false,
        '#description' => 'Show this post in this group.',
        '#default_value' =>
        array (
          0 => 11054,
        ),
        '#multiple' => true,
      ),
    ),
  ),
?>

Resolution

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.