function _classified_block_view_popular in Classified Ads 6.3
Same name and namespace in other branches
- 7.3 classified.module \_classified_block_view_popular()
Implements hook_block('view', 'popular').
Return value
array A block description array.
File
- ./
classified.module, line 32 - A pure D6 classified ads module inspired by the ed_classified module.
Code
function _classified_block_view_popular() {
if (!module_exists('statistics')) {
$ret = NULL;
}
else {
$limit = _classified_get('popular-count');
$vid = _classified_get('vid');
$sq = <<<EOT
SELECT n.nid, n.title,
td.name
FROM {node} n
LEFT JOIN {node_counter} s ON n.nid = s.nid
INNER JOIN {term_node} tn ON n.vid = tn.vid
INNER JOIN {term_data} td ON tn.tid = td.tid
WHERE
n.status = 1 AND n.type = '%s'
AND td.vid = %d
ORDER BY
s.totalcount DESC, s.daycount DESC,
n.title ASC, n.created ASC, n.nid DESC
EOT;
$sq = db_rewrite_sql($sq);
$q = db_query_range($sq, 'classified', $vid, 0, $limit);
$ads = array();
while ($result = db_fetch_object($q)) {
$title = t('!title (!category)', array(
'!title' => $result->title,
'!category' => $result->name,
));
$ads[] = l($title, 'node/' . $result->nid);
}
$ret = array(
'subject' => t('Popular ads'),
'content' => count($ads) ? theme('item_list', $ads) : t('No ad viewed yet.'),
);
}
return $ret;
}