You are here

function panels_views_list_views in Panels 5.2

Page callback to list view panes and the initial form to add new view panes.

1 string reference to 'panels_views_list_views'
panels_views_menu in panels_views/panels_views.module
Implementation of hook_menu().

File

panels_views/panels_views.module, line 102
panels_views.module

Code

function panels_views_list_views() {

  // Run the form first as it may redirect; no point in doing the rest of
  // the work if it does.
  $form = drupal_get_form('panels_views_add_view_form');
  $items = array();
  $sorts = array();
  $header = array(
    array(
      'data' => t('Title'),
      'field' => 'title',
    ),
    array(
      'data' => t('Name'),
      'field' => 'name',
      'sort' => 'asc',
    ),
    array(
      'data' => t('Type'),
      'field' => 'type',
    ),
    array(
      'data' => t('View'),
      'field' => 'view',
    ),
    t('Operations'),
  );
  foreach (panels_views_load_all() as $panel_view) {
    $ops = array();
    if (empty($panel_view->disabled)) {
      $ops[] = l(t('Edit'), "admin/panels/views/edit/{$panel_view->name}");
      $ops[] = l(t('Export'), "admin/panels/views/export/{$panel_view->name}");
    }
    if ($panel_view->type != t('Default')) {
      $text = $panel_view->type == t('Overridden') ? t('Revert') : t('Delete');
      $ops[] = l($text, "admin/panels/views/delete/{$panel_view->name}");
    }
    else {
      if (empty($panel_view->disabled)) {
        $ops[] = l(t('Disable'), "admin/panels/views/disable/{$panel_view->name}", NULL, drupal_get_destination());
      }
      else {
        $ops[] = l(t('Enable'), "admin/panels/views/enable/{$panel_view->name}", NULL, drupal_get_destination());
      }
    }
    $item = array();
    $item[] = check_plain($panel_view->title);
    $item[] = check_plain($panel_view->name);

    // this is safe as it's always programmatic
    $item[] = $panel_view->type;
    $item[] = check_plain($panel_view->view);
    $item[] = implode(' | ', $ops);
    $items[] = $item;
    $ts = tablesort_init($header);
    switch ($ts['sql']) {
      case 'title':
        $sorts[] = $item[0];
        break;
      case 'name':
      default:
        $sorts[] = $item[1];
        break;
      case 'type':
        $sorts[] = $panel_view->type . $item[0];
        break;
      case 'view':
        $sorts[] = $item[2];
        break;
    }
  }
  if (drupal_strtolower($ts['sort']) == 'desc') {
    arsort($sorts);
  }
  else {
    asort($sorts);
  }
  $i = array();
  foreach ($sorts as $id => $title) {
    $i[] = $items[$id];
  }
  $output = theme('table', $header, $i);
  $output .= $form;
  return $output;
}