You are here

function _homebox_save_user_settings in Homebox 6.2

Same name and namespace in other branches
  1. 6.3 homebox.module \_homebox_save_user_settings()
  2. 7.3 homebox.module \_homebox_save_user_settings()
  3. 7.2 homebox.module \_homebox_save_user_settings()

Save the user's page settings

Parameters

$page: A page object

$blocks: An array representing the user's page settings

4 calls to _homebox_save_user_settings()
homebox_add_block in ./homebox.module
Add a custom block to a user's page.
homebox_block_edit_form_builder_submit in ./homebox.module
Save settings for the block and render a replacement with the updated settings.
homebox_save_form_submit in ./homebox.module
_homebox_get_user_settings in ./homebox.module
Fetch user page settings, if they exist.

File

./homebox.module, line 1431
Homebox main file, takes care of global functions settings constants, etc.

Code

function _homebox_save_user_settings($page, $blocks) {

  // This function is only called after user status
  // and perms were checked
  global $user;
  $user_blocks = _homebox_get_user_settings($page);
  $i = 0;
  foreach ($blocks as $key => $value) {

    // Add weights to blocks
    $blocks[$key]['weight'] = ++$i;

    // Carry over existing settings
    if (isset($page->settings['blocks'][$key])) {
      $blocks[$key] = homebox_merge_settings($page->settings['blocks'][$key], $blocks[$key]);
    }
    if ($user_blocks !== FALSE && isset($user_blocks[$key])) {
      $blocks[$key] = homebox_merge_settings($user_blocks[$key], $blocks[$key]);
    }
  }
  if ($user_blocks !== FALSE) {

    // Preserve any existing user blocks, which are page blocks, and not already
    // saved above. These are disabled page defaults, and need to remain to
    // continue overriding the page default.
    foreach (array_intersect_key($user_blocks, array_diff_key($page->settings['blocks'], $blocks)) as $key => $value) {
      $blocks[$key] = $value;
    }
  }

  // Remove any old settings
  db_query("DELETE FROM {homebox_users} WHERE uid = %d AND name = '%s'", $user->uid, $page->name);

  // Update settings
  $data->uid = $user->uid;
  $data->name = $page->name;
  $data->settings = $blocks;
  drupal_write_record('homebox_users', $data);
  _homebox_get_user_settings($page, FALSE, TRUE);
}