You are here

function dynamic_background_random_image in Dynamic Background 7.2

Helper function that selects a random image based on extension (type).

Parameters

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

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

Return value

object An object with fid and uri to the image, if non was found FALSE is returned.

7 calls to dynamic_background_random_image()
DynamicBackgroundReaction::execute in modules/dynamic_background_context/plugins/dynamic_background_context_reaction.inc
Find the selected image and return its id.
dynamic_background_blog_dynamic_background_css in modules/dynamic_background_blog/dynamic_background_blog.module
Implements hook_dynamic_background_css().
dynamic_background_dynamic_background_css in ./dynamic_background.module
Implements hook_dynamic_background_css().
dynamic_background_node_dynamic_background_css in modules/dynamic_background_node/dynamic_background_node.module
Implements hook_dynamic_background_css().
dynamic_background_panels_dynamic_background_css in modules/dynamic_background_panels/dynamic_background_panels.module
Implements hook_dynamic_background_css().

... See full list

File

./dynamic_background.module, line 813
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_random_image($extension = 'default', $data = FALSE) {
  $query = db_select('dynamic_background_images', 'dbi');
  $query
    ->join('file_managed', 'fm', 'dbi.fid = fm.fid');
  $query
    ->fields('dbi', array(
    'fid',
  ))
    ->fields('fm', array(
    'uri',
  ));

  // If data is set, select user uploaded images and default images.
  if ($data) {
    $query
      ->condition('dbi.extension', array(
      'default',
      $extension,
    ), 'IN')
      ->condition('data', array(
      '-1',
      $data,
    ), 'IN');
  }
  else {
    $query
      ->condition('dbi.extension', $extension, '=')
      ->condition('data', '-1', '=');
  }

  // Find one random image.
  $query
    ->orderRandom();
  $query
    ->range(0, 1);
  return $query
    ->execute()
    ->fetchObject();
}