You are here

context_og_condition_member_status.inc in Context OG 6.3

Same filename and directory in other branches
  1. 7.2 plugins/context_og_condition_member_status.inc

File

plugins/context_og_condition_member_status.inc
View source
<?php

/**
 * Expose organic groups member status as a context condition.
 */
class context_og_condition_member_status extends context_condition {
  function condition_values() {
    $values = array(
      'no_member' => t('Not a member'),
      'member' => t('Member of group'),
      'admin' => t('Admin of group'),
    );
    return $values;
  }
  function options_form($context) {
    $defaults = $this
      ->fetch_from_context($context, 'options');
    return array(
      'node_form' => array(
        '#title' => t('Set on node form'),
        '#type' => 'checkbox',
        '#description' => t('Set this context on node forms'),
        '#default_value' => isset($defaults['node_form']) ? $defaults['node_form'] : TRUE,
      ),
    );
  }
  function execute($group) {
    if (isset($group)) {
      $node_form = arg(0) == 'node' && (is_numeric(arg(1)) && arg(2) == 'edit' || arg(1) == 'add');
      if (og_is_group_admin($group)) {
        $type = 'admin';
      }
      elseif (og_is_group_member($group, FALSE)) {
        $type = 'member';
      }
      else {
        $type = 'no_member';
      }
    }
    foreach ($this
      ->get_contexts($type) as $context) {
      $options = $this
        ->fetch_from_context($context, 'options');

      // The condition is met unless we are looking at a node form
      // and the "Set on node form" option is unchecked.
      if (!$node_form || !empty($options['node_form'])) {
        $this
          ->condition_met($context, $type);
      }
    }
  }

}

Classes

Namesort descending Description
context_og_condition_member_status Expose organic groups member status as a context condition.