Sorting the list on the rating element

lcollong

FabriKant d'applications web
Hi there,

I've a very basic "suggestion list" on which there is a rating element. Every one can "vote" (see config snapshot).
It works well and I can see the #__fabrik_rating table growing with the right data.
It seems that the average value is computed "on the fly" when the list is displayed. The rating column in the main list is never updated and always contains zero. Thus, it's not possible to sort the table on the average rating level.
Wouldn't be better to update the main table element with the average value ? It would allow sort on the next refresh/display. It would also prevent the queries on the #__fabrik_rating each time the main list is displayed.

Another point. I've set the decimal number to 1. In the detail/form view it shows the right value (said 3.7) whereas in the list view, it's always round up to the next integer (4). Without decimals.
 

Attachments

  • Capture.PNG
    Capture.PNG
    30.2 KB · Views: 27
The last point is a quick fix:

https://github.com/Fabrik/fabrik/commit/81f4de7e1186b91021e99903e2646ee6b6e5e6e0

I'll take a look at the main issue. It does save the rating if you submit the form, but not if you rate via AJAX from the list. Looking at the code, it seems like we used to, but that code is commented out for some reason. I need to figure out why it got commented out, before re-enabling it.

We still need to query the ratings table on display, regardless of whether we correctly maintain a total, otherwise we wouldn't pick up changes to the ratings settings, and for Other Reasons.

-- hugh
 
Oh yeah, I remember, it was because I had someone using a rating element with AJAX in a repeat group, and the commented out code assumes the element is on the main table.

I had meant to go back and fix the commented out code, but ... eh ...

I'll see what I can do.

-- hugh
 
Hmm, found a couple of other issues. Main one is the Rating element creates its field as an INT, not DECIMAL, so averaged ratings get rounded on store.

I've changed the code so new elements from here on will get created as DECIMAL, but to make yours work you'd need to manually change to to DECIMAL(3,2) in phpMyAdmin (or whatever your database weapon of choice is).

I'll commit those changes at some point this evening.

I didn't exactly fix the "doesn't work for joined elements" thing, I now just only save the average in the main table on AJAX rating if it's not in a joined group. Would need a fair amount of coding to get it to work for joins, as the JS would have to then submit the entire state of the form, so the server side can figure out the PK of the joined row to update. Which is probably why I didn't bother doing it before ... more work than I care to do for such a tiny amount of users that might need it ... one of those corner cases that someone would have to fund if they wanted it badly enough.

-- hugh
 
Thanks for the fix. However, it adds an empty star before the figure in case of a decimal value (see snapshot). It appears when you refresh the page (browser). Not always. May be some JS impact ?
For the sort issue, I've changed the column from int(1) to Dec(3,2) and will test your code when you'll commit it.
I'm not concerned by the joined element thing as my list is very basic, but I understand it's not that easy to fix....
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top