You are here

function clients_connections_list in Web Service Clients 7.2

Same name and namespace in other branches
  1. 6.2 clients.connection.admin.inc \clients_connections_list()
  2. 6 clients.module \clients_connections_list()
  3. 7 clients.connection.admin.inc \clients_connections_list()

Page callback: list connections.

1 string reference to 'clients_connections_list'
clients_menu in ./clients.module
Implements hook_menu()

File

./clients.connection.admin.inc, line 34
clients.connection.admin.inc Page callbacks relating to client connection admin.

Code

function clients_connections_list() {
  $output = '';
  $connection_types = clients_get_connection_types();
  $connections = clients_connection_load_all();
  $rows = array();
  foreach ($connections as $name => $connection) {
    $delete_label = $connection->export_type & EXPORT_IN_CODE ? t('revert') : t('delete');
    $delete_link = $connection->export_type & EXPORT_IN_DATABASE ? l($delete_label, "admin/structure/clients/connections/{$name}/delete") : '';
    $type = $connection->type;
    if (isset($connection->broken_message)) {

      // Not sure where best to shove this, will take suggestions.
      $type .= ' ' . t('(broken)');
    }
    $rows[] = array(
      'name' => l($connection->name, "admin/structure/clients/connections/{$name}/view"),
      'type' => $type,
      'endpoint' => $connection
        ->formatEndpoint($connection->endpoint),
      'storage' => $connection->export_type_label,
      'edit' => l(t('edit'), "admin/structure/clients/connections/{$name}/edit"),
      'test' => l(t('test'), "admin/structure/clients/connections/{$name}/test"),
      'delete' => $delete_link,
    );
  }

  // Ensure the table has a row if there are no connections at all.
  if (!count($rows)) {
    $rows[] = array(
      array(
        'data' => t('No connections defined yet.'),
        'colspan' => '5',
      ),
    );
  }
  $headers = array(
    t('Name'),
    t('Type'),
    t('Endpoint'),
    t('Storage'),
    array(
      'data' => t('Operations'),
      'colspan' => 3,
    ),
  );
  $output .= theme('table', array(
    'header' => $headers,
    'rows' => $rows,
  ));

  // Add a list of connection types that can be created.
  $items = array();
  if ($connection_types) {
    foreach ($connection_types as $type => $type_data) {

      //dsm($type_data);
      $items[] = l(t('Add @type connection', array(
        '@type' => $type_data['label'],
      )), 'admin/structure/clients/connections/add/' . $type);
    }
  }
  else {
    $items[] = t('No connection types are available: you need to enable one or more modules that provide them.');
  }
  $output .= theme('item_list', array(
    'items' => $items,
  ));
  return $output;
}