Mercurial > defr > drupal > og_statistics
comparison og_statistics.admin.inc @ 2:48f07e7acaca
OG Stats 1.0-rc2
author | Franck Deroche <franck@defr.org> |
---|---|
date | Tue, 24 Nov 2009 14:27:37 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:9ce879ecbce6 | 2:48f07e7acaca |
---|---|
1 <?php | |
2 // $Id: og_statistics.admin.inc,v 1.1.2.1 2009/09/08 20:42:56 dereine Exp $ | |
3 /** | |
4 * @file | |
5 * Admin settings for og_statistics module. | |
6 */ | |
7 | |
8 function og_statistics_settings() { | |
9 $form['rebuild'] = array( | |
10 '#type' => 'submit', | |
11 '#value' => t('Rebuild og_statistics') | |
12 ); | |
13 | |
14 return $form; | |
15 } | |
16 | |
17 function og_statistics_settings_submit(&$form, &$form_state) { | |
18 // get all group nodes | |
19 $types = og_get_types('group'); | |
20 $placeholders = db_placeholders($types, 'varchar'); | |
21 $result = db_query("SELECT nid FROM {node} WHERE type IN($placeholders)", $types); | |
22 while ($item = db_fetch_object($result)) { | |
23 $nodes[$item->nid] = $item->nid; | |
24 } | |
25 $counter = 0; | |
26 foreach ($nodes as $nid) { | |
27 $counter ++; | |
28 $array[] = $nid; | |
29 if (($counter % 20) == 1) { | |
30 $operations[] = array('og_statistcs_recalc', array($array)); | |
31 $array = array(); | |
32 } | |
33 } | |
34 $operations[] = array('og_statistcs_recalc', array($array)); | |
35 // Execute the batch progress | |
36 $batch = array( | |
37 'operations' => $operations, | |
38 'title' => 'Generating statistics', | |
39 'init_message' => 'Loading group nodes', | |
40 'error_message' => 'An unrecoverable error has occurred. You can find the error message below. It is advised to copy it to the clipboard for reference.', | |
41 'finished' => 'og_statistcs_settings_finished', | |
42 ); | |
43 batch_set($batch); | |
44 batch_process('admin/settings/og_statistics'); | |
45 } |