You are here

function workbench_access_user_load_data in Workbench Access 7

Load the access data for this user.

Parameters

$account: The user account object.

Return value

No return. Add the workbench_access attribute by reference.

8 calls to workbench_access_user_load_data()
workbench_access_form_alter in ./workbench_access.module
Implements hook_form_alter().
workbench_access_get_access_tree in ./workbench_access.module
Get the access hierarchy for a user.
workbench_access_get_user_tree in ./workbench_access.module
Build an access tree for a user account.
workbench_access_handler_filter_access::query in includes/workbench_access_handler_filter_access.inc
Add this filter to the query.
workbench_access_query_term_access_alter in modules/taxonomy.workbench_access.inc
Implements hook_query_TAG_alter().

... See full list

3 string references to 'workbench_access_user_load_data'
workbench_access_reset_tree in ./workbench_access.module
Reset tree data stored in statics.
workbench_access_user_section_delete in ./workbench_access.module
Deletes an access rule from the {workbench_access_user} table.
workbench_access_user_section_save in ./workbench_access.module
Save a user access record and notify other modules.

File

./workbench_access.module, line 804
Workbench Access module file.

Code

function workbench_access_user_load_data($account) {
  $access = array();
  $access_scheme = variable_get('workbench_access');
  $active = workbench_access_get_active_tree();

  // There must be active sections, and the user must be allowed to use one.
  if (!empty($active['tree']) && user_access('access workbench access by role', $account)) {

    // Get the user's assigned access sections.
    $query = db_select('workbench_access_user', 'wau')
      ->addTag('workbench_access_user')
      ->fields('wau', array(
      'access_id',
    ))
      ->condition('wau.uid', $account->uid)
      ->condition('wau.access_scheme', $access_scheme);
    $result = $query
      ->execute()
      ->fetchAll();
    $items = array();
    foreach ($result as $data) {
      $items[$data->access_id] = $data;
    }

    // Add roles.
    $query = db_select('workbench_access_role', 'war')
      ->addTag('workbench_access_role')
      ->fields('war', array(
      'access_id',
    ))
      ->condition('war.rid', array_keys($account->roles), 'IN')
      ->condition('war.access_scheme', $access_scheme);
    $result = $query
      ->execute()
      ->fetchAll();
    $account->workbench_access_by_role = array();
    foreach ($result as $data) {

      // If the role is set it matches a role the user has and does not need to
      // be added again, but we should still track it.
      if (!isset($items[$data->access_id])) {
        $items[$data->access_id] = $data;
      }

      // Identify the access-by-role features. These can be duplicated for
      // users with multiple roles.
      if (!isset($account->workbench_access_by_role[$data->access_id])) {
        $account->workbench_access_by_role[$data->access_id] = $data->access_id;
      }
    }
    foreach ($items as $item) {
      if (!in_array($item->access_id, array_keys($active['tree']))) {
        continue;
      }

      // Get the permissions for those sections.
      // @TODO: complex permission handling.
      $access[$item->access_id] = array(
        'view' => array(
          'all',
        ),
        'create' => array(
          'all',
        ),
        'update' => array(
          'all',
        ),
        'delete' => array(
          'all',
        ),
        'preview' => array(
          'all',
        ),
        'revise' => array(
          'all',
        ),
        'publish' => array(
          'all',
        ),
      );
    }
  }

  // Allow modules to alter the default behavior.
  drupal_alter('workbench_access_user', $access, $account);
  $account->workbench_access = $access;
}