/**
     * Get list of mappings based on existing Organic Groups and roles
     *
     * @param associative array $tokens of tokens and replacement values
     * @return html examples of mapping values
     */
    public function mappingExamples($tokens)
    {
        if ($this->ogVersion == 1) {
            $groups = og_get_all_group();
            $ogEntities = og_load_multiple($groups);
            $OGroles = og_roles(0);
            $rows = array();
            foreach ($ogEntities as $group) {
                foreach ($OGroles as $rid => $role) {
                    $example = "<code>ou=IT,dc=myorg,dc=mytld,dc=edu|gid=" . $group->gid . ',rid=' . $rid . '</code><br/>' . '<code>ou=IT,dc=myorg,dc=mytld,dc=edu|group-name=' . $group->label . ',role-name=' . $role . '</code>';
                    $rows[] = array($group->label, $group->gid, $role, $example);
                }
            }
            $variables = array('header' => array('Group Name', 'OG Group ID', 'OG Membership Type', 'example'), 'rows' => $rows, 'attributes' => array());
        } else {
            /**
             * 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
             */
            $rows = array();
            foreach ($this->ogs as $entity_type => $entities) {
                foreach ($entities as $entity_id => $entity) {
                    foreach ($entity['roles'] as $rid => $role) {
                        $group_role_identifier = ldap_authorization_og_authorization_id($entity_id, $rid, $entity_type);
                        $example = "<code>ou=IT,dc=myorg,dc=mytld,dc=edu|{$group_role_identifier}</code>";
                        $rows[] = array($entity['name'] . ' - ' . $role, $example);
                    }
                }
            }
            $variables = array('header' => array('Group Name - OG Membership Type', 'example'), 'rows' => $rows, 'attributes' => array());
        }
        $table = theme('table', $variables);
        $link = l('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 {$link} to see what memberships sample users would receive.

{$table}

EOT;
        $examples = t($examples, $tokens);
        return $examples;
    }
Ejemplo n.º 2
0
 /**
  * Get Group by name
  *
  * First looks inside this context's array of wrapped entities,
  * and if not found checks the site's database.
  *
  * @param $name - title of the group
  * @return EntityMetadataWrapper group or FALSE
  */
 public function getGroupByName($name)
 {
     if ($found_group = $this->entityStore->retrieve_by_name($name)) {
         return $found_group;
     }
     // In case the group was not created by 'Given groups',
     //  such as being created manually by form interaction,
     //  we fetch the group using entity_load
     $gids = og_get_all_group("node");
     foreach ($gids as $gid) {
         $groups = entity_load($this->entity_type, array($gid));
         foreach ($groups as $group) {
             if ($group->title == $name) {
                 return entity_metadata_wrapper('node', $group);
             }
         }
     }
     return FALSE;
 }
    /**
     * Get list of mappings based on existing Organic Groups and roles
     *
     * @param associative array $tokens of tokens and replacement values
     * @return html examples of mapping values
     */
    public function mappingExamples($tokens)
    {
        if ($this->ogVersion == 1) {
            $groups = og_get_all_group();
            $ogEntities = og_load_multiple($groups);
            $OGroles = og_roles(0);
            $rows = array();
            foreach ($ogEntities as $group) {
                foreach ($OGroles as $rid => $role) {
                    $example = "<code>ou=IT,dc=myorg,dc=mytld,dc=edu|gid=" . $group->gid . ',rid=' . $rid . '</code><br/>' . '<code>ou=IT,dc=myorg,dc=mytld,dc=edu|group-name=' . $group->label . ',role-name=' . $role . '</code>';
                    $rows[] = array($group->label, $group->gid, $role, $example);
                }
            }
            $variables = array('header' => array('Group Name', 'OG Group ID', 'OG Membership Type', 'example'), 'rows' => $rows, 'attributes' => array());
        } else {
            /**
             * 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 = array();
            $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));
                        // run the query as user 1
                        $result = $query->execute();
                        $entities = entity_load($entity_type, array_keys($result[$entity_type]));
                        $i = 0;
                        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[] = array("{$entity_type} {$title} - {$role_name}", $example);
                        }
                    }
                }
            }
            $variables = array('header' => array('Group Entity - Group Title - OG Membership Type', 'example'), 'rows' => $rows, 'attributes' => array());
        }
        $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 {$link} to see what memberships sample users would receive.

{$table}

EOT;
        $examples = t($examples, $tokens);
        return $examples;
    }
Ejemplo n.º 4
0
 /**
  * Return a list of all groups
  * 
  * @return Array          An array of MaestroCommonOgObject
  */
 public static function getAllGroups()
 {
     $group_array = array();
     self::getOGVersion();
     if (self::$ogVersion === self::OG_VERSION_1) {
         $og_gids = og_get_group_ids();
         foreach ($og_gids as $og_gid) {
             $og_group = og_load($og_gid);
             $group_array[] = new MaestroCommonOgObject($og_group->label, $og_gid);
         }
     } else {
         $og_group_ids = og_get_all_group('node');
         foreach ($og_group_ids as $og_group_id) {
             $og_group = node_load($og_group_id);
             $group_array[] = new MaestroCommonOgObject($og_group->title, $og_group_id);
         }
     }
     return $group_array;
 }