/**
  * Return all user authorization ids (group x role) in form gid-rid such as 2-1.
  *   regardless of it they were granted by this module, any authorization ids should be returned.
  *
  * @param user object $user
  * @return array such as array('3-2','7-2')
  */
 public function usersAuthorizations(&$user)
 {
     $authorizations = array();
     if ($this->ogVersion == 1) {
         $groups = og_load_multiple(og_get_all_group());
         $authorizations = array();
         if (is_object($user) && is_array($groups)) {
             foreach ($groups as $gid => $discard) {
                 $roles = og_get_user_roles($gid, $user->uid);
                 foreach ($roles as $rid => $discard) {
                     $authorizations[] = ldap_authorization_og_authorization_id($gid, $rid);
                 }
             }
         }
     } else {
         // og 7.x-2.x
         $user_entities = entity_load('user', array($user->uid));
         $memberships = og_get_entity_groups('user', $user_entities[$user->uid]);
         foreach ($memberships as $entity_type => $entity_memberships) {
             foreach ($entity_memberships as $og_membership_id => $gid) {
                 $roles = og_get_user_roles($entity_type, $gid, $user->uid);
                 foreach ($roles as $rid => $discard) {
                     $authorizations[] = ldap_authorization_og_authorization_id($gid, $rid, $entity_type);
                 }
             }
         }
     }
     return $authorizations;
 }
Beispiel #2
0
/**
 * Implements hook_preprocess_node().
 */
function platon_preprocess_node(&$vars)
{
    $vars['base_path'] = base_path();
    if (defined('OPIGNO_COURSE_BUNDLE') && !empty($vars['node']->type) && in_array($vars['node']->type, array(OPIGNO_COURSE_BUNDLE, 'class'))) {
        $vars['content']['fields'] = array('#weight' => -100, '#prefix' => '<div class="node-course-other-fields node-course-more-info">', '#suffix' => '</div>');
        $i = 0;
        foreach ($vars['content'] as $key => $item) {
            if (!in_array($key, array('body', 'opigno_course_tools')) && !empty($item['#theme']) && $item['#theme'] === 'field') {
                $vars['content']['fields'][$i][$key] = $item;
                $i++;
                unset($vars['content'][$key]);
            }
        }
        // HACKY - add CSS classes based on roles :-S
        // This is absolutely horrible, but there's just too much pressure
        // to get this out the door quickly :-(. It pains me.
        $roles = og_get_user_roles('node', $vars['node']->nid);
        foreach ($roles as $role) {
            $vars['classes_array'][] = str_replace(' ', '-', $role);
        }
        if (user_access('administer nodes')) {
            $vars['classes_array'][] = 'is-admin';
        }
    }
    if (module_exists('quiz') && $vars['node']->type == 'quiz') {
        global $user;
        $vars['passed_quiz'] = _platon_check_user_passed_quiz($vars['node'], $user);
    }
}
 /**
  * @see ldapAuthorizationConsumerAbstract::usersAuthorizations
  */
 public function usersAuthorizations(&$user, $reset = FALSE, $return_data = TRUE)
 {
     static $users;
     if (!is_array($users)) {
         $users = array();
         // no cache exists, create static array
     } elseif ($reset && isset($users[$user->uid])) {
         unset($users[$user->uid]);
         // clear users cache
     } elseif (!$return_data) {
         return NULL;
         // simply clearing cache
     } elseif (!empty($users[$user->uid])) {
         return $users[$user->uid];
         // return cached data
     }
     $authorizations = array();
     if ($this->ogVersion == 1) {
         $gids = og_get_groups_by_user($user);
         foreach ($gids as $i => $gid) {
             $roles = og_get_user_roles($gid, $user->uid);
             if (!empty($roles[$this->defaultMembershipRid])) {
                 // if you aren't a member, doesn't matter what roles you have in og 1.5
                 if (isset($roles[$this->anonymousRid])) {
                     unset($roles[$this->anonymousRid]);
                 }
                 // ignore anonymous role
                 $rids = array_values($roles);
                 asort($rids, SORT_NUMERIC);
                 // go low to high to get default memberships first
                 foreach ($rids as $rid) {
                     $authorizations[] = ldap_authorization_og_authorization_id($gid, $rid);
                 }
             }
         }
     } else {
         // og 7.x-2.x
         $user_entities = entity_load('user', array($user->uid));
         $memberships = og_get_entity_groups('user', $user_entities[$user->uid]);
         foreach ($memberships as $entity_type => $entity_memberships) {
             foreach ($entity_memberships as $og_membership_id => $gid) {
                 $roles = og_get_user_roles($entity_type, $gid, $user->uid);
                 foreach ($roles as $rid => $discard) {
                     $authorizations[] = ldap_authorization_og_authorization_id($gid, $rid, $entity_type);
                 }
             }
         }
     }
     $users[$user->uid] = $authorizations;
     return $authorizations;
 }
Beispiel #4
0
 /**
  * Get the role of a user in a group.
  *
  *  @return
  *    0 - if user is not a member of the group.
  *    1 - user has a role which is not the role given.
  *    2 - user has the role given
  */
 public static function checkUserRoleInGroup($name, $role, $group)
 {
     drupal_static_reset();
     $gid = self::GetNodeId($group);
     $user = user_load_by_name($name);
     if (!og_is_member('node', $gid, 'user', $user)) {
         return 1;
     }
     $user_roles = og_get_user_roles('node', $gid, $user->uid);
     return !in_array($role, $user_roles) ? 1 : 2;
 }