You are here

function imagepicker_group_stats in Image Picker 6.2

Same name and namespace in other branches
  1. 5.2 imagepicker.module \imagepicker_group_stats()
  2. 7 imagepicker.functions.inc \imagepicker_group_stats()

statistics

3 calls to imagepicker_group_stats()
imagepicker_admin_groups in ./imagepicker.admin.inc
imagepicker_admin_images in ./imagepicker.admin.inc
imagepicker_user_page in ./imagepicker.user.inc
@file my imagepicker in my account

File

./imagepicker.functions.inc, line 1926
Imagepicker functions

Code

function imagepicker_group_stats($account = FALSE, $label = '') {

  // stats
  $groupusercount = FALSE;
  $usercount = FALSE;
  $bytecount = 0;
  if ($account) {
    if (is_numeric($account) && $account == -1) {
      $allcount = _imagepicker_user_has_img();
      $totcount = _imagepicker_user_has_grouped_img('all');
      $publiccount = _imagepicker_user_has_grouped_img('yes');
      $nopubliccount = _imagepicker_user_has_grouped_img('no');
      $groupcount = _imagepicker_user_has_groups('all');
      $publicgroupcount = _imagepicker_user_has_groups('yes');
      $nopublicgroupcount = _imagepicker_user_has_groups('no');
      $bytecount = imagepicker_get_all_bytes(-1);
    }
    else {
      $allcount = _imagepicker_user_has_img($account);
      $totcount = _imagepicker_user_has_grouped_img('all', $account);
      $publiccount = _imagepicker_user_has_grouped_img('yes', $account);
      $nopubliccount = _imagepicker_user_has_grouped_img('no', $account);
      $groupcount = _imagepicker_user_has_groups('all', $account);
      $publicgroupcount = _imagepicker_user_has_groups('yes', $account);
      $nopublicgroupcount = _imagepicker_user_has_groups('no', $account);
      $bytecount = imagepicker_get_all_bytes($account);
    }
  }
  else {

    // imagepicker users
    $result = db_query("SELECT count(DISTINCT uid) AS ct FROM {imagepicker_user_groups}");
    $row = db_fetch_array($result);
    $groupusercount = $row['ct'];
    $result = db_query("SELECT count(DISTINCT uid) AS ct FROM {imagepicker}");
    $row = db_fetch_array($result);
    $usercount = $row['ct'];

    // all groups
    $result = db_query("SELECT count(gid) AS ct FROM {imagepicker_user_groups}");
    $row = db_fetch_array($result);
    $groupcount = $row['ct'];

    // public groups
    $result = db_query("SELECT count(gid) AS ct FROM {imagepicker_user_groups} WHERE public = 1");
    $row = db_fetch_array($result);
    $publicgroupcount = $row['ct'];

    // private groups
    $result = db_query("SELECT count(gid) AS ct FROM {imagepicker_user_groups} WHERE public = 0");
    $row = db_fetch_array($result);
    $nopublicgroupcount = $row['ct'];

    // all images
    $result = db_query("SELECT count(img_id) AS ct FROM {imagepicker}");
    $row = db_fetch_array($result);
    $allcount = $row['ct'];

    // grouped images
    $result = db_query("SELECT count(DISTINCT gi.img_id) AS ct FROM {imagepicker_group_images} gi, {imagepicker_user_groups} g WHERE g.gid = gi.gid ");
    $row = db_fetch_array($result);
    $totcount = $row['ct'];

    // public images
    $result = db_query("SELECT COUNT(i.img_id) AS ct FROM {imagepicker} i, {imagepicker_user_groups} g, {imagepicker_group_images} gi WHERE i.img_id = gi.img_id AND g.gid = gi.gid AND g.public = 1");
    $row = db_fetch_array($result);
    $publiccount = $row['ct'];

    // private images
    $result = db_query("SELECT COUNT(i.img_id) AS ct FROM {imagepicker} i, {imagepicker_user_groups} g, {imagepicker_group_images} gi WHERE i.img_id = gi.img_id AND g.gid = gi.gid AND g.public = 0");
    $row = db_fetch_array($result);
    $nopubliccount = $row['ct'];
    $bytecount = imagepicker_get_all_bytes();
  }
  $bytecount = _imagepicker_bkmg($bytecount);
  $header = array(
    array(
      'data' => t('Group statistics'),
      'colspan' => 2,
    ),
    array(
      'data' => t('Image statistics'),
      'colspan' => 2,
    ),
  );
  if (user_access('use public imagepicker') && variable_get('imagepicker_public_enabled', 1)) {
    $rows = array(
      array(
        t('Groups') . ": ",
        $groupcount,
        t('Images') . ": ",
        $allcount,
      ),
      array(
        t('Public groups') . ": ",
        $publicgroupcount,
        t('Public images') . ": ",
        $publiccount,
      ),
      array(
        t('Private groups') . ": ",
        $nopublicgroupcount,
        t('Private images') . ": ",
        $nopubliccount,
      ),
      array(
        '',
        '',
        t('Grouped images') . ": ",
        $totcount,
      ),
      array(
        '',
        '',
        t('Ungrouped images') . ": ",
        $allcount - $totcount,
      ),
      array(
        $groupusercount ? t('Group Users') . ": " : '',
        $groupusercount ? $groupusercount : '',
        t('Space used') . ": ",
        $bytecount,
      ),
    );
    if (!$account) {
      $rows = array_merge($rows, array(
        array(
          $usercount ? t('All Users') . ": " : '',
          $usercount ? $usercount : '',
          '',
          '',
        ),
      ));
    }
  }
  else {
    $rows = array(
      array(
        t('Groups') . ": ",
        $groupcount,
        t('Images') . ": ",
        $allcount,
      ),
      array(
        '',
        '',
        t('Grouped images') . ": ",
        $totcount,
      ),
      array(
        '',
        '',
        t('Ungrouped images') . ": ",
        $allcount - $totcount,
      ),
      array(
        $groupusercount ? t('Group Users') . ": " : '',
        $groupusercount ? $groupusercount : '',
        t('Space used') . ": ",
        $bytecount,
      ),
    );
    if (!$account) {
      $rows = array_merge($rows, array(
        array(
          $usercount ? t('All Users') . ": " : '',
          $usercount ? $usercount : '',
          '',
          '',
        ),
      ));
    }
  }
  return theme('imagepicker_stats', $header, $rows, '<div class="imgp_groups_info">', '</div>', $label);
}