You are here

function reviews_get_reviews_block in Reviews 7

Helper function to return content for Reviews block.

1 call to reviews_get_reviews_block()
reviews_block_view in ./reviews.module
Implements hook_block_view().

File

./reviews.module, line 319
This file defines all the necessary hooks and functions to create a system for enabling and authoring content reviews on a per content type basis.

Code

function reviews_get_reviews_block() {
  $path = $_GET['q'];
  if (drupal_match_path($path, "node/*")) {
    $nid = arg(1);

    // Get the sort order for reviews.
    if (variable_get('reviews_sort_order', 0) == 0) {
      $sort = 'ASC';
    }
    else {
      $sort = 'DESC';
    }
    $reviews = db_select('reviews', 'r')
      ->fields('r')
      ->condition('nid', $nid, '=')
      ->condition('status', 1, '=')
      ->orderBy('created', $sort)
      ->range(0, 5)
      ->execute()
      ->fetchAll();
    if (count($reviews) != 0) {
      return theme('block_reviews', array(
        'nid' => $nid,
        'reviews' => $reviews,
      ));
    }
    else {
      return '';
    }
  }
  else {
    return '';
  }
}