You are here

function quant_quants in Quant 7

Same name and namespace in other branches
  1. 6 quant.module \quant_quants()

Implements hook_quants().

Provide quant objects to be rendered as charts

Quant object items: id A unique ID (Ex: 'comment_creation') label The title of the chart labelsum Whether or not to display the sum of items in the title (Boolean) table Which database to query from field The database field that stores the timestamp query Specify a complete DB query to use to fetch the items (Optional; Use :period to indicate timestamp. This overrides field and table) queryCustom If query is set, you must provide the same query here altered to take a 'from' and 'to' date. (Use :period0 and :period1 to specify both, with 'from' coming before 'to') dataType Specify the type of data we're dealing with (Options: single, multiple, count) group The database field to group items on. (Optional; Only needed if dataType= multiple) count Which database field to count (Optional; Only needed if dataType= count) chartType Which type of chart to use (Options: line, bar, pie)

Return value

An array of quant objects

File

./quant.quant.inc, line 67
Quant hook implementations.

Code

function quant_quants() {
  $quants = array();

  // User Creation
  $quant = new Quant();
  $quant->id = 'user_creation';
  $quant->label = t('User creation');
  $quant->labelsum = TRUE;
  $quant->table = 'users';
  $quant->field = 'created';
  $quant->dataType = 'single';
  $quant->chartType = 'line';
  $quants[$quant->id] = $quant;

  // Content Creation
  $quant = new Quant();
  $quant->id = 'content_creation';
  $quant->label = t('Content creation');
  $quant->labelsum = TRUE;
  $quant->table = 'node';
  $quant->field = 'created';
  $quant->query = quant_node_query();
  $quant->queryCustom = quant_node_query(array(), TRUE);
  $quant->dataType = 'single';
  $quant->chartType = 'line';
  $quants[$quant->id] = $quant;

  // Comment Creation
  if (module_exists('comment')) {
    $quant = new Quant();
    $quant->id = 'comment_creation';
    $quant->label = t('Comment creation');
    $quant->labelsum = TRUE;
    $quant->table = 'comment';
    $quant->field = 'created';
    $quant->dataType = 'single';
    $quant->chartType = 'line';
    $quants[$quant->id] = $quant;
  }

  // Content Creation by Type
  $quant = new Quant();
  $quant->id = 'node_creation_by_type';
  $quant->label = t('Content creation by type');
  $quant->labelsum = TRUE;
  $quant->table = 'node';
  $quant->field = 'created';
  $quant->group = 'type';

  // Which db field to group items by
  $quant->query = quant_node_query(array(
    $quant->group,
  ));
  $quant->queryCustom = quant_node_query(array(
    $quant->group,
  ), TRUE);
  $quant->dataType = 'multiple';

  // See $quant->group
  $quant->chartType = 'line';
  $quants[$quant->id] = $quant;

  // Aggregate Content Creation by Type
  $quant = new Quant();
  $quant->id = 'node_creation_aggregate_by_type';
  $quant->label = t('Aggregate content creation');
  $quant->labelsum = TRUE;
  $quant->table = 'node';
  $quant->field = 'created';
  $quant->count = 'type';

  // Which db field to we want to count
  $quant->dataType = 'count';
  $quant->chartType = 'pie';
  $quants[$quant->id] = $quant;

  // Page views (Statistics)
  if (module_exists('statistics')) {
    $quant = new Quant();
    $quant->id = 'accesslog';
    $quant->label = t('Page views');
    $quant->labelsum = TRUE;
    $quant->table = 'accesslog';
    $quant->field = 'timestamp';
    $quant->dataType = 'single';
    $quant->chartType = 'line';
    $quants[$quant->id] = $quant;
  }

  // User Points - Uses transactions only, not point amount
  if (module_exists('userpoints')) {
    $quant = new Quant();
    $quant->id = 'user_points';
    $quant->label = t('User point transactions');
    $quant->labelsum = TRUE;
    $quant->table = 'userpoints_txn';
    $quant->field = 'time_stamp';
    $quant->dataType = 'single';
    $quant->chartType = 'line';
    $quants[$quant->id] = $quant;
  }

  // Organic Groups
  if (module_exists('og')) {

    // Group Joins
    $quant = new Quant();
    $quant->id = 'group_joins';
    $quant->label = t('Group joins');
    $quant->labelsum = TRUE;
    $quant->query = "\n      SELECT created \n      FROM {og_membership}\n      WHERE created >= :period\n      AND entity_type = 'user'\n      AND state = " . OG_STATE_ACTIVE . "\n      ORDER BY created DESC\n    ";

    // We can provide a custom query instead
    $quant->queryCustom = "\n      SELECT created \n      FROM {og_membership}\n      WHERE created >= :period0\n      AND created <= :period1\n      AND entity_type = 'user'\n      AND state = " . OG_STATE_ACTIVE . "\n      ORDER BY created DESC\n    ";

    // We can provide a custom query instead
    $quant->table = 'og_membership';
    $quant->field = 'created';
    $quant->dataType = 'single';
    $quant->chartType = 'line';
    $quants[$quant->id] = $quant;

    // Group Creation
    if (db_table_exists('og')) {
      $quant = new Quant();
      $quant->id = 'group_creation';
      $quant->label = t('Group creation');
      $quant->labelsum = TRUE;

      // Show the total amount of items in the chart title
      $quant->query = "\n        SELECT created \n        FROM {og}\n        WHERE created >= :period\n        ORDER BY created DESC\n      ";

      // We can provide a custom query instead
      $quant->queryCustom = "\n        SELECT created \n        FROM {og}\n        WHERE created >= :period0\n        AND created <= :period1\n        ORDER BY created DESC";

      // We need to provide the query altered for a custom interval
      $quant->table = 'og';
      $quant->field = 'created';
      $quant->dataType = 'single';
      $quant->chartType = 'line';
      $quants[$quant->id] = $quant;
    }
  }

  // User Shouts
  if (module_exists('shoutbox')) {
    $quant = new Quant();
    $quant->id = 'user_shouts';
    $quant->label = t('User shouts');
    $quant->labelsum = TRUE;
    $quant->table = 'shoutbox';
    $quant->field = 'created';
    $quant->dataType = 'single';
    $quant->chartType = 'line';
    $quants[$quant->id] = $quant;
  }

  // Invites
  if (module_exists('invite')) {

    // Invites sent
    $quant = new Quant();
    $quant->id = 'user_invites_sent';
    $quant->label = t('Invites sent');
    $quant->labelsum = TRUE;
    $quant->table = 'invite';
    $quant->field = 'created';
    $quant->dataType = 'single';
    $quant->chartType = 'line';
    $quants[$quant->id] = $quant;

    // Invites accepted
    $quant = new Quant();
    $quant->id = 'user_invites_accepted';
    $quant->label = t('Invites accepted');
    $quant->labelsum = TRUE;
    $quant->query = "\n      SELECT created \n      FROM {invite} \n      WHERE joined = 1 \n      AND created >= :period \n      ORDER BY created DESC";
    $quant->queryCustom = "\n      SELECT created \n      FROM {invite} \n      WHERE joined = 1 \n      AND created >= :period0 \n      AND created <= :period1 \n      ORDER BY created DESC";
    $quant->table = 'invite';
    $quant->field = 'created';
    $quant->dataType = 'single';
    $quant->chartType = 'line';
    $quants[$quant->id] = $quant;
  }

  // Status shares (Statuses)
  if (module_exists('statuses')) {
    $quant = new Quant();
    $quant->id = 'statuses';
    $quant->label = t('Statuses shared');
    $quant->labelsum = TRUE;
    $quant->table = 'statuses';
    $quant->field = 'created';
    $quant->dataType = 'single';
    $quant->chartType = 'line';
    $quants[$quant->id] = $quant;
  }

  // Private messages
  if (module_exists('privatemsg')) {
    $quant = new Quant();
    $quant->id = 'private_msg';
    $quant->label = t('Private messages');
    $quant->labelsum = TRUE;
    $quant->table = 'pm_message';
    $quant->field = 'timestamp';
    $quant->dataType = 'single';
    $quant->chartType = 'line';
    $quants[$quant->id] = $quant;
  }
  return $quants;
}