Hey Daniel,

what's the plan for a port of this module to organic groups for D7 ?
General group statistics are in even more desperate need for OG7 than they have been in OG6 (see http://drupal.org/node/1070322).
Are there any architectural thoughts yet? How could we help building it?

cheers,

daniel

Comments

dawehner’s picture

A while ago there was some discussion about moving back a small version of this module back into og, but the discussion stopped.

One problem was, that you can't provide a small version, because it's hard to write a module with dynamic created tables.

The port itself could be perhaps made very flexible/generic: last entity, count entities etc.

idiotprayer’s picture

I've posted a link to a very rough port of the module here.
http://drupal.org/node/1070322#comment-4272810
I too am very curious as to how to properly set this up.
@dereine, is the idea of a flexible/generic version being that you build statistics for a group on request, as opposed to trying to use a hook and count/update for every possible group/group_audience action?
(...this seems like it would be extremely tough to work into any sort of views integration)

dawehner’s picture

s the idea of a flexible/generic version being that you build statistics for a group on request, as opposed to trying to use a hook and count/update for every possible group/group_audience action?

This will not fly. You can't sort/filter by it in views.

Additional this would be too slow in general. We really would have to use some kind of hooks to count stuff.

nikit’s picture

I am continue porting here: http://drupal.org/sandbox/nikit/1169152

dawehner’s picture

Can't you have the same module names and keep the history of the module?

You could git clone og_statistiscs locally and push to your sandbox.
This would help a lot when merging back.

nikit’s picture

ok, module file names are refixed.
But what's mean: "keep the history of the module"?

dawehner’s picture

Don't copy the files but use git to clone the current repo.

nikit’s picture

ok, please check.

dawehner’s picture

Great. Exactly how it should be.

nikit’s picture

Hello Dereine!
When it appear as release here?
regards, Nikit

dawehner’s picture

@nikit
Are you read with your port?

bluestarstudios’s picture

I really would like to finally use this module on my drupal site. It's been over half a year in the making, so any news on the port to Drupal 7?

dawehner’s picture

As there were no new informations from @Nikit i guess he didn't started a port yet.

To be able to support the full new flexibility of og in d7 i fear that at least one day of work is required to proper rewrite the module (as porting would be basically the same).

nikit’s picture

Status: Active » Needs review

Dereine, my sandbox version work with drupal 7 and used on one live site.

dawehner’s picture

Status: Needs review » Needs work

Thanks for the big work you did on porting the module
Some things which could be seen


+// $Id: og_statistics.admin.inc $

This is minor..., but perhaps a sign that you started to port the module quite some time ago.

-  $form['include_unapproved_members'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Include unapproved members in membership count'),
-    '#default_value' => variable_get('og_statistics_include_unapproved_members', TRUE),
-  );

It would be nice if this feature wouldn't be removed. I know it's not your purpose.

+      $comments_count = (int) db_query('SELECT SUM(comment_count) FROM {node} n INNER JOIN {field_data_group_audience} f ON n.nid = f.entity_id LEFT JOIN {node_comment_statistics} ncs ON n.nid = ncs.nid WHERE f.group_audience_gid = :gid', array(':gid' => $group->gid))->fetchField();
  +    $last_comment = (object) db_query('SELECT * FROM {field_data_group_audience} f INNER JOIN {node_comment_statistics} ncs ON ncs.nid = f.entity_id WHERE f.group_audience_gid = :gid ORDER BY f.group_audience_created DESC LIMIT 1', array(':gid' => $group->gid))->fetchObject();

Funny. All other queries have .entity_type but this two misses it.

+files[] = og_statistics.install
+files[] = og_statistics.module

As long a file doesn't contain classes/interfaces you don't need to add it.
Sadly the test is missing here, which, if you just include it throws an error. If you rename the class to the current og test class
it doesn't work. This should be fixed. In general this module should only contain tested functionality.

+++ b/og_statistics.install
  • Sure it's fine to add new fields, but please write an update hook to be able to migrate the module to d7
  • +    'gid' => array(
    +      'description' => "The group's gid",
    +    'type' => 'int',
    +    'size' => 'normal',
    +    'not null' => TRUE,
    +    ),
    

    This indentation looks odd.

  • -      'posts_count' => array(
    +      'content_count' => array(
    

    It seems to be that an even better name would be entity_count, but sure an update hooks is missing as well.

  • + 'last_activity' => array(
    + 'description' => 'Last Time of activity.',
    + 'type' => 'int',
    + 'size' => 'normal',
    + 'not null' => FALSE,
    + 'default' => 0,
    + ),
  • Well in normal cases ports shouldn't contain new features. Actually i don't care if it's tested.

- *   Logs statistics of the organic group module.
- *
- * @todo
- *   Write more inline comments.
- *   Build a central api function.
- *   Use the abstract api function to remove all this functions,
- *   like og_stat_add_*, og_stat_update_*.
- *
- *   Remove all og_statistics_load in update/add/remove functions, its not needed there.
- *
- *   Make more functions use arrays instaed of single values.

Any reason why this is removed?

+function og_statistics_views_api() {
+  return array(
+    'api' => '2',
+  );
 }
 

You can't know this, but it's actually 3.

- * Central og_statistics api function.
- *
- * This function is not used yet.
- *
- * @param $gid
- *  The group nid.
- *
- * @param $key
- *   The statistics key, for example members_count.
- *
- * @param $method
- *   How should the value be handled, possible values:
- *   - set: Ignore the previos value.
- *   - add: add a integer to the previos value.
- *
- * @param $value
- *   The new statistics value.
- *
+ * Implements hook_views_api().
  */
-function og_statistics_update_statistic($gid, $key, $method = 'set', $value) {
-  $stat = og_statistics_load($gid);
-  $stat[$key] = $method == 'set' ? $value : $stat[$key] + $value;
-  // Update if a stat could be found
-  if (isset($stat['nid']) && $stat['nid']) {
-    return drupal_write_record('og_statistics', $stat, 'nid');
-  }
-  else {
-    return og_statistics_write_pure_record($gid);
-  }

Any reasons why it should be removed?

In general i like the cleaner code of the module file and the cleanups in the views file.

The .faceted_search file should probably be removed because this module shouldn't be ported :)

nikit’s picture

hello Dereine!
ok, thanks for reviewing, I'll make these changes

SJTmedia’s picture

Hello, I'm using your Drupal 7 port of OG Statistics. I get the following error messages when someone creates a new user on my site. Do you know how to fix it? Thanks!

Notice: Undefined property: stdClass::$original in og_statistics_user_update() (line 229 of /sites/all/modules/og_statistics/og_statistics.module).
Notice: Trying to get property of non-object in og_statistics_user_update() (line 229 of /sites/all/modules/og_statistics/og_statistics.module).
Warning: Invalid argument supplied for foreach() in og_statistics_user_update() (line 229 of /sites/all/modules/og_statistics/og_statistics.module).
Notice: Undefined property: stdClass::$group_audience in og_statistics_user_update() (line 237 of /sites/all/modules/og_statistics/og_statistics.module).
Warning: Invalid argument supplied for foreach() in og_statistics_user_update() (line 237 of /sites/all/modules/og_statistics/og_statistics.module)

naught101’s picture

definitely needs work. Works ok for existing groups (minor testing), but when I try to create a new group, I get:

Notice: Trying to get property of non-object in og_statistics_node_insert() (line 63 of /home/coalnet/public_html/sites/all/modules/og_statistics/og_statistics.module).
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'gid' cannot be null: INSERT INTO {og_statistics} (nid, gid, members_count, content_count, comments_count, last_activity, last_node_timestamp, last_comment_timestamp, last_member_timestamp, last_comment_uid, last_comment_nid, last_comment_cid, last_node_nid, last_node_uid, last_member_uid) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9, :db_insert_placeholder_10, :db_insert_placeholder_11, :db_insert_placeholder_12, :db_insert_placeholder_13, :db_insert_placeholder_14); Array ( [:db_insert_placeholder_0] => 5 [:db_insert_placeholder_1] => [:db_insert_placeholder_2] => 1 [:db_insert_placeholder_3] => 0 [:db_insert_placeholder_4] => 0 [:db_insert_placeholder_5] => 1323342408 [:db_insert_placeholder_6] => 0 [:db_insert_placeholder_7] => 0 [:db_insert_placeholder_8] => 0 [:db_insert_placeholder_9] => 0 [:db_insert_placeholder_10] => 0 [:db_insert_placeholder_11] => 0 [:db_insert_placeholder_12] => 0 [:db_insert_placeholder_13] => 0 [:db_insert_placeholder_14] => 6 ) in og_statistics_node_insert() (line 80 of /home/coalnet/public_html/sites/all/modules/og_statistics/og_statistics.module).
drew29’s picture

Hej Hej,

is the drupal 7 version available?

kind regards
drew

dawehner’s picture

Mh the current statue of this patch is not really apply-able.

Maybe i will have time during christmas to work on a port, as it should be that hard with actual simpletests of nearly all features.

drew29’s picture

@dereine,

many thanks I wish you a merry christmas

kind regards
drew

dawehner’s picture

As there seems to be no response from the original port creator i started to do the port for myself.

Therefore i created a small chipin: http://ogstatistics7.chipin.com/ and would be happy about any kind of support

g089h515r806’s picture

I need Drupal 7 version.

I have an suggestion,
1, we could create a statistics field,when user add/edit content, we hide the form element of the statistics field.
2,we create a rules action which could populate the value of statistics field. I have check rules module, and find that it support set a value, that means it is possible to build it base on rules module.
3,we config rules.

jacobpov’s picture

Subscribed its a must for me!

naught101’s picture

@jacobpov: if you're not adding any information to the issue, please just use the "follow" button up top.

playfulwolf’s picture

I have a simple question: is it possible to do this kind of table of groups just with views alone with some grouping/agregation? Any one tried?

dawehner’s picture

Sure this should be possible but you will see performance issues if you have a big site.

playfulwolf’s picture

I do not see this as a performance issue, if a view is heavilly cached.
Have view screenshot?

playfulwolf’s picture

Are there anything install'able for D7?

playfulwolf’s picture

How much do I need to chip-in for the initial D7 release? Or even better - to sponsor D7 development?

ishadakota’s picture

I'd be willing to help or sponsor development as well.

Not sure where the latest port is or what it's status is...

nikit’s picture

I have started converting this module sometime ago: http://drupal.org/sandbox/nikit/1169152
But stop it then owner decalre about chip-in. So if he allow or will have silence for this topic, I can continue on it...

playfulwolf’s picture

Please, continue your project! As the current maintainer does not seem to answer to this topic.

naught101’s picture

Title: Port to Organic Groups 7 ? » Port Organic Groups Statistics to OG 7

Name clarification for post trackers

pedrorocha’s picture

Any news on this? I'm starting to work on @Nikit sandbox module, so if anyone have a newer code that could share, would be useful.

pedrorocha’s picture

I use some code from @Nikit and changed some other things(some portion of my code is useless right now - mainly the classes) and now it's possible to run the statistics, with 2 special additions: a page to view the statistics and the count of nodes by bundle(content types). It's in use right know, in a project of mine, and i wish to keep contributing.

For the ones that doesn't know how to apply a patch, i'm attaching a compressed file with the whole module too.

dawehner’s picture

a page to view the statistics

Why not just use this module called views ;)

If you want I can give you co-maintainership, as I won't have time to work on it anyway.

pedrorocha’s picture

Would be great @dawehner !

About the page, we(me and my client on this project) liked the idea to have a general overview page(with stats for every group in one page, to spot things quickly), and i think that on this case Views is unnecessary and with worst performance than a simple query. But obviously, the Views integration must be there to enable other people to create whatever visualisation they want.

dawehner’s picture

About the page, we(me and my client on this project) liked the idea to have a general overview page(with stats for every group in one page, to spot things quickly), and i think that on this case Views is unnecessary and with worst performance than a simple query.

You simply can't convince me with that, so I would strictly say NO if I would do anything with OG_stats but I don't. At least ensure that the views integration is working all the time.

I just gave you the maintainership of the module: Ensure to use the standards defined on https://drupal.org/node/363367
Thank you for stepping up!

pedrorocha’s picture

Ok! Certainly i'll ensure this. Thanks for permissions.

About not convincing you, is about the whole thing(the overview page itself and the argument) or the performance?

BTW, i tend to not use Views on some pages that could be used on projects without Views, but is a fact that OG depends on Views, so this is not the case. I'll make this page a default View instead.

dawehner’s picture

BTW, i tend to not use Views on some pages that could be used on projects without Views, but is a fact that OG depends on Views, so this is not the case. I'll make this page a default View instead.

I think not using views is fine for some usecases like you have a gigantic site on which server costs are higher as developers.

Good to know that OG was dependent on views. Thank you for making this page a view instead. If you really need you should probably your custom tweaks in a custom module. Thank you!

dixon_’s picture

Please make the D7 port agnostic to entity types as well, since any entity type can be a group in D7! I have this use case at the moment.

That would mean that instead of the nid field on {og_statistics} there should be these fields:

  • gid - the group's entity id
  • group_type - the group entity type

Those are the filed names OG itself uses.

I might take a stab at this improvement later.

pedrorocha’s picture

Good point Dixon! I really like this kind of abstraction too, as this module can be used on many different cases.

dixon_’s picture

Ok, so here's a patch and sandbox that ports this module to D7 and OG 7.x-2.x. It's based on previous work by Nikit from his sandbox (which was for OG 7.x-1.x).

My sandbox: https://drupal.org/sandbox/dixon/2105777

At the moment it sort of works, but there's not upgrade path, and the tests needs to be updated.

I strongly recommend to base the base og_statistics 7.x-1.x on this code. It's up to speed with current version of OG and takes an approach that's more agnostic to entity types than earlier patches.

dixon_’s picture

Status: Needs work » Needs review
StatusFileSize
new45.33 KB

Aaand a patch:

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Gave maintainership to dixon.

  1. +++ b/og_statistics.module
    @@ -33,412 +23,253 @@ function og_statistics_menu() {
    +    'api' => '2',
    

    This will probably be the only review point. In Drupal 7 it is recommened to specify 'api' => '3'

  2. +++ b/og_statistics.views.inc
    @@ -174,3 +171,25 @@ function og_statistics_views_og_statistics() {
    +/**
    + * Implements hook_views_data_alter().
    + */
    +function og_statistics_views_data_alter(&$data) {
    +  foreach (og_get_all_group_entity() as $entity_type => $entity_type_label) {
    +    $info = entity_get_info($entity_type);
    +    $data[$info['base table']]['og_statistics_rel'] = array(
    +      'group' => t('OG statistics'),
    +      'title' => t('OG statistics from @entity', array('@entity' => ucfirst($info['label']))),
    +      'help' => t('The OG statistics associated with the @entity entity.', array('@entity' => ucfirst($info['label']))),
    +      'relationship' => array(
    +        // Pass the entity to the handler.
    +        'group_type' => $entity_type,
    +        'handler' => 'og_statistics_handler_relationship',
    +        'label' => t('OG statistics from @entity', array('@entity' => $entity_type)),
    +        'base' => 'og_statistics',
    +        'base field' => 'gid',
    +        'relationship field' => $info['entity keys']['id'],
    +      ),
    +    );
    

    Really nice!

caschbre’s picture

Issue summary: View changes

Any word on the status of the D7 port / release?

izmeez’s picture

+1 for a 7.x-dev branch so this can be tested further. Thanks.

caschbre’s picture

FYI... I just released a lightweight alternative OG SimpleStats until og_statistics D7 can get itself out the door.

igorik’s picture

is this module still alive? Looks like nobody cares about that and new maintainer Dixon are doing anything for D7 release.

dawehner’s picture

@igorik
Did you tried the current patch? I'm happy to create a release with it, even I won't really have time to support it.

igorik’s picture

I didn't catch that there is working patch, sorry.
At the end I tried og_simplestats and for my needs it was enough.