You are here

function reviews_get_reviews in Reviews 7

Gather reviews for current displayed node and pass to theming function.

1 string reference to 'reviews_get_reviews'
reviews_menu in ./reviews.module
Implements hook_menu().

File

includes/reviews.pages.inc, line 12
This file contain all function necessary for displaying and leaving reviews.

Code

function reviews_get_reviews($nid) {
  $reviews_count = reviews_reviews_count($nid);
  $pending_count = reviews_reviews_pending_count($nid);
  if ($reviews_count == 0) {
    return theme('reviews_no_reviews', array(
      'nid' => $nid,
    ));
  }

  // Get the sort order for reviews.
  if (variable_get('reviews_sort_order', 0) == 0) {
    $sort = 'ASC';
  }
  else {
    $sort = 'DESC';
  }
  if (user_access('administer reviews')) {
    $operand = '<=';
  }
  else {
    $operand = '=';
  }

  // Get the reviews from the database.
  $reviews = db_select('reviews', 'r')
    ->extend('PagerDefault')
    ->fields('r')
    ->condition('nid', $nid, '=')
    ->condition('status', 1, $operand)
    ->orderBy('created', $sort);

  // Change this number to amount of reviews you want per page.
  $page_size = variable_get('reviews_per_page', 0);
  if ($page_size == 0) {
    $page_size = 25000;
  }
  $result = $reviews
    ->limit($page_size)
    ->execute();
  return theme('reviews', array(
    'nid' => $nid,
    'review_count' => $reviews_count,
    'pending_count' => $pending_count,
    'reviews' => $result,
    'pager' => array(
      '#theme' => 'pager',
    ),
  ));
}