You are here

public static function MostPopularItem::fetch in Drupal Most Popular 6

Same name and namespace in other branches
  1. 7 classes/items.php \MostPopularItem::fetch()

Fetches the cached most popular items for the given service or interval.

Parameters

integer $sid: The service ID. If null, all services are used.

integer $iid: The interval ID. If null, all intervals are used.

Return value

array<MostPopularItem> An array of the most popular items, sorted by the number of times they appeared.

1 call to MostPopularItem::fetch()
mostpopular_get_items in ./mostpopular.block.inc
Gets a themed list of the most popular items for a given service and interval.

File

classes/items.php, line 76
Defines a wrapper for the mostpopular_items table.

Class

MostPopularItem
@file Defines a wrapper for the mostpopular_items table.

Code

public static function fetch($sid = NULL, $iid = NULL) {
  $where = array();
  $params = array();
  if (!empty($sid)) {
    $where[] = 'sid = %d';
    $params[] = $sid;
  }
  if (!empty($iid)) {
    $where[] = 'iid = %d';
    $params[] = $iid;
  }
  $sql = 'SELECT * FROM {' . self::$table . '}';
  if (count($where)) {
    $sql .= ' WHERE ' . implode(' AND ', $where);
  }
  $sql .= ' ORDER BY count DESC';
  $max = variable_get('mostpopular_max', 5);
  $result = db_query_range($sql, $params, 0, $max);
  $out = array();
  while ($row = db_fetch_object($result)) {
    $out[] = new MostPopularItem($row);
  }
  return $out;
}