You are here

public function LdapAuthorizationConsumerOG::mappingExamples in Lightweight Directory Access Protocol (LDAP) 7.2

Same name and namespace in other branches
  1. 8.2 ldap_authorization/ldap_authorization_og/LdapAuthorizationConsumerOG.class.php \LdapAuthorizationConsumerOG::mappingExamples()
  2. 7 ldap_authorization/ldap_authorization_og/LdapAuthorizationConsumerOG.class.php \LdapAuthorizationConsumerOG::mappingExamples()

Get list of mappings based on existing Organic Groups and roles.

Parameters

array $tokens: Array of tokens and replacement values.

Return value

HTML examples of mapping values.

File

ldap_authorization/ldap_authorization_og/LdapAuthorizationConsumerOG.class.php, line 594

Class

LdapAuthorizationConsumerOG

Code

public function mappingExamples($tokens) {

  /**
   * OG 7.x-2.x mappings:
   * $entity_type = $group_type,
   * $bundle = $group_bundle
   * $etid = $gid where edid is nid, uid, etc.
   *
   * og group is: entity_type (eg node) x entity_id ($gid) eg. node:17
   * group identifier = group_type:gid; aka entity_type:etid e.g. node:17
   *
   * membership identifier is:  group_type:gid:entity_type:etid
   * in our case: group_type:gid:user:uid aka entity_type:etid:user:uid e.g. node:17:user:2
   *
   * roles are simply rids ((1,2,3) and names (non-member, member, and administrator member) in og_role table
   * og_users_roles is simply uid x rid x gid
   *
   * .. so authorization mappings should look like:
   *    <ldap group>|group_type:gid:rid such as staff|node:17:2
   */
  $og_fields = field_info_field(OG_GROUP_FIELD);
  $rows = [];
  $role_name = OG_AUTHENTICATED_ROLE;
  if (!empty($og_fields['bundles'])) {
    foreach ($og_fields['bundles'] as $entity_type => $bundles) {
      foreach ($bundles as $i => $bundle) {
        $query = new EntityFieldQuery();
        $query
          ->entityCondition('entity_type', $entity_type)
          ->entityCondition('bundle', $bundle)
          ->range(0, 5)
          ->addMetaData('account', user_load(1));
        $result = $query
          ->execute();
        if (!empty($result)) {
          $entities = entity_load($entity_type, array_keys($result[$entity_type]));
          $i = 0;
          if ($entities) {
            foreach ($entities as $entity_id => $entity) {
              $i++;
              $rid = ldap_authorization_og2_rid_from_role_name($entity_type, $bundle, $entity_id, OG_AUTHENTICATED_ROLE);
              $title = is_object($entity) && property_exists($entity, 'title') ? $entity->title : '';
              $middle = $title && $i < 3 ? $title : $entity_id;
              $group_role_identifier = ldap_authorization_og_authorization_id($middle, $rid, $entity_type);
              $example = "<code>ou=IT,dc=myorg,dc=mytld,dc=edu|{$group_role_identifier}</code>";
              $rows[] = [
                "{$entity_type} {$title} - {$role_name}",
                $example,
              ];
            }
          }
        }
      }
    }
  }
  $variables = [
    'header' => [
      'Group Entity - Group Title - OG Membership Type',
      'example',
    ],
    'rows' => $rows,
    'attributes' => [],
  ];
  $table = theme('table', $variables);
  $link = l(t('admin/config/people/ldap/authorization/test/og_group'), 'admin/config/people/ldap/authorization/test/og_group');
  $examples = <<<EOT

<br/>
Examples for some (or all) existing OG Group IDs can be found in the table below.
This is complex.  To test what is going to happen, uncheck "When a user logs on" in IV.B.
and use {<span class="php-variable">$link</span>} to see what memberships sample users would receive.

{<span class="php-variable">$table</span>}

EOT;
  $examples = t($examples, $tokens);
  return $examples;
}