function quotes_get_quote in Quotes 5
Same name and namespace in other branches
- 6 quotes.module \quotes_get_quote()
 - 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 in ./
quotes.module  - Implementation of hook_block().
 - quotes_cron in ./
quotes.module  - Implementation of hook_cron().
 
File
- ./
quotes.module, line 1277  
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 (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();
      }
    }
  }
  $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. */
  $result = db_query_range(db_rewrite_sql($query), 0, $limit);
  $ret = array();
  while ($row = db_fetch_array($result)) {
    $ret[] = $row['nid'];
  }
  return $ret;
}