You are here

function user_dashboard_user_insert in UserDashboard 7

Implements hook_user_insert().

Sets default user dashboard blocks if they are defined.

File

./user_dashboard.module, line 107
The User Dashboard module forks Drupal 7's awesome Dashboard module to provide an individual dashboard for each user on the site.

Code

function user_dashboard_user_insert(&$edit, $account, $category) {
  $default = variable_get('user_dashboard_default_blocks', array());
  $available = variable_get('user_dashboard_available_blocks', array());
  if (!empty($default)) {
    foreach ($default as $block) {

      // Make sure the block is still available.
      if (in_array($block->module . '_' . $block->delta, $available)) {

        // Make sure the block still actually exists.
        $data = db_select('block', 'b')
          ->fields('b')
          ->condition('theme', $block->theme)
          ->condition('module', $block->module)
          ->condition('delta', $block->delta)
          ->execute()
          ->fetchAssoc();
        if ($data) {
          db_merge('user_dashboard_block')
            ->key(array(
            'module' => $block->module,
            'delta' => $block->delta,
            'theme' => $block->theme,
            'uid' => $account->uid,
          ))
            ->fields(array(
            'status' => $block->status,
            'weight' => $block->weight,
            'region' => $block->region,
            'pages' => '',
            'uid' => $account->uid,
          ))
            ->execute();
        }
      }
    }
  }
}