Add groups reports module

A new reporting module with an initial group membership collector
feature. Th module is collecting meetup.com's membership numbers daily into
the groups_membership_stat table.

Change-Id: I35a18d3883117bfb670a4eac18b885fa21a8bbc3
This commit is contained in:
Marton Kiss 2015-02-11 11:08:48 +01:00
parent fbf29ddc18
commit b1de61f89e
5 changed files with 102 additions and 0 deletions

View File

@ -162,4 +162,5 @@ dependencies[] = groups_feeds
dependencies[] = groups_events dependencies[] = groups_events
dependencies[] = groups_events_pages dependencies[] = groups_events_pages
dependencies[] = groups_pages dependencies[] = groups_pages
dependencies[] = groups_reports
dependencies[] = groups_wikis dependencies[] = groups_wikis

View File

@ -303,6 +303,16 @@ function groups_update_7114() {
drupal_flush_all_caches(); drupal_flush_all_caches();
} }
/**
* Enable groups_reports module.
*/
function groups_update_7115() {
if (!module_exists('groups_reports')) {
module_enable(array('groups_reports'));
}
drupal_flush_all_caches();
}
/** /**
* Set language negotiation to URL based. * Set language negotiation to URL based.
*/ */

View File

@ -0,0 +1,7 @@
name = Groups Reports
description = Groups reports building blocks
core = 7.x
package = Groups - Building Blocks
version = 7.x-1.0
project = groups_reports
dependencies[] = elysia_cron

View File

@ -0,0 +1,46 @@
<?php
/**
* @file
* Install, update, and uninstall functions for the groups_reports module.
*/
/**
* Implement hook_schema
*/
function groups_reports_schema() {
$schema['groups_membership_stat'] = array(
'description' => 'Stores group membership daily aggregated statistics.',
'fields' => array(
'nid' => array(
'description' => 'The group\'s {node}.nid for these statistics.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'timestamp' => array(
'description' => 'The YYYYMMDD format date of membership record',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
),
'membercount' => array(
'description' => 'The total number of members registered for the group.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'size' => 'medium',
),
'datasrc' => array(
'description' => 'The data source of the data',
'type' => 'varchar',
'length' => 1,
'not null' => TRUE,
'default' => '',
),
),
'primary key' => array('nid', 'timestamp'),
);
return $schema;
}

View File

@ -0,0 +1,38 @@
<?php
/**
* Update the daily membership statistics
*/
function groups_reports_update_membership_stat($timestamp = null) {
$timestr = date('Ymd', $timestamp ? $timestamp : time());
$result = db_select('node', 'n')
->fields('n')->condition('status', 1)
->condition('type', 'group', '=')
->execute();
foreach ($result as $record) {
$node = node_load($record->nid);
db_merge('groups_membership_stat')
->key(array('nid' => $node->nid, 'timestamp' => $timestr))
->fields(array(
'nid' => $node->nid,
'timestamp' => $timestr,
'membercount' => (int)$node->field_meetup_members[LANGUAGE_NONE][0]['value'],
'datasrc' => 'M',
))->execute();
}
watchdog('Groups Reports', 'Groups membership statistics had been updated.', array(), WATCHDOG_INFO);
}
/**
* Implements hook_cronapi()
*
* Define groups_reports module's scheduled jobs.
*/
function groups_reports_cronapi($op, $job = NULL) {
$items['groups_update_membership_stat'] = array(
'description' => 'Update group membership daily statistcs.',
'rule' => '0 4 * * *',
'callback' => 'groups_reports_update_membership_stat',
);
return $items;
}