You are here

function word_link_get_link in Word Link 7

Same name and namespace in other branches
  1. 8 word_link.module \word_link_get_link()

Get links from DB.

Parameters

int $id: (optional) ID of a word.

array $header: (optional) header to build a table.

int $limit: (optional) determines the number of fields to get.

Return value

array Formatted array with links.

6 calls to word_link_get_link()
word_link_add_form in ./word_link.admin.inc
Form builder for add or edit page.
word_link_comment_view in ./word_link.module
Implements hook_comment_view().
word_link_exchange_export_form_submit in modules/word_link_exchange/word_link_exchange.module
Submit for export form.
word_link_list_page_form in ./word_link.admin.inc
Buid a Word Link list page.
word_link_node_view in ./word_link.module
Implements hook_node_view().

... See full list

File

./word_link.module, line 406
This module allows users to replace previously defined words to the links.

Code

function word_link_get_link($id = NULL, $header = array(), $limit = NULL) {
  $words = drupal_static(__FUNCTION__);
  $key = FALSE;

  // Get only one link by given id.
  if ($id) {
    $query = isset($words['id'][$id]) ? $words['id'][$id] : db_select('word_link', 'wl')
      ->fields('wl')
      ->condition('id', $id, '=')
      ->execute()
      ->fetchAll();
    $key = 'id_' . $id;
  }
  elseif (empty($id) && empty($header) && empty($limit)) {
    $query = isset($words['empty']) ? $words['empty'] : db_select('word_link', 'wl')
      ->fields('wl')
      ->execute()
      ->fetchAll();
    $key = 'empty';
  }
  else {
    $header_serialized = serialize($header);
    $query = isset($words['header'][$header_serialized]) ? $words['header'][$header_serialized] : ($query = db_select('word_link', 'wl')
      ->extend('PagerDefault')
      ->limit($limit)
      ->extend('TableSort')
      ->orderByHeader($header)
      ->fields('wl')
      ->execute()
      ->fetchAll());
    $key = 'header_' . $header_serialized;
  }
  $words[$key] = $query;
  $links = array();
  if (isset($words['ready'][$key])) {
    $links = $words['ready'][$key];
  }
  elseif (count($query) > 0) {
    foreach ($query as $value) {
      $links[$value->id] = $value;
    }
    $words['ready'][$key] = $links;
  }
  return $links;
}