You are here

function biblio_admin_keyword_orphans_form in Bibliography Module 7

Same name and namespace in other branches
  1. 6.2 includes/biblio.admin.inc \biblio_admin_keyword_orphans_form()
  2. 6 biblio.admin.inc \biblio_admin_keyword_orphans_form()
  3. 7.2 includes/biblio.admin.inc \biblio_admin_keyword_orphans_form()

_state

Parameters

$form:

Return value

multitypeNULL

1 string reference to 'biblio_admin_keyword_orphans_form'
biblio_menu in ./biblio.module
Implements hook_menu().

File

includes/biblio.admin.inc, line 2715
biblio.admin.inc

Code

function biblio_admin_keyword_orphans_form($form, $form_state) {
  $orphans = $keywords = $options = array();
  $base = variable_get('biblio_base', 'biblio');
  $header = array(
    'keyword' => t('Keyword'),
  );
  $query = db_select('biblio_keyword', 'bk');
  $active_kids = $query
    ->fields('bk', array(
    'kid',
  ))
    ->groupBy('kid')
    ->execute()
    ->fetchCol();
  $query = db_select('biblio_keyword_data', 'bkd');
  $all_kids = $query
    ->fields('bkd', array(
    'kid',
  ))
    ->groupBy('kid')
    ->execute()
    ->fetchCol();
  $orphans = array_diff($all_kids, $active_kids);
  if (count($orphans)) {
    $query = db_select('biblio_keyword_data', 'bkd')
      ->extend('PagerDefault')
      ->limit(50);

    // SELECT * FROM {biblio_contributor_data}.
    $query
      ->fields('bkd');
    $query
      ->condition('kid', $orphans, 'IN');

    // pager_query('SELECT * FROM {biblio_keyword_data} WHERE kid NOT IN (SELECT kid FROM {biblio_keyword} GROUP BY kid)', 50);.
    $result = $query
      ->execute();
    foreach ($result as $keyword) {
      $options[$keyword->kid] = array(
        'keyword' => array(
          'data' => array(
            '#type' => 'link',
            '#title' => $keyword->word,
            '#href' => $base . '/keywords/' . $keyword->kid . '/edit',
          ),
        ),
      );
    }
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Delete'),
    '#disabled' => !count($options),
    '#submit' => array(
      'biblio_admin_keyword_orphans_form_submit',
    ),
  );
  $form['words'] = array(
    '#type' => 'tableselect',
    '#header' => $header,
    '#options' => $options,
    '#empty' => t('No orphaned keywords.'),
  );
  $form['pager'] = array(
    '#markup' => theme('pager'),
  );
  return $form;
}