You are here

function domain_view in Domain Access 7.2

Same name and namespace in other branches
  1. 5 domain_admin.inc \domain_view()
  2. 6.2 domain.admin.inc \domain_view()

The main administration page, a list of active domains.

Return value

A sortable table of active domain records, or an error message.

1 string reference to 'domain_view'
domain_menu in ./domain.module
Implements hook_menu()

File

./domain.admin.inc, line 17
Administration functions for the domain module.

Code

function domain_view() {
  $build = array();
  $_domain = domain_get_domain();
  $build['header']['#prefix'] = '<p>';
  $build['header']['#markup'] = t('The following domains have been created for your site.
    The currently active domain <strong>is shown in boldface</strong>.  You
    may click on a domain to change the currently active domain.  Your default
    domain has an ID of %id.', array(
    '%id' => variable_get('domain_default', 0),
  ));
  $build['header']['#suffix'] = '</p>';
  $header = array(
    array(
      'data' => t('Id'),
      'field' => 'd.domain_id',
    ),
    array(
      'data' => t('Domain'),
      'field' => 'd.subdomain',
    ),
    array(
      'data' => t('Site name'),
      'field' => 'd.sitename',
    ),
    array(
      'data' => t('Status'),
      'field' => 'd.valid',
    ),
    array(
      'data' => t('Scheme'),
      'field' => 'd.scheme',
    ),
  );

  // Get header elements from other modules
  $extra = module_invoke_all('domainview', 'header');
  $header = array_merge($header, $extra);
  $header[] = array(
    'data' => t('Actions'),
  );

  // Cannot use domain_domains() here because we need to sort the output.
  $domains = array();
  $actions = array();

  // Set up the base query.
  $query = db_select('domain', 'd')
    ->fields('d', array(
    'domain_id',
    'sitename',
    'subdomain',
    'scheme',
    'valid',
  ));

  // Get any tablesort sql from other modules.
  module_invoke_all('domainview', 'query', array(), $query);

  // Add the tablesort.
  $query = $query
    ->extend('TableSort')
    ->orderByHeader($header);
  $query = $query
    ->extend('PagerDefault')
    ->limit(variable_get('domain_list_size', DOMAIN_LIST_SIZE));

  // Get the domains.
  $result = $query
    ->execute();
  foreach ($result as $data) {
    $domains[] = (array) $data;
  }
  foreach ($domains as $domain) {

    // Let submodules overwrite the defaults, if they wish.
    $domain = domain_api($domain);
    $link = l($domain['subdomain'], domain_get_uri($domain), array(
      'absolute' => TRUE,
    ));
    $actions = array();
    if ($domain['domain_id'] > 0) {
      $actions = array();
      $actions[] = l(t('edit'), 'admin/structure/domain/edit/' . $domain['domain_id']);
      $actions[] = l(t('delete'), 'admin/structure/domain/delete/' . $domain['domain_id']);
    }

    // Add advanced settings from other modules.
    $items = array();
    $items = module_invoke_all('domainlinks', $domain);
    if (!empty($items)) {
      foreach ($items as $item) {
        if (!empty($item)) {
          $actions[] = l($item['title'], $item['path']);
        }
      }
    }

    // Set the valid flag.
    $domain['valid'] == 1 ? $valid = t('Active') : ($valid = t('Inactive'));
    $row = array(
      $domain['domain_id'],
      $domain['domain_id'] == $_domain['domain_id'] ? '<strong>' . $link . '</strong>' : $link,
      filter_xss_admin($domain['sitename']),
      $valid,
      $domain['scheme'],
    );

    // Let other modules add data.
    $data = array();
    foreach (module_implements('domainview') as $module) {
      $add = module_invoke($module, 'domainview', 'data', $domain);
      $row = array_merge($row, $add);
    }

    // Add the actions.
    $list = array(
      'items' => $actions,
    );
    $row[] = theme('item_list', $list);
    $rows[] = $row;
  }
  if (!empty($rows)) {
    $build['content'] = array(
      '#theme' => 'table',
      '#header' => $header,
      '#rows' => $rows,
      '#attributes' => array(
        'id' => 'domain-list',
      ),
    );
    $build['pager']['#theme'] = 'pager';
    return $build;
  }
  else {
    $build = array();
    $build['no_content']['#prefix'] = '<p>';
    $build['no_content']['#markup'] = t('No domains have been configured.');
    $build['no_content']['#suffix'] = '</p>';
    return $build;
  }
}