You are here

function domain_content_list in Domain Access 7.3

Same name and namespace in other branches
  1. 6.2 domain_content/domain_content.admin.inc \domain_content_list()
  2. 7.2 domain_content/domain_content.admin.inc \domain_content_list()

List the available domains for this user.

See http://drupal.org/node/367752 for a discussion of the need for this function.

1 string reference to 'domain_content_list'
domain_content_menu in domain_content/domain_content.module
Implements hook_menu()

File

domain_content/domain_content.admin.inc, line 43
Administration pages for Domain Content.

Code

function domain_content_list() {
  global $user;
  domain_user_set($user);
  $build = array();
  $show_all = user_access('bypass node access') || user_access('review content for all domains');
  if (!$show_all) {
    if (empty($user->domain_user)) {
      return drupal_access_denied();
    }
    $user_domains = array_filter($user->domain_user);
  }

  // Table information
  $header = array(
    array(
      'data' => t('Id'),
      'field' => 'domain_id',
    ),
    array(
      'data' => t('Site content'),
      'field' => 'sitename',
    ),
    array(
      'data' => t('Content count'),
    ),
    array(
      'data' => t('Unpublished'),
    ),
    array(
      'data' => t('Site'),
      'field' => 'subdomain',
    ),
  );

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

  // Filter by user access to assigned domains.
  if (!$show_all) {
    $query
      ->condition('domain_id', $user_domains, 'IN');
  }

  // Add the tablesort.
  $query = $query
    ->extend('TableSort')
    ->orderBy('is_default', 'DESC')
    ->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;
  }

  // Create the table.
  $rows = array();
  foreach ($domains as $domain) {
    $path = trim(domain_get_path($domain), '/');
    $rows[] = array(
      $domain['domain_id'] . ($domain['is_default'] ? ' * ' : ''),
      l(t('@sitename content', array(
        '@sitename' => $domain['sitename'],
      )), 'admin/domain/content/' . $domain['domain_id']),
      number_format((int) db_query("SELECT COUNT(nid) FROM {domain_access} WHERE gid = :gid AND realm = :realm", array(
        ':gid' => $domain['domain_id'],
        ':realm' => 'domain_id',
      ))
        ->fetchField()),
      number_format((int) db_query("SELECT COUNT(n.nid) FROM {node} n INNER JOIN {domain_access} da ON n.nid = da.nid WHERE da.gid = :gid AND da.realm = :realm AND n.status = 0", array(
        ':gid' => $domain['domain_id'],
        ':realm' => 'domain_id',
      ))
        ->fetchField()),
      l(t('View @domain', array(
        '@domain' => $domain['subdomain'],
      )), $path),
    );
  }
  $all = array(
    '-',
    l(t('Content assigned to all affiliates'), 'admin/domain/content/all'),
    number_format((int) db_query("SELECT COUNT(nid) FROM {domain_access} WHERE gid = :gid AND realm = :realm", array(
      ':gid' => 0,
      ':realm' => 'domain_site',
    ))
      ->fetchField()),
    number_format((int) db_query("SELECT COUNT(n.nid) FROM {node} n INNER JOIN {domain_access} da ON n.nid = da.nid WHERE da.gid = :gid AND da.realm = :realm AND n.status = 0", array(
      ':gid' => 0,
      ':realm' => 'domain_site',
    ))
      ->fetchField()),
    '',
  );
  array_unshift($rows, $all);
  if (!empty($rows)) {
    $output = '<p>' . t('The table below shows all the affiliates sites whose content you may edit. Click on the site name link to see all content assigned to that affiliate. Note that not all users may view unpublished content.') . '</p>';
    $build['header'] = array(
      '#markup' => $output,
    );
    $build['content'] = array(
      '#theme' => 'table',
      '#header' => $header,
      '#rows' => $rows,
      '#attributes' => array(
        'id' => 'domain-list',
      ),
    );
    $build['pager']['#theme'] = 'pager';
  }
  else {
    $build['content'] = array(
      '#markup' => t('You do not have editing access to any domains. Please contact your site administrator.'),
    );
  }
  return $build;
}