6 years have passed and no solution has been found?
| Comment | File | Size | Author |
|---|---|---|---|
| #85 | userpoints-decimal_support-1165256-85-D7.diff | 30.82 KB | VasilyKraev |
| #77 | userpoints-1165256-decimal_support-77.patch | 29.75 KB | PatchRanger |
| #55 | masterchief.patch | 17.75 KB | MasterChief |
Comments
Comment #1
berdirI am still opposed to actually use a float to store the points.
The reason is simple. It is not exact. So you could give 0.01 points and it would be saved as 0.0099754665 (just an example). That sums up... Some use this module to allow to buy stuff or buy points with real money. So we need to be sure that we are exact...
What we could think about is an option to consistently implement a option to specify the number of decimal places *but continue to save it as an integer*. However, that will be a non-trivial task, because we need to take care of both input and output.
- Output: This is relatively easy. We just need a userpoints_format_points() function that needs to be used everywhere where points are printed which converts for example 100 to "1.00", when you have two decimal places.
- Input: This could be trickier. Think of the dozens of modules out there with configuration options for setting the amount of points you get for something. I think the easiest option would be to implement a custom form field, so that all these modules can simply do "'#type' => 'userpoints_points'". That form field will do two things: Verify that the amount is entered in the correct way. If you have set it to two decimal places, you *must* specify the points value everywhere as "2.00" and not "2". To be sure that the admin is aware what exactly he is setting it to. b) It must implement a value callback to return "2.00" as 200.
We also need to think about what changing that setting implies. My suggestion would be that setting it from "0" (the default) to "2" means that if a user had 100 points now, he simply has "1.00" now. Everything else is too complex.
Comment #2
MasterChief commentedHi berdir!
Thank you for your answer, i think the solution A is the better.
I can backport the changes that will be made in d7 in the sandbox project :)
Comment #3
IWasBornToWin commentedAm I missing something or has the three year discussion (starting back at version 5) about decimal places with userpoints still not made it into code on version 7? I installed version 7 but it still appears the points fields are intergers, not decimals. Am I to assume, at this time, If I want decimals I must manually change the field format type to decimal and hack(remove) references to (int) in the code? If this is the case I will but I somewhat surprised we still don't have a decimal point setting in this new version, unless I'm missing something?
Comment #4
IWasBornToWin commentedAlso, I changed format of fields in userpoints table and transaction table. For now, I am able to use points with decimals. But it appears the total points is not a running calculation of transaction points because the transaction table is not storing decimal values yet the userpoints total field is? I am giving .01 point for making a comment. When I do this, 0.00 is stored in transaction table and .01 is added to the total in userpoints total field. I cant seem to get the .01 to be inserted properly into the transaction table?
Comment #5
berdirNo it is not compatible and it is very likely that calculations are casted to an integer. Just changing the database schema won't be enough.
Features don't magically emerge when discussing them, someone needs to implement it. See #1 for how I envision this to work in Drupal 7, patches are welcome.
Comment #6
jredding commented@berdir The upgrade to Drupal 7 is something we should take advantage of. Continuing with integer is not a good solution to this problem. I think we are all aware that this module should have been built with float/decimal to begin with.
Whenever possible we should store real data in the database and not modify/format it with code (i.e. by storing 150 even though we know it is truly 1.50). Not only does this ensure data integrity over time but it also allows other modules to utilize our data correctly. A good example here is Views. Unless we write a new data handler and always intercept views the views module will write a SQL query that will return 150 and all modules that work with views will see that data amount. Instead the database should return 1.50, decimal and all.
I'm well aware that this change to the database will modify the API and require changes to the core of this module, which will ripple through all contributed modules. However, the upgrade to Drupal 7 gives us the perfect opportunity to make this change. Those modules have to be upgraded to work with Drupal 7 and having them modify (pretty slightly) to work with float/decimal will not be too much additional work.
In short. Let's move this to float/decimal and phase out the use of integer.
Comment #7
berdirPHP does not have an exact decimal variable type.
There is only float (not exact, rounding errors could happen, which is not acceptable when using userpoints as a virtual currency) and integer.
So, I don't see a way to use anything else than integer. This is IMHO how all systems deal with currencies: Use the smallest available currency (e.g. 100 cents instead of 1.00 dollars).
Providing a field handler to be used with views is easy, we for example already need one for the category anyway (For the general category, that is not actually a term).
Comment #8
berdir*Even* if we would use float for this, we'd still have to use a common theme function/display function to ensure a consistent amount of decimal places everywhere. For Views and everywhere else.
Comment #9
IWasBornToWin commentedUbercart uses a decimal format with 3 decimal places. Not suggesting this is the best way but I'm confused at the comment "php does not "have an exact decimal variable type". How much would it cost to move the discussion to implementation? I'd be willing to chip in, soon.
Comment #10
jredding commented@berdir Using integer as a method of storing currency is one method but I haven't found it to be the most common or a standard. Ubercart uses a numeric database type (i.e. MySQL decimal), zencart (php based) uses decimal. You also don't have to define a format if you set your database to store only 2 decimal places. Without the use of float/decimal in the database you have to filter the input and output. For example, when one enters .03 as a point value you would need to translate that to 3 before entering it into the database. Then on output you modify that back to .03 for display. Finally views already understand floats and has a formatter for it, which defaults to 2 places. So you don't need to modify it.
Comment #11
berdirubercart isn't exactly the project that I would use as an example :)
Drupal Commerce does use an integer, for example:
As said before, PHP does not have a fixed decimal data type. If you have a fixed decimal in your database with 2 decimal places, it will be converted to a float in PHP. And with a float, when you add 3.0 and 3.0, you will eventually end up with 5.99 oder 6.01, depending on how it's rounded.
Comment #12
berdirSee also: http://stackoverflow.com/questions/3819508/best-practice-for-working-wit...
Comment #13
IWasBornToWin commentedOk, so where do we go from here? Can I pay someone to do the patch you're suggesting? As stated above, sooner than later?
Comment #14
jredding commented@Berdir I can see your point and if you'd like to continue with integer I could get behind it. Although I'm not a fan of it by any means.
The next question that has to be resolved is how to deal with all of the past points. If we decide that 1 point is now actually 100 (with two decimal points), we have to go to all previously awarded points and multiply by 100 and hard code a 2 place decimal (cringe). This means updating the transaction table and also the summary table. There also needs to be a routine for deciding how to prevent this update from running twice or creating a "transaction" in order to roll back if an update of all rows were to fail part way through
Comment #15
berdirYes, changing the amount of decimal places is a problem. In theory, it is also a problem for a DECIMAL storage type, but we could work around that by always storing 5 decimal places and just allowing 0-5 to choose from.
I can see a few options here:
- Not deal with it at all. Just telling users what effect it has when that option is changed. Not really a solution but very easy to implement ;)
- Store the amount of decimal places for every transaction and user. Then we only need to convert old rows if they are changed. Requires an additional column and I don't see a way to make this work for all the variable_get() configurations. Unless we add a userpoints_variable_get_points() or so and save them as an array.
- Changing all existing transactions. Rather complicated and very slow if you have many transactions and users.
- Always store points with *5. Still requires an initial conversion for existing sites and a lot of overhead of all the users which don't need it (which I assume is most of the users).
- Store the decimal places in a separate column. That basically means creating a custom DECIMAL storage type. That I just thought of and I kinda like this solution. The advantage is that we can work around PHP's limitation of not having a decimal variable type (Not by default that is, although there are extensions like bcmath). And there is very little overhead for users which do not use this. And modules which don't support decimal places (in their configuration and so on) still work. Since points configurations are stored as a string, we could actually support storing '12.5' points as a variable and then take it apart in the API.
Comment #16
IWasBornToWin commentedAnyone available for hire to get this patch done sooner than later?
Thanks
Comment #17
IWasBornToWin commented@berdir I read your stack overflow link, and it seems you're correct. In the long run, for sure.
If I use a decimal format in the database, until the patch or a revision is made for integer, will I be able to convert the records afterward? I'd expect if I am storing 45.50 points in a decimal format, the new integer format will store it as 4550. Is this correct? And if so, wouldn't I need to run a query to multiply all of my points fields by 100 before I convert or update the decimal format to an integer? Would it be as simple(or difficult) as changing the 45.50 to 4550 and then changing the format back to integer before updating to the new module?
I really need to use a 2 decimal point format now. I am looking for the least painful way to use the data now and also when version 7.x,2.x has the new format.
Thanks
Comment #18
jredding commented@Berdir
A separate column would provide the best backwards compatibility but because you would rarely (if ever) have an instance where one row has a decimal place of 2 and another row with a decimal place of 3 this column would be unnecessary overheard going forward.
I think it is best to just focus on writing a simple transactional routine that updated all past rows. On the plus side this same routine can be used anytime someone wanted to adjust the granularity of the decimal places.
For example (pseudo code)
-----
function userpoints_add_decimal_place(dec_places) {
$records = db_query('select txn, point from userpoints_txn');
foreach ($record as $records) {
$point = $record['point'] * dec_places; (this needs to be 10, 100, 1000, etc.)
db_query('UPDATE {userpoints_tax} SET point = %d WHERE txn >= %d', array($point, $record['txn']))
}
-----
Of course we should use db_update() in D7 and preferably this would be in a transaction. Due to the lack of transaction perhaps this routine could create a temporary table to track all rows updated so they could be rolled back if need be.
Comment #19
sslider999 commentedSub
Comment #20
IWasBornToWin commentedAre we moving forward with this? Just curious. Not sure what else I should do. I can't write code but I've offered to pay more than once. And i've gotten no response. The "free" drupal system sure does cost as far as, time waiting. #Yawn
Comment #21
berdirMoney is not the issue, time is. I started a new job this week, am moving and was away some time. Also, I first want to get out a stable 7.x-1.0 version. Only after that I'm going start a 7.x-2.x branch and work on new features.
Comment #22
IWasBornToWin commentedThanks Berdir. My comment wasn't for you, specifically. Maybe I don't know how the processes go around here. I'm posting my comment, in general, hoping someone with coding experience, who wants to make money, will see the comment. Do you know of a company who does Drupal independent work for this stuff?
It looks like a lot of pressure is put on you, and a lot of patience, and waiting is required for people like me. What does a company usually do if they need a feature? I'd assume the following?
1. Wait
2. Pay module maintainer for customization
3. Build own module
4. Pay coder to hack some code
5. Is it possible for someone who knows what the're doing to build a separate module that turns userpoints into decimals? Or allows you to input 135.05 at the user interface, code multiplies it by 100, then stores in database as 10305 and then that module would also divide the data by 100 anytime it's being presented to a user? Could someone do a separate module that would do that? If so, this may be my quickest route?
Thanks
Comment #23
MasterChief commentedHi Iwasborntowin !
Sorry to didn't answer you before, i am lacking of time too but i think i will have time in the next days.
I made a sandbox module before to make userpoints works with float, but berdir convinced me to rethink how i handled it.
I saw you proposed money, if you want to contact me, see my drupal profile.
Comment #24
MasterChief commentedComment #25
berdirProviding a better title and changing the targetted version.
Comment #26
liupascal commentedSub
is it possible to have an approximate timeline ? just to have an idea if we can expect the changes to be made in a matter of day(s), week(s), month(s)....
I would understand if there is no timeline at all :-)
Thanks !
Comment #27
IWasBornToWin commentedI just paid MasterChief for a module which allows decimals. I installed it tonight. It works very well. I had one issue and I emailed him about it. Should be solved tomorrow. He did an excellent job!
Comment #28
berdirI did an initial review of the patch attached in #1289348: New upgrade not compatible with Master chiefs decimal customization, below is my feedback.
- Nice work, looks pretty good
- More detailed review below
- Tons of trailing spaces and tabs instead of two spaces. you can see the for example with http://drupal.org/project/dreditor or when using "git diff" in a colored bash terminal.
- I've unfortunately rewritten userpoints_userpointsapi() completely, so these parts will need to be updated.
- Your patch made it work which is great, what we need to do now is make it easy to use for developers, so that it will be easy for the dozens of modules with integrate with userpoints to become compatible with this.
- Views, rules and services integration will need to be updated too as a starting point.
You need to use git diff without the -p0 option, as this is required now for official patches.
My suggestion would be that we define a new form elements called 'userpoints_points' through hook_elements_info(). Then we can use that everywhere where points are set. We can use userpoints_split_floats() in a #value_callback.
However, I'm not yet sure how to store points settings as variables. Doing it as an array there would be rather unconfortable unless we provide a helper function somehow.
#group definition is missing to make this a vertical_tab. Have a look at the other fieldset definitions.
Also, a summary would be great for this, have a look at userpoints_admin.js for examples.
Do we really want to allow up to 8 decimal places? Just a question, not sure..
Also, you don't need to specify the key explicitly, this is the default key value (0...)
I haven't seen it yet, but I assume that #size 1 looks rather strange. I'd suggest to make this a bit bigger (3 or so) and add a #max_length key of 1 so that it can't be bigger (#size is just the textfield size, not the allowed characters)
I think we should default to an empty thousands separator here, because that's what we've done before. And if not, we should try to get the locale default for it as the default value.
Tab here.
More tabs
Make sure you're using the same description as above here. (Which is kinda strange but so is the current max_points description).
Not sure if we need these indexes, we only do if there are query conditions on these fields, which I doubt.
Also, if we *do* want them, they need to be added to hook_schema() too.
What it says :)
I'm not too fond of using constants for variable names and will probably drop them at some point it 7.x-2.x. It might make sense to do this from the beginning here.
Note that this will need to be updated as I've completely rewritten this in 7.x-2.x. The total calculations and the message formatting will need to be updated too as it has moved, but it hasn't changed much (yet).
This is kinda long. I suggest we add a wrapper function or something which allows to get the catenated points for a given uid/tid.
should be removed, $string instead of $params and a description of the param should be added on the line below, indented tw spaces. Also, maybe use a better variable name than $string?
Same here, a empty space above @param, no type, param description, and a return description.
We can unfortunately not realy on bcmath being installed, so we need to find a way to do this without it.
Always use expanded version of if conditions with { } and a separate line for the inner code.
I think this does not need a separate query, simply add another expression on the existing unapproved query and then use fetchObject() and get points and points_dec from there. (Make sure you're using an explicit alias for the expression so that you can address it).
Comment #29
IWasBornToWin commentedBerdir,
Can you tell me where we are as far as this being implemented into Userpoints? I do not want to update to a new version since I am using MasterChef's module he created for me.
Thanks
Comment #30
sachitsac commentedHi Guys,
I am using userpoints and am new to drupal. Now i noticed today there was an issue with floats in user points so i did some search and arrived to this thread. I read that a fix was done by MasterChef's for IWasBornToWin. I am wondering if that fix has been brought back to this module? If not, can you guys suggest how i can tackle this problem and i will do the fix and submit the code?
Thanks.
Comment #31
sachitsac commentedHi Guys,
Some more info on the version: I am using drupal 6.22 and userpoints version 6.x-1.2 and ubercart userpoints 6.x-2.0-beta2
Thanks.
Comment #32
IWasBornToWin commented@sachitsac
All of this is referring to Drupal and Userpoints version 7
Comment #33
berdirNothing has happened since my last review and this currently isn't far up in my own to do list. If there is something going to happen, it will be posted here.
If no on else works on this I will only get back to this after other tasks of the 7.x-2.x roadmap have been implemented. And as said before, this will not find it's way back into the 7.x-1.x.
Comment #34
rfayIn Commerce, we store things as integers, in the *minor units* (like cents in USD). The *presentation* is turned into a format like $1.99, but the storage is always integers.
IMO currency can never be stored with a float.
Comment #35
IWasBornToWin commentedAny more action on this? Berdir, do you have an ETA for 7.2 userpoints...and will the new patch with decimals be in it?
Comment #36
IWasBornToWin commentedI've noticed a version 7.2 out. Did decimals make this? I'm still using masterchief's custom module I paid him to do for me. Don't want to upgrade and overwrite if 7.2 isn't ready.
Comment #37
edufol commentedHi,
I'm also using Masterchief patch to allow decimals in my userpoints but I see that views module doesn't show decimals.
How can I solve this?
Thanks!
Comment #38
IWasBornToWin commented# 37 Views does show decimals. I use it. Did you check the formatter, either in the display section of the field at the node, or in the formatter section of the view.
Berdir,
Per your instructions on #33, someone did work on this. I paid Masterchief for decimals and he submitted patch to you over 6 mos ago. I asked 2 months ago if his decimal patch is in new 7.2? I've been using his module for 6 mos and it works great. Is it committed yet? Will it be, why isn't it, etc.? I'd appreciate a quick response...thanks.
Comment #39
edufol commentedI Was Born to Win,
Sorry, but I don't know how to show userpoints decimals in views. I can't find the option to change the formatter :(
Also, I print the function
print userpoints_get_current_points($user->uid);on different templates and don't recognise decimal numbers. Only show the integer. How can I solve it?On the other hand, It works well on the transaction list page. I can see all the operations correctly.
I found another error when changing the decimal point that will be used on decimal settings to a comma. I'm trying to use userpoints as a complementary currency system in Spain and I found Userpoints Donation contrib module to make transactions. Well, if I use points as a "decimal point" there aren't problems between transactions but If I select commas this is what it happens:
System transfers 1,55 points to the other user but only deducts 1 from me! :P
I could use dots, but in Spain decimal numbers are expressed in commas... for me is a problem.
I think that all of this issues will be solved with the new userpoints version, but I need something basic now to start the project.
Any ideas? Could you help me?
Thanks for your time!
Comment #40
michaek commentedI don't think @Masterchief's patch is a good design direction. If support for decimal userpoints is needed, that should be made available as an optional supporting module, and the decimal settings should be used for display and input only. That is: no changes to userpoints_get_current_points and userpoints_userpointsapi should be needed, but a (themeable) function for displaying userpoints should be added to the main module.
Based on my reading of @Masterchief's code, I'm assuming that the decimal settings are global. I'll put together a module implementing this today. Code will be available at http://drupal.org/sandbox/michaek/1545604
Comment #41
berdir@michaek:
Yes, a theme function that is consistently used would be great, could also happen in a separate issue. It might not get us 100% there, however, see comment #1. Basically, it's impossible to change the decimal places without messing things up. Another point are form fields, there needs to be a usable way to deal with them, that validate input and convert it (e.g. that you don't have to write 500 when you have two decimal places)
Feel free to work on it in a sandbox, I do prefer patches to review however.
Comment #42
michaek commentedI've pushed my work regarding the suggestions in #40. If you're interested in browsing the commits in a more legible environment, I've also pushed to github, https://github.com/michaek/drupal_userpoints
@Berdir: I understand your feeling about patches. If you need one, I can roll it from this commit: https://github.com/michaek/drupal_userpoints/commit/7be09e5d46ddadff83e1...
Comment #43
berdirYes, looks interesting.
- Some minor coding style issues, like missing spaces around the =>.
- Views integration need to be updated, and Services maybe too.
- As mentioned above, the problem with this approach is that changing the amount of decimal places changes the value of all existing values and settings. That is unfortunate, to say the least. It makes it e.g. impossible to start with 2 decimal places and after a year to decide that you need smaller values and change it. There are ways to fix this, but remember that there aren't only the values in the tables, there are also all kinds of settings and additional places where userpoints might be stored. So we'd need a hook or something to tell other modules that we're changing the decimal places, if we want to support changing it.
- You changed the add points form field with hook_form_alter(). That's a start. Remember that there is also rules integration that should be updated, and a *long* list of contributed modules, which often add one to many form fields to configure how many points you receive for a certain action. See userpoints_nc for an example, or userpoints_donation for one that adds a user facing form that deals with points. If you want to support all of them from within your module, you're going to write *many* hook_form_alters(). What I have been thinking about is providing a specialized form element (#type => userpoints) that contains the proper #element_validate, #value_callback and #process definitions to deal with decimal places in a transparent way.
It doesn't make sense to do the last two points in an optional module. E.g. the userpoints element type must be in userpoints.module so that other modules can rely on it. So, here is my suggestion: Open a separate issue for the theme function and provide a patch for it. There is probably even an old issue for this in the queue. This is a non-controversal, relatively simple change. This allows you to and others to start using the additional module without having to patch userpoints and gives us time to discuss and implement the above things.
Comment #44
michaek commentedI don't think there's any obstacle to changing the decimal values at any time. All the values are still stored as integers, and this only changes the display (and form processing when adding points manually). I would expect all API use to continue using integers.
I didn't look closely at views or services. I'd prefer not to use form_alter, but to create a custom alter hook for point values, but that seemed out of scope for this feature. It would be a better design moving forward.
I'm not looking to become a maintainer of this approach, I just thought I would contribute a more flexible and less invasive design. I truly hope my days working with Drupal are numbered.
Comment #45
berdirImagine having decimal places set to two. A user has 7500,50 points, stored as 750050. Now you change decimal places to 3. Which means that your user suddenly only has 750,050 points anymore.
Nobody is asking you to maintain anything. I'm also not forcing you to work with Drupal. But *I* need to maintain it. And to do that, I need a solution that I can maintain. All those additional modules are an important part of the Userpoints ecosystem, if they don't work well and don't integrate properly with the features that Userpoints has, then Userpoints itself becomes less useful.
All I'm asking you is splitting this up to get the theme function in, asap.
Comment #46
michaek commentedI don't assume that there's any need to change the number of points if you change the decimal places, as the number decimal places is just an element of the display. If someone does need to make that change, the person making the change should make changes to the underlying data on their own. Changing the underlying data shouldn't be part of this feature, as it's (conceptually and practically) all about display.
Comment #47
michaek commentedIf, however, you really need only the theme function, here's how to get it: it's all the changes that aren't in the userpoints_decimal directory. The only thing I changed in the main module was the addition of the theme function.
Comment #48
IWasBornToWin commentedYawn....Berdir, for about a year now I have asked about decimals. Others have asked longer. You then direct me to Master Chief. I paid him for a module. it works. I, along with others have long begged for a decimal solution. Getting you to respond in any timely fashion is like getting a root canal. I realize you're slammed busy and contribute a lot to Drupal and I'm very grateful. But when I write you private messages, in different issue logs, don't get replies, and then see you on this thread now talking to someone else about a whole other [hopeful] solution I have to start wondering where your thoughts are? You've totally ignored my questions on #32, 33, and #38. So, as I asked you over a year ago, what do you suggest now?
I've been building a site around Master chiefs customized module for almost a year now. And the only response you now give is to Michael, who jumps in and claims Masterchiefs solution [the one you recommended over a year ago] is now not good and here you are having a conversation with him about it?
Here's an idea - don't suggest I pay for, and master chief write modules, that you aren't willing to reply to questions about. And, as you would tell others, if you and Michael want to discuss other options, start you own new issue! This LONG issue is still about doing decimals in userpoints. Sorry for being blunt but i'm actually tired of waiting for you to decide how and when we will do this. And I'm certainly not happy about spending my money and getting ignored by you only to see you comment about something else to someone else.
Comment #49
berdir@IWasBornToWin: I understand your frustration, but...
I have not ignored you. I have reviewed the patch in #28 and informed about the things that need to be improved. These *will* need to be fixed before anything is going to be commited. I have explained so again in #33. What I've written there is still true, I do not need to repeat that every few weeks. If work happens on this topic, it will be posted to this issue, as you've just seen.
michaek provided an alternative solution, which is based on a theme function. That function *is* useful, with and without decimal places. That's why I asked him to provide that theme function as a patch in a separate issue.
@michaek: Yes, and what I'm asking you is to provide your theme function related changes as a patch in a separate issue. The development process of this module is issue and patch based, that integrates nicely with our automated testing environment on d.o so that your patch will be tested automatically. There already is an issue, all you need to do is attach the patch and update it to 7.x-2.x: #310737: Have a centralized theme function for points display
Comment #50
IWasBornToWin commentedThanks for replying berdir. Just to ensure I understand you correctly, are you saying if the fixes are completed in the patch that it will get committed? It didn't initially seem that way since michaek claimed MasterChiefs patch wasn't a good solution and then you started new dialogue with him. But you're saying michaek's suggestion can be used either way and MasterChiefs module will still be committed once fixed, regardless of michaek's opinion of it?
My concern is, besides having already paid for this module, i'm building (and creating data) in the new tables from MasterChiefs module. Provided it will end up in 7.2 userpoints (some day, preferably sooner) then I am fine. But if I'm building and adding data to some wild fantacy that will not end up being used then I'm very concerned.
I will contact Masterchief but I'm going to wait until you give me clarity - fixed patches = solution for decimals?
Thanks again for replying. I appreciate all your hard work.
Comment #51
rowbotony commentedHello, quite a few interesting posts in the issue queue about using decimals for userpoints. I'd just like to know if there is a simple theme function snippet someone can provide for showing my userpioints with a decimal? Also - would this snipped be able to add a comma for points greater than 1000? ex: 250055 user points displayed as - 2,500.55 on the front end via a theme function?
I understand userpoints are stored as integers, and that works very well for me. I'm not a hardcore developer, so I don't necessarily want to be hacking and patching the userpoints module itself to actually store the number in MySQL as a decimal. I'd very much appreciate if anyone has a template.php snippet they can share that will allow me to format userpoints with a decimal just on the front-end display.
Thank you,
--Tony
Comment #52
IWasBornToWin commentedBerdir - I am paying Masterchief more money to correclt patch the decimals module I bought from him. He will fix the errors you pointed out in #28 of this post. He will be done by June 22. I am hoping this will get the patch committed to core?
Comment #53
MasterChief commentedHi Berdir!
IWasBornToWin contact me to make the patch, so here i am :)
I will take in count your remarks in #28, it will be great if you don't do any updates before i make the patch to make another branch of userpoints module like you said in #33 !
I think i can do it before June 22th.
Comment #54
IWasBornToWin commentedAwesome, Masterchief....thumbs up :)
Comment #55
MasterChief commentedHi Berdir, here the patch against 7.x-2.x-dev of Userpoints.
I spotted a problem you need to fix, you removed the function userpoints_create_description() but you forget to replace it in userpoints.admin.inc line 597 when you accept a transaction in moderation. I don't know what you prefer to do on this so i let you do it :)
Comment #57
berdirAll removed functions should now exist as methods on the UserpointsTransaction class.
There are still a lot ofs of trailing spaces and, more important, tabs in your code. Please clean them up. Many IDE's can be configured to enforce spaces instead of tabs and avoid trailing spaces. If you do git diff in a terminal that supports colors, you should be able to see them as well.
I'll try to give you a detailed review soon. It would also be really useful if you could open an issue for the theme function implemented by michaek and make that a separate issue. If we can get that in first (not the separate module he's suggesting, just the changes in userpoints module), then this will hopefully make this issue easier. Just take his code, make a patch of it and upload it. There are a few coding style issues that you could clean up while you're at it, see comment #43.
Comment #58
berdirComment #59
MasterChief commentedNew issue open Berdir :)
Comment #60
IWasBornToWin commentedThanks for all your help MasterChief, Berdir!
Comment #61
IWasBornToWin commentedWhere are we on getting latest patch committed Berdir, Masterchief?
Thanks
Comment #62
MasterChief commentedNow the patch below is commited, i will do another patch very soon:
http://drupal.org/node/1643692
Comment #63
MasterChief commentedBerdir could you explain why we must use theme() function vs userpoints_catenate in my patch in #55 ?
I don't understand why we do this ?
Comment #64
IWasBornToWin commentedBerdir? Can we please get new patch committed?
Comment #65
MasterChief commentedBerdir, iwasborntowin get this error :
Fatal error: Call to undefined function _userpoints_userpoints_transaction_properties() in /home4/growtogi/public_html/sites/all/modules/userpoints/userpoints_rules.rules.inc on line 176
In effect in 7.x-2.x-dev this function doesn't exist anymore, i didn't spot the function which replace it, could you tell the function we must call ?
Comment #66
IWasBornToWin commentedBerdir, we could really use some love here. We've asked for decimals forever, we've done as you asked, I think? I've paid twice now. It would really be cool (for many userpoint users) if we could use what I've paid for. It works really well. The whole community has asked for these decimals for a while. Any chance you could commit MasterChiefs patch to the latest Dev please? Thanks
Comment #67
webczarina commented@MasterChief, @IWasBornToWin - I'm starting from scratch with 7.x-1.0 on a production site. My client has one category of actions for which he wants to assign .25 point per webform submission. I'm not sure how to proceed -- try to apply MasterChief's patch, or set up a rule that will give a user 1 point for every 4 submissions, or...? Does either of you have any suggestions for me? Thanks.
Comment #68
IWasBornToWin commentedIf you want to do decimals, You have to apply Masterchiefs patch. And then you can assign decimals to different actions. And/or use rules.
I use rules a lot because I" give different points per user level for the same action. You'd be quicker, in my opinion, of applying patch and assigning .25 per post than trying to give 1 point ever 4 posts.
Comment #69
MasterChief commentedJust an information, enter 0.25 and not .25 it will be better :)
Comment #70
IWasBornToWin commentedBerdir, Masterchief, did we ever find out about using Master chief's patch in latest version? Berdir I'm changing status so hopefully you will answer us? Thank you.
Comment #71
seakayjay commentedI wish to have this feature as well. But I tried to apply the patch mentioned in #28 against version 7.x-1.0 but it failed.
May I know which version of userpoints does the patch apply to?
Comment #72
rimu commentedIt applies to 7.x-1.0. I just applied the patch from http://drupal.org/node/1289348 successfully.
Comment #73
mrfelton commentedFor those that want to be able to override the display of userpoints by using a theme function, I backported the changes that went into the 7.x-2.x branch to 7.x-1.x. #1918008: Backport theme_userpoints_points to 7.x-1.x
Comment #74
rowbotony commentedTHANK YOU @mrfelton! I asked about this back in June 2012, such a seemingly simple thing - I just wanted the theme to show the userpoints with a decimal, but writing a patch for 7.x-1.x was beyond me. Thank you for taking the time to backport and post this functionality, your efforts are very much appreciated!
Comment #75
PatchRanger commented@Berdir
@rfay
Could we then create a module which is called let's say 'Fake Decimal' and does what is necessary for all of these modules: provides a field which behaves and looks like decimal but is in fact integer with minor units? It will become the dependency for Userpoints and all of the E-Commerce modules including Commerce.
Do you like the idea? I am willing to create such module. I will post an update here in case of any success.
Comment #76
PatchRanger commentedWell, looks like there is no need in creating new, cause there is already plenty of related modules.
The most close and reasonable options (in my view) are:
Commerce is suggested to use Fraction as well: #1125706: Price Implementation for Commerce 2.x (see https://drupal.org/node/1125706#comment-7154004 for reference) - though the decision is not approved yet.
There is another module that depends on Fraction: Ledger - I've suggested them to rely on Userpoints (see #2075785: Why don't you use Userpoints? It has account balances and transaction types.), which will really makes sense in case Userpoints adopts dependency on Fraction.
Probably we could turn Fraction into an extension of "Format Number API": that is add optional parameter to
function format_number($number, $decimals = 0) {as
function format_number($number, $decimals = 0, $exact = FALSE) {and in case if
$exactisTRUErun the logic, which is currently encapsulated into Fraction.Nevertheless, Userpoints should depend on Fraction. Thoughts?
Comment #77
PatchRanger commentedDone. Didn't add any update/migration, because there is introduced new dependency (on Fraction module) and therefore I am in doubt whether it should be implemented in 2.x or in a separate branch (let's say 3.x).
This patch should fail because it depends on Fraction patch: #2077643: Integration with Entity API.
Please review, looks like it does what is desired in a preferable manner.
Comment #79
PatchRanger commentedI insist that it needs review though it failed testing.
Please keep in mind that besides it requires the forementioned patch, it introduces new dependency - and therefore couldn't be tested by testbot, it is due to the logic of calculating dependencies by testbot: https://drupal.org/node/1710704#comment-6304512 .
We should decide here how to deal with this patch: either create a new branch for it, or it is appropriate to commit it to 2.x. My vote is for separate branch, because adding new dependency couldn't be considered as compatible change.
About the solution:
Please note!: Rounding errors could only occur in case of viewing amounts - all data is stored absolutely correctly! You shouldn't be worried about loosing preciseness.
Comment #80
berdir7.x-2.x is a development branch and supposed to change, so no need for a new branch. I'll try to look at the code asap, don't have much time for Userpoints atm.
Comment #81
zulfierken commentedIs this patch applied and implemented in 7.x-2.x ?
Comment #82
g089h515r806 commentedIt is very usefull.
Comment #83
VasilyKraev commentedI update patch #79 from PatchRanger. There was some problem with saving right points to database, because function declared as
and by default, rounded values was saved in database.
Main changes from
to
Comment #85
VasilyKraev commentedMy texteditor trim whitespaces at end of line (also at lines with single whitespace), so patch was broken, and got error, like 'malformed patch at line 652'.
Upload correct file.
Comment #86
A.Kotov commentedRe: Patch userpoints-decimal_support-1165256-85-D7.diff
gives:
faultCode0faultStringFatal error:Call to undefined function fraction_from_decimal() in /hsphere/local/home/xxxxxxxxxxxxxxxxx/sites/all/modules/userpoints/userpoints.transaction.inc on line 366
has Dependency: Fraction
edited: I see that it was discussed already
Comment #87
A.Kotov commentedSent 0.1 point
came error:
Sent 1.1 point to user with 3 points
When click on details, came error:
Also noted if more then one transaction type exists - "Points" fields become blank in all tables. Probably that indexes are not handled properly.
bcmath library and Fraction module installed
Comment #88
VasilyKraev commentedTry make clean install 7.x-2.x-dev and apply patch before making any transactions.
Comment #89
ursatuba commentedVery sad that Userpoints does not properly support decimals.
I tried a clean install of 7.x-2.x-dev, installed Fraction, and patched Userpoints (#85) without too much drama. But the minute I tried to add on Userpoints Nodes and Comments it all falls apart again (unless I set the point award to 0 - but then what's the point). I would be happy to raise that over at userpoints_nc but not until the patch actually gets rolled into dev. Any possibility of this happening at some point in the foreseeable future?
This could be an amazingly powerful module if it supported decimals but I am not sure the author has much time to dedicate to this particular issue (which will be 4 years old in the coming months).
Great module in concept. Please update to dev for decimals soon.
Comment #90
oktboy commentedJust another way of thinking about the use of userpoints is by defining your concept of decimals.
1 userpoint can be a decimal or whatever type of scale you want to use.
For my purposes, I declared 15min increments to be 1 userpoint. And by using computed field module, I am removing the exact amount of time from my userpoint bucket through rules.
For example,
1.25hrs = 5 15min userpoints
Then my rules removes 5 points from my userpoints bucket. I am now in the process of simply changing the way the amount is rendered to the user.
33 userpoints gets displayed to the user as 8.25 hrs.
As I said before, just another way of thinking.
Comment #91
neovictor commented6 years have passed and no solution has been found?
Comment #92
neovictor commented6 years have passed and no solution has been found?