You are here

function _classified_block_view_recent in Classified Ads 6.3

Same name and namespace in other branches
  1. 7.3 classified.module \_classified_block_view_recent()

Implements hook_block('view', 'recent').

Return value

array A block description array.

File

./classified.module, line 83
A pure D6 classified ads module inspired by the ed_classified module.

Code

function _classified_block_view_recent() {
  $limit = _classified_get('recent-count');
  $vid = _classified_get('vid');
  $sq = <<<EOT
    SELECT n.nid, n.title,
      td.name
    FROM {node} n
      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
      n.created DESC, n.changed DESC, n.title ASC
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('Recent ads'),
    'content' => count($ads) ? theme('item_list', $ads) : t('No ad viewed yet.'),
  );
  return $ret;
}