You are here

function dynamic_background_set_active in Dynamic Background 7.2

Helper function that sets the active image for the context created by the parameters passed.

Parameters

int $fid: File id.

string $type: The extension that the image should be locationed under.

string $data: Identifier defined by the extension that the image should be located under.

9 calls to dynamic_background_set_active()
DynamicBackgroundReaction::options_form_submit in modules/dynamic_background_context/plugins/dynamic_background_context_reaction.inc
Options form submit handler.
dynamic_background_admin_images_submit in includes/backgrounds.admin.inc
Administration images form submittion handler.
dynamic_background_blog_form_submit in modules/dynamic_background_blog/dynamic_background_blog.module
Submit handler for user background selection and saves the selected image's id into the database.
dynamic_background_context_update_7000 in modules/dynamic_background_context/dynamic_background_context.install
Update stored data to use the new database tables.
dynamic_background_node_node_delete in modules/dynamic_background_node/dynamic_background_node.module
Implements hook_node_delete().

... See full list

File

./dynamic_background.module, line 982
This module enables administrators to upload images used as background on the site. The selected background image link is exposed as either $background in the page.tpl file or as /background.css.

Code

function dynamic_background_set_active($fid, $type = 'default', $data = -1) {

  // Check if active image allready exists, if so run delete old entry.
  $query = db_select('dynamic_background_usage', 'dbu');
  $query
    ->fields('dbu', array(
    'id',
  ))
    ->condition('type', $type)
    ->condition('data', $data);
  $result = $query
    ->execute()
    ->fetchField();
  if ($result) {

    // Delete old entry.
    db_delete('dynamic_background_usage')
      ->condition('id', $result)
      ->execute();
  }

  // Insert image.
  if (!is_null($fid)) {
    db_insert('dynamic_background_usage')
      ->fields(array(
      'fid' => $fid,
      'type' => $type,
      'data' => $data,
    ))
      ->execute();
  }
}