You are here

function _classified_list_nodes in Classified Ads 7.3

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

Prepare a node listing from a DB query resource.

Parameters

resource $results: A PDO results set returning node ids within objects.

Return value

array A render array for the listing.

3 calls to _classified_list_nodes()
classified_tokens in ./classified.tokens.inc
Implements hook_tokens().
_classified_page_term in ./classified.module
Page callback for classified/<tid>.
_classified_page_user_ads in ./classified.module
Page callback for user/<uid>/classified.

File

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

Code

function _classified_list_nodes($results) {
  $rows = array();
  $now = REQUEST_TIME;
  $list_body = _classified_get('list-body');
  $node_ids = array();
  foreach ($results as $result) {
    $node_ids[] = $result->id;
  }
  $date_format = _classified_get('date-format');
  switch ($list_body) {
    case 'empty':
    case 'body':
      $header = array(
        t('Contents'),
        t('Expires'),
      );
      break;
    case 'node':
    default:
      $header = NULL;
  }
  $nodes = node_load_multiple($node_ids);
  foreach ($nodes as $node) {
    switch ($list_body) {
      case 'empty':
        $cell = l($node->title, 'node/' . $node->nid);
        $row = array(
          $cell,
          strftime($date_format, $node->expires),
        );
        break;
      case 'body':
        $body_items = field_get_items('node', $node, 'body');
        $cell = array(
          'data' => array(
            'title' => array(
              '#markup' => l($node->title, 'node/' . $node->nid, array(
                'attributes' => array(
                  'class' => 'classified-list-title',
                ),
              )),
            ),
          ),
        );
        if (!empty($body_items)) {

          // Assume a single body item.
          $body_field = reset($body_items);
          $cell['data']['body'] = array(
            '#prefix' => '<span class="classified-list-teaser">',
            '#markup' => filter_xss(text_summary($body_field['value'], $body_field['format'])),
            '#suffix' => '</span>',
          );
        }
        $row = array(
          $cell,
          strftime($date_format, $node->expires),
        );
        break;
      case 'node':
        $cell = array(
          'data' => node_view($node, 'classified'),
        );
        $row = array(
          $cell,
        );
        break;

      // Should not happen.
      default:
        $row = array();
    }
    if ($list_body != 'node' && $node->expires < $now) {
      foreach ($row as $index => $cell) {
        $row[$index] = array(
          'data' => $cell,
          'class' => 'node-unpublished',
        );
      }
    }
    $rows[] = $row;
  }
  $ret = array(
    '#theme' => 'table',
    '#header' => $header,
    '#rows' => $rows,
  );
  return $ret;
}