You are here

function quotes_get_quote in Quotes 6

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

Returns the node ID for either a random quote or the most recent quote based on the provided filter criteria.

Parameters

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

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

$limit: The number of quotes to retrieve. Note that random quote blocks will only retrieve one quote.

Return value

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

2 calls to quotes_get_quote()
quotes_block_view in ./quotes.module
Build Quotes blocks.
quotes_cron in ./quotes.module
Implementation of hook_cron().

File

./quotes.module, line 1302
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 = 1) {
  if ($filters['block_type'] == 0) {

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

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

        // Nope, not this time.
        return array();
      }
    }
  }
  $query = 'SELECT n.nid FROM {quotes} q INNER JOIN {node} n ON q.vid=n.vid ' . quotes_block_join_sql($filters) . 'WHERE n.status=' . (int) ($filters['block_type'] != 2) . " AND n.type='quotes' AND " . ($promoted_only ? ' q.promote = 1 AND ' : '') . quotes_block_where_sql($filters) . ' ORDER BY ' . ($filters['block_type'] == 0 ? 'RAND()' : 'n.created DESC');

  /* Type=0 is random. */
  $query = db_rewrite_sql($query);
  $result = db_query_range($query, 0, $limit);
  $ret = array();
  while ($row = db_fetch_array($result)) {
    $ret[] = $row['nid'];
  }
  return $ret;
}