You are here

function quotes_author in Quotes 7

Same name and namespace in other branches
  1. 5 quotes.module \quotes_author()
  2. 6 quotes.module \quotes_author()

Menu callback that selects quotes based on author.

Parameters

string $author: The name of the author of the quotes.

Return value

array A renderable array to display a page of quotes by author.

1 call to quotes_author()
quotes_page in ./quotes.module
Menu callback that displays a page of quotes restricted to a certain user.
1 string reference to 'quotes_author'
quotes_load in ./quotes.module
Implements hook_load().

File

./quotes.module, line 2047
The quotes module allows users to maintain a list of quotes that can be displayed in any number of administrator-defined quote blocks.

Code

function quotes_author($author = NULL) {

  // Get a count of our authors.
  $count = db_query("SELECT COUNT(*) FROM {quotes_authors}")
    ->fetchField();

  // Only one author present, display their quotes.
  if ($count == 1) {
    $author = $count;
  }

  // Check to see if we want to find an anthor.
  if ($author === "- FIND -") {
    return drupal_get_form('quotes_author_form');
  }
  if ($author === 0 || $author === t('unspecified')) {
    $aid = 0;
    $auth = array(
      'name' => $author,
      'bio' => '',
    );
  }
  else {

    // See whether we have a name or an id.
    if (is_numeric($author)) {
      $aid = $author;
      $auth = db_query("SELECT name, bio FROM {quotes_authors} WHERE aid = :aid", array(
        ':aid' => $aid,
      ))
        ->fetchAssoc();
      $author = $auth['name'];
    }
    else {
      $auth = db_query("SELECT aid, bio FROM {quotes_authors} WHERE name = :author", array(
        ':author' => $author,
      ))
        ->fetchAssoc();
      $aid = $auth['aid'];
    }
    if (!$aid) {

      // Unspecified author.
      drupal_set_message(t("I couldn't locate that author."));
      return drupal_get_form('quotes_author_form');
    }
  }

  // Get the format for author and citation.
  $format = variable_get('quotes_format', filter_default_format());
  $build = array();
  variable_set('quotes_bio_set', FALSE);
  $limit = variable_get('quotes_per_page', 10);
  $menu_info = menu_get_item('quotes');
  $menu_title = $menu_info['title'];
  if (!$author) {
    $author = 'Unknown Authors';
  }
  drupal_set_title(decode_entities(t('!menu by !name', array(
    '!menu' => $menu_title,
    '!name' => $author,
  ))), PASS_THROUGH);
  $sql = db_select('node', 'n')
    ->extend('PagerDefault');
  $nr_alias = $sql
    ->join('node_revision', 'nr', 'nr.vid = n.vid');
  $q_alias = $sql
    ->join('quotes', 'q', 'q.vid = nr.vid');
  $sql
    ->fields('n', array(
    'nid',
  ))
    ->condition('q.aid', $aid)
    ->condition('nr.status', '1')
    ->condition('n.type', 'quotes')
    ->orderBy('nr.sticky', 'DESC')
    ->orderBy('n.created', 'DESC')
    ->addTag('node_access');
  $result = $sql
    ->limit($limit)
    ->execute()
    ->fetchCol();
  if (!empty($result)) {
    $nodes = node_load_multiple($result);

    // Undo sticky flag.
    foreach ($nodes as $node) {
      if ($node->sticky) {
        $node->sticky = 0;
      }
    }
    $build['quotes_list'][] = node_view_multiple($nodes, $view_mode = 'full', $language = NULL);
    $build['pager'] = array(
      '#theme' => 'pager',
      '#weight' => 5,
    );
  }
  else {
    if (isset($account)) {
      if (!$account) {
        drupal_set_message(t('No quotes have been created.'));
      }
      elseif (isset($account) && $account->uid == $user->uid) {
        drupal_set_message(t('You have not created any quotes.'));
      }
    }
  }
  return $build;
}