You are here

function kwresearch_keyword_pages_page in Keyword Research 7

Same name and namespace in other branches
  1. 6 kwresearch.admin.inc \kwresearch_keyword_pages_page()

Generates table of pages assoicated with a keyword

Parameters

int $kid:

1 string reference to 'kwresearch_keyword_pages_page'
kwresearch_menu in ./kwresearch.module
Implements hook_menu()

File

./kwresearch.admin.inc, line 616
Admin include file.

Code

function kwresearch_keyword_pages_page($kid) {
  drupal_add_css(drupal_get_path('module', 'kwresearch') . '/kwresearch.css');
  drupal_set_title('Keyword pages');
  $keyword_obj = kwresearch_load_site_keyword($kid);
  $output = '<label>' . t('Keyword:') . '</label>' . t(' @keyword', array(
    '@keyword' => $keyword_obj->keyword,
  ));
  $rows = array();

  //dsm($filter);
  $header = array(
    array(
      'data' => t('Page'),
      'field' => 'k.page',
    ),
    array(
      'data' => t('Nid'),
      'field' => 'pk.nid',
    ),
    array(
      'data' => t('Page priority'),
      'field' => 'pk.priority',
      'sort' => 'desc',
    ),
    array(
      'data' => t('Operations'),
    ),
  );
  $query = db_select('kwresearch_page_keyword', 'pk')
    ->fields('pk')
    ->condition('kid', $kid)
    ->extend('PagerDefault')
    ->limit(100)
    ->extend('TableSort')
    ->orderByHeader($header);
  $result = $query
    ->execute();

  /*
  $sql = '
    SELECT pk.*
    FROM {kwresearch_page_keyword} pk
    WHERE kid = %d
  ';
  $tablesort = tablesort_sql($header);
  $sql = $sql . $tablesort;
  $result = pager_query($sql, 100, 0, NULL, $kid);
  */
  $lo = array(
    'attributes' => array(
      'query' => array(
        'destination' => 'destination=admin/structure/kwresearch/keywords_pages',
      ),
    ),
  );
  $priorities = kwresearch_get_priority_options();
  while ($r = $result
    ->fetchObject()) {
    if (!$r->path && $r->nid) {
      $r->path = 'node/' . $r->nid;
    }
    $rows[] = array(
      'data' => array(
        // Cells
        l(drupal_get_path_alias($r->path), $r->path),
        l($r->nid, 'node/' . $r->nid),
        $priorities[$r->priority],
        l(t('keywords'), 'admin/structure/kwresearch/page_keywords/' . $r->nid, $lo),
      ),
      // Attributes for tr
      'class' => array(
        "kwresearch",
      ),
    );
  }
  if (!$rows) {
    $msg = t('No pages are associated with this keyword.');
    $rows[] = array(
      array(
        'data' => $msg,
        'colspan' => count($header),
      ),
    );
  }
  $vars = array(
    'header' => $header,
    'rows' => $rows,
    'attributes' => array(
      'id' => 'kwresearch-site-keywords',
    ),
  );
  $output .= theme('table', $vars);
  $types = node_type_get_types();
  $output .= t('!add', array(
    '!add' => l('+Add content', 'node/add'),
  ));
  if (!empty($types['enterprise_blog'])) {
    $output .= ' ' . t('!add', array(
      '!add' => l('+Add blog post', 'node/add/enterprise-blog', array(
        'query' => array(
          'kwresearch_page_kid' => $kid,
        ),
      )),
    ));
  }

  //$output .= theme('pager', array('tags' => NULL, 'element' => 0));
  return $output;
}