public static function MostPopularItem::fetch in Drupal Most Popular 7
Same name and namespace in other branches
- 6 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.
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;
}