You are here

function quotes_get_quote in Quotes 7

Same name and namespace in other branches
  1. 5 quotes.module \quotes_get_quote()
  2. 6 quotes.module \quotes_get_quote()

Returns random quote or the most recent quote ID based on filter criteria.

Parameters

array $filters: The array specifying filter criteria to be passed to quotes_block_join_sql() and quotes_block_where_sql().

int $promoted_only: The boolean specifying whether or not only promoted quotes should be returned.

int $limit: The number of quotes to retrieve.

Return value

array An array of node IDs for quotes matching the specified criteria.

2 calls to quotes_get_quote()
quotes_block_view in ./quotes.module
Implements hook_block_view().
quotes_cron in ./quotes.module
Implements hook_cron().

File

./quotes.module, line 1812
The quotes module allows users to maintain a list of quotes that can be displayed in any number of administrator-defined quote blocks.

Code

function quotes_get_quote($filters = array(), $promoted_only, $limit = NULL) {
  if (empty($filters['block_type'])) {

    // Random block, see if we want to display it this time?
    if (isset($filters['rand_freq']) && $filters['rand_freq'] < 100) {

      // Check against a random number.
      if ($filters['rand_freq'] < rand(0, 100)) {

        // Nope, not this time.
        return array();
      }
    }
  }
  $q_snippet = 'n.status = ' . (int) ($filters['block_type'] != 2);
  $query = db_select('quotes', 'q');
  $n_alias = $query
    ->join('node', 'n', 'q.vid=n.vid');
  $query
    ->fields('n', array(
    'nid',
  ));
  quotes_block_join_sql($filters, $query);
  $query
    ->where($q_snippet)
    ->condition('n.type', 'quotes');
  if (!$promoted_only) {
    $query
      ->condition('q.promote', 1);
    quotes_block_where_sql($filters, $query);
  }
  if ($filters['block_type'] == 0) {
    $query
      ->orderRandom();

    /* Type=0 is random. */
  }
  else {
    $query
      ->orderBy('n.created', 'DESC');
  }
  $query
    ->range(0, $limit);
  return $result = $query
    ->execute()
    ->fetchCol();
}