It would be really nice to have some better handling of the filter options used for the rating value stored in the fivestar field. Right now we are using the default views filter for integers, which allows users to select equal, greater than, lower than etc.
What we should use instead is the in_operator which will create a query using "IN" or "NOT IN" and will give the flexibility of the admins to display results with fx 1 and 5 stars. It will also allow us to create a more natural selection for the users, who can use a select list to enter stars instead of users having tp enter 20, 40 etc and know how many stars that translate to.
Comment | File | Size | Author |
---|---|---|---|
#47 | interdiff-47.txt | 3.4 KB | gg24 |
#47 | add_better_views-1255160-47.patch | 6.46 KB | gg24 |
| |||
#45 | interdiff-45.txt | 4.26 KB | gg24 |
#45 | add_better_views-1255160-45.patch | 6.61 KB | gg24 |
| |||
#43 | add_better_views-1255160-43.patch | 6.6 KB | gg24 |
|
Comments
Comment #1
googletorp CreditAttribution: googletorp commentedI've created the initial views integration for fivestar, handling this issue and added it to my Fivestar sandbox: b4ab341
The remote for this is http://git.drupal.org/sandbox/googletorp/1255156.git
Comment #2
ericduran CreditAttribution: ericduran commentedPatches are welcome. Even proper git patches are welcome so you can get the proper commit credit. But we just changed a lot regarding the field and the widgets so patches would be simpler to work with. Sorry :(
Comment #3
ericduran CreditAttribution: ericduran commentedMarking as wont-fix. Patches are always welcome :)
Comment #4
googletorp CreditAttribution: googletorp commentedBeen busy with other stuff, anyways cleaned up the the code so that it actual works, somehow some debug stuff landing with the code (Ups), also created this as a git patch for head, so should be easier for you to make it work as well.
Otherwise this is basically the same as before.
How it works:
We use hook_field_views_data to add a custom handler for the rating column and otherwise use views default.
The custom handler is an in type operator like content types, as we know the possible values (1 star, 2 stars.. foo stars). This data is fetched from the field settings and added as possible filter options. Works great for exposed filters.
TODO: A nicety would be to render the exposed form as a fivestart widget instead of a simple select box.
Comment #5
ericduran CreditAttribution: ericduran commentedAWESOME!!!
I'm testing this out. Thanks.
Comment #6
googletorp CreditAttribution: googletorp commentedAdd patch for alpha 2 release.
Comment #7
googletorp CreditAttribution: googletorp commentedFixed issue with previous patch for alpha 2 release
Comment #8
jasonglisson CreditAttribution: jasonglisson commentedGreat job guys! This works great!
Comment #9
anemirovsky CreditAttribution: anemirovsky commentedThe patch didin't work for me.
field_info_field($this->definition['field_name'])
does not pull the configuration setting for the number of stars for the field. That setting is stored in field_config_instance and you get it by using field_info_instance. However, field_info_instance takes both the entity_type and bundle_name for the field along with the field_name for arguments. I had a bit of trouble figuring out how to get that info, so the solution I have is a bit hacky but seems to work. Basically, I get the field_info and entity_type from the field_info_field by doing some hacky stuff the the bundles array. Then, I call field_info_instance to get the number of stars configured for the field.Comment #11
anemirovsky CreditAttribution: anemirovsky commentedLet's try that again...
Comment #12
anemirovsky CreditAttribution: anemirovsky commentedAnd again...
Comment #14
anemirovsky CreditAttribution: anemirovsky commentedAnd again again...
Comment #15
anemirovsky CreditAttribution: anemirovsky commentedComment #17
anemirovsky CreditAttribution: anemirovsky commentedThis should work now. I'm patching against 7.x rather than alpha 2.
Comment #19
anemirovsky CreditAttribution: anemirovsky commentedThis is becoming comedic...if this doesn't work, I don't know what will.
Comment #20
anemirovsky CreditAttribution: anemirovsky commentedComment #21
ericduran CreditAttribution: ericduran commented@anemirovsky well then good thing that one work ;-p
I'll review this this weekend.
Thanks for your hard work :)
Comment #22
jibize CreditAttribution: jibize commentedPatch from #19 worked for me thank you!
Comment #23
ExTexan CreditAttribution: ExTexan commented#19 worked for me except for selecting "No stars". Evidently the result of no stars is blank (or null), not zero.
Comment #24
anemirovsky CreditAttribution: anemirovsky commentedThis is a tougher problem to solve. There isn't actually a row created for the fivestar field if the value is no stars, so the Views query fails to find those nodes because it's looking for a row in the fivestar field's table.
One way I thought of to try to fix this is to modify the Views query if the selected filter option is 0 to not add the where clause that looks for a value in the joined field table. Instead it will add a where clause that checks that the node doesn't have a corresponding row in the field table, since if it doesn't appear there, the rating for that node must be 0. However, there are some serious performance issues with that, so I don't really think that's a good choice.
To be honest, I'm not sure what the best option is here. Ideally, the fivestar module would record a 0 rating for the node if the node has no stars, but I don't know how feasible that is.
Comment #25
ExTexan CreditAttribution: ExTexan commentedIs it possible to modify the query it to do a left join and change the where to test for "zero or null" (test for both, I mean)?
Comment #26
anemirovsky CreditAttribution: anemirovsky commentedTry this one on for size. It's not the prettiest code I've written, but I tried to err on the side of understandable logic rather than minimal lines of code. This should handle the No Stars use case for multiple values in the filter as well as for the "Is one of" and "Is not one of" operators.
Comment #27
ExTexan CreditAttribution: ExTexan commentedI installed patch #26. I'm able to add the exposed filter to my view just fine, but it doesn't seem to select the correct nodes.
My filter is defined as a single filter, with operator = "is one of", and the default options (Select all, No stars, 1 star, 2 stars, etc.).
I have a view that (unfiltered) returns 30 nodes with average votes ranging from 2.1 to 4.8.
Select "No Stars" - I get no results (as expected).
Select "1 Star" - I get 3 nodes, with averages of 2.3, 2.3, and 3.1.
Select "2 Stars" - I get 3 nodes, with averages of 3, 2.9, and 3.1.
Select "3 Stars" - I get 5 nodes, with averages ranging from 2.8 to 3.5.
Select "4 Stars" - I get 5 nodes, with averages of 3.6 for one node, and 4 for the other 4 (1 vote each).
Select "5 Stars" - I get 14 nodes, with averages ranging from 2.1 to 4.8.
My guess is that if any single vote on any node matches the selection, the node is shown. If that's the case, that's counter-intuitive to what users would expect, IMO.
If I filter on "3 Stars", for example, I would expect to see all nodes with an average rating from 3 to 3.9.
Is there a way to get this patch to accomplish that?
Comment #28
ydahi#26 fails to patch for Fivestar 7.x-2.1 with the following error:
inside fivestar.info.rej:
In views, you the "Broken/Missing handler" error and are unable to use the filter.
Comment #29
Xen CreditAttribution: Xen at Reload commentedRerolled aganst 2.1.
Removed the "is empty"/"is not empty" operator options for better UX (they're covered by the "0 stars" option).
Replaced the four massive, nested, "if" statements and replaced them with more nimble conditions.
Fixed fivestar_field_views_data to not use the title for identification.
Comment #31
Xen CreditAttribution: Xen at Reload commentedRemoved unintended whitespace fix.
Comment #32
Xen CreditAttribution: Xen at Reload commentedComment #33
Selfirian CreditAttribution: Selfirian commentedHi,
I tried the patch in #31, using latest dev version: 7x-2.0+5
I get this error (in views, I have BEF enabled)
(Products referenced by field_product) Broken/missing handler (= )
I'm using Fivestar on products inside Drupal commerce if that matters at all.
Thanks for the great work
Comment #34
Xen CreditAttribution: Xen at Reload commentedOkay, using the patch in drush make doesn't seem to work. Looks like it chokes on the lines that the packaging system adds to the info file.
New patch that moves the added lines a few up. Also seems more "right" to have includes before tests.
Comment #35
Xen CreditAttribution: Xen at Reload commentedDoh, missed a file.
Comment #36
J-LeePatch #35 is working for me.
Thank you.
Comment #37
spgd01 CreditAttribution: spgd01 commentedPatch works but I got following error in drush:
Patch #35 failed:
Comment #38
spgd01 CreditAttribution: spgd01 commentedRemoved
Comment #39
spgd01 CreditAttribution: spgd01 commentedPatch #35 always selects "no Stars" when using grouped filters even when deselected.
Comment #40
Xen CreditAttribution: Xen at Reload commentedRerolled against 7.x-2.2.
Comment #41
gg24 CreditAttribution: gg24 as a volunteer and at QED42 commented"IN" condition works fine after applying the patch but for "NOT IN" view will display all the results.
As query contains:
WHERE (( (node.status = '1') AND( (field_data_field_rate.field_rate_rating NOT IN ('0', '20', '40', '60', '80', '100')) OR (field_data_field_rate.field_rate_rating IS NOT NULL ) )))
And data will pass through this filter, as it is NOT NULL.
Comment #42
gg24 CreditAttribution: gg24 as a volunteer and at QED42 commentedI am working on this issue.
Comment #43
gg24 CreditAttribution: gg24 as a volunteer and at QED42 commentedComment #45
gg24 CreditAttribution: gg24 as a volunteer and at QED42 commentedComment #46
navneet0693 CreditAttribution: navneet0693 as a volunteer and at QED42 commentedMay be we could convert this in a switch case. It looks nice! It is only a suggestion not necessary though :)
Comment #47
gg24 CreditAttribution: gg24 as a volunteer and at QED42 commentedComment #48
dbt102 CreditAttribution: dbt102 commented+1 bump
Comment #49
gg24 CreditAttribution: gg24 as a volunteer and at QED42 commentedThis feature introduced to have a filter handler inside view. This patch handles both "IN" and "NOT IN" conditions to filter out the correct set of data.
Comment #50
navneet0693 CreditAttribution: navneet0693 as a volunteer and at QED42 commentedWorking as per expectations !
Comment #51
navneet0693 CreditAttribution: navneet0693 as a volunteer and at QED42 commentedIssuing RTBC
Comment #53
dbt102 CreditAttribution: dbt102 commentedThanks for the patches and reviews everyone !!!
Comment #54
dbt102 CreditAttribution: dbt102 commentedComment #56
thommyboy CreditAttribution: thommyboy commentedI use the filter because I simply want to filter (exposed) voted from unvoted nodes. When configuring the filter I can choose 1star, 2stars, ... BUT there is a "No star" setting that ALWAYS gets set automnatically when saving the filter making it useless?
EDIT: I use a grouped filter (seems to work on a single filter) with three (desired) options (Any, NOT IN NO STARS, IN 1..6 STARS)