function domain_content_list in Domain Access 7.2
Same name and namespace in other branches
- 6.2 domain_content/domain_content.admin.inc \domain_content_list()
- 7.3 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;
$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);
// We don't bother to unset the -1 here, since it won't matter to the query.
// Cast the -1 as domain 0 for the query.
if (!empty($user->domain_user[-1])) {
$user_domains[] = 0;
}
}
// 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(
'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')
->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'],
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 site'), $path),
);
}
// Add entry for 'all affiliates'
$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);
// Build result table for UI
$build = array();
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;
}