Needs review
Project:
User Points
Version:
7.x-2.x-dev
Component:
Code: userpoints
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
23 Aug 2011 at 23:08 UTC
Updated:
23 Dec 2015 at 12:21 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
BenK commentedSubscibing... definitely agree with your "important" point.
Comment #2
guybrush commentedThe problem with trying to do this is that the user is referenced so many times within the module. One option might be to make a change so that instead of the UserpointsTransaction class extending the Entity class directly, it instead extends a EntityTransaction class. The only difference is that the EntityTransaction class would not be interested in the user's uid.
It may be possible to continue to use the existing userpoints_txn table structure, but make the uid field nullable.
Entity points transactions could then be attached to entities by doing something like attaching an entity reference field, or similar to it. That would introduce a dependency on either the entity_reference or relation module, for example.
Comment #3
guybrush commentedOther options that occur to me are:
1. Rename the uid field to something like entity_id, and add a field to specify the entity type (defaulting, perhaps, to 'user')
2. Make the standard implementation a generic Entity Transaction, but then have a feature module for 'user', which brings in the standard userpoints functionality using Entity Reference. Example feature modules could be added for alternative entity points transactions (e.g. attached to a Basic Page node)
Comment #4
berdirYeah, I never said that this is going to be easy. :)
I'm not sure if having generic EntityPointsTransaction class helps because SQL doesn't support something like that and we'd need multiple tables.
So yes, we will need to change uid in the transaction to something like entity_type/id. The thing is that this already exists, so we either need a new name or rename the old one. Entity Reference doesn't work, because that's limited to a single entity type per field. Relation technically would, but then we have yet another entity and table inbetween.
Additionally, this is already related to the "replace tid with bundles" issues, because we then have two different ways of separating transactions: a) multiple transaction bundles, and b) multiple fields to which they are assigned.
So, my suggestion at this point is the following, let's split this issue up into two separate tasks:
1. Use a field to store the points total.
2. (Later on) Make it possible to assign such a field to another entity than user.
The first point has already enough conflict potentation, especially with #1258026: Implement userpoint bundles. We might want to split that one up as well and first remove the current categorization (and replace with a taxonomy term reference field if it's currently used), then implement 1. here and then look into making it entity type agnostic and add bundles.
The advantage of that is that we currently have two tables to store userpoints totals, one is the overall total and one is per category. The per-category one would be removed, which would make it easier to replace the other one with a field.
Comment #5
mradcliffeThis is going to require splitting off the user field and functionality attached to user accounts into a separate sub-module so that we can create the field type in userpoints and create the field and field instance in the sub-module.
I'm working on a patch for this.
Comment #6
mradcliffeHere's a patch that leaves in the current stuff, but adds an optional field that can be added with the userpoints_user sub-module. Todo: tests, upgrade, and removing of old implementation.
The only other way is to do like Og does and create an interface to "add fields" to the entity after installation. I'm not sure which is better UX.
I guess another alternative is to make userpoints_field and then have userpoints depend on that sub-module instead. Then userpoints can be the one adding fields that userpoints_field defines the field types for.
Comment #7
berdirNot sure yet if it should be userpoints + userpoints_user or uerpoints_field + userpoints. It can't be in the same module due to dependencies, is that correct?
Given that, I think having userpoints_field and depending on it makes more sense. Enabling Userpoints should get you the default experience and if you want something more advanced, then using the default field UI sounds fine to me. That will, for the moment, also allow us to directly set the values for it in the userpoints transaction storage controller.
Nice start, but there are some interesting problems ahead, like the whole categorization thing, as discussed before, it might make sense to remove that first.
That relation should be created by default if uid is set to type user?
That is not correct* and doesn't scale. Have a look at the update total logic in the storage controller to see what needs to be done here.
* It makes the same mistake as the earlier max points implementation. Once you have negative points, the max is a "sum of all positive transactions" and not "highest point amount the user ever had" anymore.
Comment #8
mradcliffeThanks for the feedback.
I think fields can be transition before categorization as the taxonomy term aggregation can be added with views. I didn't attempt anything there yet (lots of @todo). I'm trying to develop things side-by-side so that I can compare functionality.
Changes
I refactored so much there wouldn't be a point to an interdiff.
Comment #9
mradcliffeI forgot to change to needs work as it still needs work. :-)
Also need to respect status in getting points.
Comment #10
mradcliffeHmm... I think the field needs to be split out into a dependency because it is now difficult to disable / uninstall userpoints.
Comment #11
mradcliffeHere's a patch splitting field into userpoints_field and then installed by userpoints so that the module can be uninstalled appropriately.
Comment #12
mradcliffeHere's a patch reflecting #1870674: Categorization with default taxonomy term reference field and views #6 from months ago, which is a different direction from the above patches.
Objective of patch so far:
Comment #14
berdirLooks interesting, some thoughts below.
Points branding is going to be an interesting challenge, we might need to implement some alter hooks so that the field label is changed to whatever is configured in the backend (later even field settings).
should use the LANGUAGE_NONE constant. Wondering if we can prevent this from being made translatable, that's going to result in an interesting mess.
Not sure what you're doing with user_save() here exactly :) A user is usually saved like this: user_save($account, (array)$account). entity_save('user', $account) should take care of that weirdness?
Also, I still don't understand why this is separate from the existing logic to calculate the total that happens in in UserpointsTransactionController::updateTotals(). That's IMHO the right place for this.
Then you don't need this anymore, as we already have (quite complicated) points and max points calculation there.
There shouldn't be additional spaces before the @file description
Again, we already calculate this in updateTotals(). The calculation is currently more complicated due to the special 'all' category, can probably be simplified once we remove it.
Hm. Not yet 100% sure how points label branding/field label/bundle label will play together.
Using the bundle label as branding might probably make the most sense but what can we do if there is none available (for generic descriptions and so on).
Also, translations, this will need to be translatable somehow. Either i18n_string or entity/field translation.
Hm, this could actually use the entity type as type?
Comment #15
mradcliffeI haven't posted a patch in a while, but I had been working on this. I am trying to keep the current taxonomy stuff untouched so that it can be migrated later.
I attached a git show interdiff of my past commits without the binary chunk from the patch.
Comment #16
mradcliffeStatus change.
Comment #17
tclnj commented#12: 1258032-points-field-patch-4.patch queued for re-testing.
Comment #18
PatchRanger commentedDon't you all think that such module shouldn't be called 'Userpoints' anymore? I guess the best name is just 'Points' - it is free now: https://drupal.org/project/points . In my view it should be done as a separate sandbox completely independent from Userpoints - just relying on its code by copy-paste :)
Comment #19
giorgio79 commentedGreat idea for the Points name.
Perhaps that should be used for D8, and provide a migration / update path to that module as this change wont be happening for D7 it seems :)
Comment #20
Anonymous (not verified) commentedany progress on this...can't wait to test the first release?!
Comment #21
ibexy commentedany progress on this. I will help test.