function _classified_block_view_recent in Classified Ads 7.3
Same name and namespace in other branches
- 6.3 classified.module \_classified_block_view_recent()
Implements hook_block() for ('view', 'recent').
File
- ./
classified.module, line 79 - A pure D7 classified ads module inspired by the ed_classified module.
Code
function _classified_block_view_recent() {
$limit = _classified_get('recent-count');
$vid = _classified_get('vid');
/** @var SelectQuery $q */
$q = db_select('node', 'n')
->comment(__FUNCTION__);
$q
->innerJoin('taxonomy_index', 'ti', 'n.nid = ti.nid');
$td = $q
->innerJoin('taxonomy_term_data', 'td', 'ti.tid = td.tid');
$results = $q
->fields('n', array(
'nid',
'title',
))
->fields($td, array(
'name',
))
->condition('n.status', 1)
->condition('n.type', 'classified')
->condition("{$td}.vid", $vid)
->orderBy('n.created', 'DESC')
->orderBy('n.changed', 'DESC')
->orderBy('n.title', 'ASC')
->addTag('node_access')
->range(0, $limit)
->execute();
$ads = array();
foreach ($results as $result) {
$title = t('!title (!category)', array(
'!title' => $result->title,
'!category' => $result->name,
));
$ads[] = l($title, 'node/' . $result->nid);
}
$ret = array(
'subject' => t('Recent ads'),
'content' => count($ads) ? array(
'#theme' => 'item_list__classified_recent',
'#items' => $ads,
) : array(
'#markup' => t('No ad viewed yet.'),
),
);
return $ret;
}