You are here

function view_custom_table_delete_custom_table_to_view_callback in Views Custom Table 7

Function to delete a custom table form views.

1 string reference to 'view_custom_table_delete_custom_table_to_view_callback'
view_custom_table_menu in ./view_custom_table.module
Implements hook_menu().

File

./view_custom_table.admin.inc, line 493
File for administrative functions.

Code

function view_custom_table_delete_custom_table_to_view_callback($table_id) {
  if ($table_id == NULL) {
    return "<h3 style='text-align: center;'>Table id not found in records.</h3>";
  }
  $query = db_select('custom_table_view_data', 'ctvd')
    ->fields('ctvd', array(
    'table_name',
  ))
    ->condition('id', $table_id);
  $table_name = $query
    ->execute()
    ->fetchField();
  if ($table_name == NULL) {
    return "<h3 style='text-align: center;'>Table id not found in records.</h3>";
  }
  else {
    $query = db_select('views_view', 'v')
      ->fields('v', array(
      'vid',
      'human_name',
      'name',
    ))
      ->condition('base_table', $table_name);
    $views_in_uses = $query
      ->execute()
      ->fetchAll();
    if (!empty($views_in_uses)) {
      foreach ($views_in_uses as $view_info) {
        $rows[] = array(
          $view_info->vid,
          $view_info->human_name,
          l(t('View'), 'admin/structure/views/view/' . $view_info->name . '/edit'),
        );
      }
      $headers = array(
        "Vid",
        "Name",
        "View",
      );
      drupal_set_message(t('Can not delete "@tablename". Following views are using "@tablename".', array(
        '@tablename' => $table_name,
      )), 'error');
      $output = l(t('Return to list'), 'admin/structure/views/custom_table');
      $output .= '<p></p>';
      $output .= theme('table', array(
        'header' => $headers,
        'rows' => $rows,
      ));
      return $output;
    }
    else {
      $delete_form = drupal_get_form('view_custom_table_delete_custom_table_to_view_form', $table_name);
      return render($delete_form);
    }
  }
}