You are here

function _classified_page_term in Classified Ads 7.3

Same name and namespace in other branches
  1. 6.3 classified.module \_classified_page_term()

Page callback for classified/<tid>.

Unlike the standard taxonomy term page, this one only accepts one term from the module vocabulary, and builds a breadcrumb trail based on the tree assumption for that vocabulary. It does NOT honor the sticky flag, the expiration date taking priority over it.

Parameters

object $term: A fully loaded term used as a Classified Ads category to list.

Return value

array Render array for the ads listing.

See also

classified_term_load()

1 string reference to '_classified_page_term'
classified_menu in ./classified.module
Implements hook_menu().

File

./classified.module, line 562
A pure D7 classified ads module inspired by the ed_classified module.

Code

function _classified_page_term($term) {
  $bc = _classified_get_breadcrumb_by_term($term, FALSE);
  drupal_set_breadcrumb($bc);
  unset($bc);
  $ret = array();
  $children = taxonomy_get_children($term->tid);
  $children_list = array();
  foreach ($children as $child_tid => $child_term) {
    $q = new EntityFieldQuery();
    $count = $q
      ->entityCondition('entity_type', 'node', '=')
      ->entityCondition('bundle', 'classified')
      ->fieldCondition('classified_category', 'tid', $child_tid, '=', 0)
      ->count()
      ->execute();
    $children_list[] = t('!link (@count)', array(
      '!link' => l($child_term->name, classified_term_path($child_term)),
      '@count' => $count,
    ));
  }
  unset($child_tid, $child_term, $children, $count, $q);
  if (!empty($children_list)) {
    $ret['children'] = array(
      '#markup' => t('<p>Sub-categories: !cats<p>', array(
        '!cats' => implode(' ', $children_list),
      )),
    );
  }

  /** @var SelectQuery $q */
  $q = db_select('node', 'n');
  $q
    ->comment(__FUNCTION__);

  /** @var PagerDefault $q */
  $q = $q
    ->extend('PagerDefault');
  $q
    ->limit(10);
  $cn = $q
    ->innerJoin('classified_node', 'cn', 'n.vid = cn.vid');
  $ti = $q
    ->innerJoin('taxonomy_index', 'ti', 'n.nid = ti.nid');
  $q
    ->addField('n', 'nid', 'id');
  $q
    ->condition('n.type', 'classified')
    ->condition("{$ti}.tid", $term->tid)
    ->orderBy("{$cn}.expires")
    ->orderBy("n.changed")
    ->orderBy('n.created')
    ->addTag('node_access');
  $results = $q
    ->execute();
  unset($cn, $q);
  $ret['list'] = _classified_list_nodes($results);
  $ret['pager'] = array(
    '#theme' => 'pager',
  );
  return $ret;
}