You are here

function total_control_overview_content_type_render in Total Control Admin Dashboard 6

Same name and namespace in other branches
  1. 6.2 plugins/content_types/overview.inc \total_control_overview_content_type_render()
  2. 7.2 plugins/content_types/overview.inc \total_control_overview_content_type_render()

File

plugins/content_types/overview.inc, line 29

Code

function total_control_overview_content_type_render($subtype, $conf, $panel_args, &$context) {
  $block = new stdClass();
  $block->module = t('total_control');
  $types = node_get_types('types');
  $overview_cnt = array();
  $overview_usr = array();

  // Content Overview
  foreach ($types as $type => $object) {
    if ($conf['types'] == NULL || $conf['types'][$type]) {

      // compare against type option on pane config
      $type_query = db_query("SELECT count(*) FROM {node} WHERE type = '%s' and status = 1", $type);
      $total[$type] = format_plural(db_result($type_query), '1 ' . $object->name . ' item', '@count ' . $object->name . ' items');
      $comment_setting = variable_get('comment_' . $type, 'comment');
      if ($comment_setting != 0 || $conf['comments'][$type]) {

        // compare against comment option on pane config
        $comment_query = db_query("SELECT count(DISTINCT cid) FROM {comments} c INNER JOIN {node} n ON c.nid = n.nid WHERE n.type = '%s' and c.status = 1 AND n.status = 1", $type);
        $total[$type . '_comments'] = format_plural(db_result($comment_query), '1 comment', '@count comments');
        if ($conf['spam'] == 1) {

          // compare against comment option on pane config
          $spam_query = db_query("SELECT count(DISTINCT c.cid) FROM {comments} c INNER JOIN {node} n ON c.nid = n.nid WHERE n.type = '%s' and c.status = 0 AND n.status = 1", $type);
          $total[$type . '_comments_spam'] = format_plural(db_result($spam_query), '1 spam', '@count spam');
        }

        // if spam
      }

      // if comment
      $line = $total[$type];
      $line .= $total[$type . '_comments'] ? ' with ' . $total[$type . '_comments'] : '';
      $line .= $total[$type . '_comments_spam'] ? ' (' . $total[$type . '_comments_spam'] . ')' : '';
      $overview_cnt[] = $line;
    }

    // if type
  }

  // foreach
  // User Overview
  if (!$conf['user'] || $conf['user'] == 1) {

    // compare against user option on pane config
    $user_query = db_query("SELECT count(*) FROM {users}");
    $total['users_all'] = format_plural(db_result($user_query), '1 total user', '@count total users');
    $user_active_query = db_query("SELECT count(*) FROM {users} WHERE status = 1 AND login != 0");
    $total['users_active'] = format_plural(db_result($user_active_query), '1 active user', '@count active users');
    $user_block_query = db_query("SELECT count(*) FROM {users} WHERE status = 0");
    $total['users_block'] = format_plural(db_result($user_block_query), '1 blocked user', '@count blocked users');
    $overview_usr[] = $total['users_all'];
    $overview_usr[] = $total['users_active'];
    $overview_usr[] = $total['users_block'];
  }

  // Roles Overview
  $roles = user_roles(TRUE);
  $total['users_roles'] = '';
  foreach ($roles as $rid => $role) {
    if ((!$conf['roles'] || $conf['roles'][$rid]) && $rid != 2) {

      // compare against roles option on pane config
      $user_role_query = db_query("SELECT count(*) FROM {users} u INNER JOIN {users_roles} r on u.uid = r.uid WHERE r.rid = %d", $rid);
      $total['users_role_' . $rid] .= format_plural(db_result($user_role_query), '1 user', '@count users');
      $total['users_role_' . $rid] .= ' in role: ' . $role;
      $overview_usr[] = $total['users_role_' . $rid];
    }

    // if not auth
  }

  // foreach
  $pane = total_control_overview_ctools_content_types();

  // Building the content
  $content = '<div class="total-control-site-overview">';
  $content .= '  <h2 class="title">' . $pane['title'] . '</h2>';
  $content .= '  <div class="content">';
  $content .= '    <strong>' . t('Content') . '</strong>';
  $content .= theme('item_list', $overview_cnt);
  $content .= '    <strong>' . t('Users') . '</strong>';
  $content .= theme('item_list', $overview_usr);
  $content .= '  </div>';
  $content .= '</div>';
  $block->content = $content;
  return $block;
}