You are here

function og_subgroups_context_condition_node_below_og::execute in Subgroups for Organic groups 6

Execute the plugin

File

modules/og_subgroups_context/plugins/og_subgroups_context_condition_node_below_og.inc, line 26

Class

og_subgroups_context_condition_node_below_og
Enable OG Subgroups to trigger a condition based on node's position below the OG defined in the condition.

Code

function execute() {
  if ($this
    ->condition_used()) {

    // Determine the group we're in
    if ($group = og_subgroups_context_current_group()) {
      foreach ($this
        ->get_contexts($value) as $context) {
        og_subgroups_include('tree');

        // Get groups selected in our conditions when context was defined.
        $selected = $context->conditions['og_subgroups_context_condition_node_below_og']['values'];

        // Iterate each of the selected groups
        foreach ($selected as $pid) {

          // Build a parent object to pass
          $parent = new stdClass();
          $parent->nid = $pid;

          // See if the current group is a child of the parent
          if (og_subgroups_group_is_child($parent, $group)) {

            // Activate the context
            $this
              ->condition_met($context, $parent->nid);

            // Stop here
            break;
          }
        }
      }
    }
  }
}