Hi Morbus,

I'm going to describe a particular/complex task to meet a particular need for my site, and I would really love to hear your own opinion.

Premise: I'm doing a migration from an old (non drupal) website to a new Drupal 7 version of the same (I'm using migrate module for this). In this old website there's something similar to a "userpoints system": users gain points for their actions in the site (write a comment, vote a content and so on).
My new Drupal site now uses achievements for this scope, and there isn't any correspondence between the old "userpoints" and the new "achievements" system. I don't want to install the userpoint module and do an integration with this one in the new site, but in the same time I don't want to loose all points old users have actually gained... I have to keep track of that... So, here's what I thought to resolve the issue:

potential solution: step by step:

  1. add a new column in the leaderboard, near to the existing "Points" one, called "Points from old website", as a historical memory.
  2. this new column shows the old users points
  3. the existing "Points" column should now show the achievements system point PLUS the next cell old points amount (so the Points column values are equals to achievements points + old points)
  4. To do what described until now I think I simply have to implement hook_achievements_leaderboard_alter() to add the new column: isn't?
  5. The key point is: where to store (and then retrieve) this old users points data? Well, I think I can implement an hook_schema_alter (or hook_update_N ... I've never done it, so I have to learn) to add a new column to achievement_total table provided by achievements module, and then fill this column during my data migration...




I don't know... What do you think about that?

Thank you very much for your support

MXT

Comments

mxt’s picture

Hi Morbus, I would really like to hear your opinion on this...

Thank you very much

mxt’s picture

Here I am, after some months, with the same issue.

Update of the situation:

I'm now able to add a new column in the global leaderboard, in this way:

function helper_achievements_leaderboard_alter(&$leaderboard) {
  // Add column header:
  $leaderboard['render']['#header'][] = 'Old site points';
  
  // Add row values for new colum
  foreach ($leaderboard['render']['#rows'] as $key => $row) {
    $leaderboard['render']['#rows'][$key]['data'][] = 'TEST ' . $key;
  }

}

Ok, this works, but now I have to insert real values instead of 'TEST ' . $key, so I think to proceed in this way:

  1. Manually create a new custom table in database with 2 fields: 'uid' and 'old_site_point'
  2. Populate this table with old points values during migration (using migrate module)
  3. Modify the above code adding a query that retrieves old site point value for each row, using $key (the user id) as condition

This is the best solution I can find at the moment, I think performance issues are negligible because leaderboard shows paginated results, and so the query is executed for a max of 10 - 20 times (it depends on the number of rows the leaderboard shows, based on settings in admin page).

Can you guys give me any advices on this? Is there a better way to proceed?

I've also discarded the idea to add the new column in the existing 'achievements_totals' table and then use hook_query_alter() to alter the 'achievement_totals' query to add the new column in results: I have no idea on how to inject the query results in the render array built in achievements_leaderboard_totals function provided by achievements module (there is no way to override this function and I don't want hack the original code)

Thank you very much for any help

MXT