You are here

function og_subgroups_force_private_children in Subgroups for Organic groups 6

Force all children of a group to be private

This function will check if the admin settings call for this behavior It will also check to see if the group provided is private itself, before continuing. Both checks can be skipped by provided the argument to do so.

Parameters

$group: The group node object whos children will be set private

$force: TRUE if both admin and node settings should be ignored, resulting in the forced-privacy (default to FALSE)

1 call to og_subgroups_force_private_children()
og_subgroups_nodeapi in ./og_subgroups.module
Implementation of hook_nodeapi().

File

./og_subgroups.module, line 135
Maintains a hierarchy of groups created by the orgainc groups module.

Code

function og_subgroups_force_private_children($node, $force = FALSE) {
  og_subgroups_include('tree');

  // Avoid recursion from the node saves
  if (isset($node->og_subgroups_force_private_ignore)) {
    return;
  }

  // Check admin settings
  if ($force || variable_get('og_subgroups_inherit_privacy', 0)) {

    // Check to see if the group if private
    if ($force || $node->og_private == 1) {

      // Gather the children
      $children = og_subgroups_get_group_children($node, FALSE);

      // Force each child to be private
      foreach ($children as $child) {

        // Only force if the group is not already private
        if ($child->og_private == 0) {

          // Load the child completely
          $child = node_load($child->nid);

          // Set to private
          $child->og_private = 1;

          // Flag the node to avoid this function running recursively
          $child->og_subgroups_force_private_ignore = 1;

          // Save the node
          node_save($child);
        }
      }
    }
  }
}