Overview

Modifies the fivestar module to allow voting with half stars.

The need for this module arose from answering a Drupal Stack Exchange question asking for this feature.

Documentation

Documentation is provided on the project page and also in the modules README.txt.

Dependencies

This module is dependent on the Fivestar module.

Git Repository

To clone project:

git clone --branch 7.x-1.x http://git.drupal.org/sandbox/dahousecat/2233333.git halfstar
cd halfstar 

Pareview results:

http://pareview.sh/pareview/httpgitdrupalorgsandboxdahousecat2233333git

Manual reviews of other projects

(I quite like reviewing other modules and I'm also thinking that if I clear the whole queue down then my module will get reviewed sooner :) )

Comments

dahousecat’s picture

Issue summary: View changes
dahousecat’s picture

Issue tags: +PAreview: review bonus
dahousecat’s picture

Issue summary: View changes
dahousecat’s picture

Issue summary: View changes
dahousecat’s picture

Status: Needs review » Needs work
dahousecat’s picture

Status: Needs work » Needs review
dahousecat’s picture

Issue summary: View changes
dahousecat’s picture

Issue summary: View changes
dahousecat’s picture

Issue summary: View changes
Jeroen94’s picture

I'm the one who asked a question on Drupal Answers about the feature to vote with half stars with Fivestar. I'm very thankful to Felix that he provided the 'Halfstar' module as it works quite well (there are still some problems) for my purposes. As far as I've tested the module, everything works, so I'm sure it'll help others in the future too. Hopefully 'Halfstar' will be launched officially on Drupal soon.

dahousecat’s picture

Issue summary: View changes
dahousecat’s picture

Issue summary: View changes
dahousecat’s picture

Issue summary: View changes
dahousecat’s picture

Status: Needs review » Needs work

Score doesn't display correctly for logged out users.

dahousecat’s picture

Status: Needs work » Needs review

Issues all fixed.

dahousecat’s picture

Issue summary: View changes

Another review...

dahousecat’s picture

Issue summary: View changes

Added a review...

dahousecat’s picture

Issue summary: View changes
dahousecat’s picture

Issue summary: View changes

Review added.

dahousecat’s picture

Issue summary: View changes

Review added.

dahousecat’s picture

Issue summary: View changes

review

dahousecat’s picture

Issue summary: View changes

review

davidpetit’s picture

Issue summary: View changes

Hi ! I just tested your module. It's working well, I can indeed vote with halfstars.

There is just a small css issue if I choose to display both user vote and the average vote:
When there is not halfstar, the fields for voting are side by side whereas with halfstar it' broken. It's because with halfstar we lose a float:left on the .form-item div. You should fix this.

Other than that, I think we don't see it well that we can vote with half stars (even if there is the title tooltip with values). But this is just a UX notice.

dahousecat’s picture

Status: Needs review » Needs work

Hi David,

Thanks for your review. I fixed the minor CSS issue that you pointed out however this also made me aware of a bigger issue: When the average and users votes are displayed then the average score displayed in text below the stars is double what it should be.

I'm setting my status back to needs work whilst I'm working on a fix for this issue.

In response to it being a bit hard to see voting with half stars changing the widget will help. I've also considering adding some new widgets that are specifically designed for voting with half stars too.

davidpetit’s picture

Ok dahousecat,

I am glad to have helped and that it even made you see another issue. It will definitely improve the module.

Concerning the idea of having new widgets designed for halfstar, it could help indeed.

By the way, I checked the jquery plugin: http://www.fyneworks.com/jquery/star-rating/ and saw that you can even split it more than half and as you want.
Maybe we can have a more generic splitstar module ? Then you can do not only half but also custom split. :)

dahousecat’s picture

Status: Needs work » Needs review

Issue fixed.

Used hook_theme_registry_alter to add a pre-proccess function to theme_fivestar_summary and a drupal_static variable to determine if halfstar is enabled.

klausi’s picture

Assigned: Unassigned » dman
Status: Needs review » Reviewed & tested by the community

manual review:

  1. halfstar_form_alter(): instead of using switch() I think it would make more sense to split up this function into two hook_form_FORM_ID_alter() implementations.
  2. Why can't you use hook_field_widget_form_alter()? Please add a comment.
  3. 420 lines of CSS? Seriously? Why? Please add an @file comment.

But otherwise looks RTBC to me. Assigning to dman as he might have time to take a final look at this.

dahousecat’s picture

Hi Klaus,

Many thanks for the review.

  1. I'm now using 2 instances of hook_form_FORM_ID_alter() instead of a swtich in hook_form_alter().
  2. Instead of using hook_field_widget_form_alter() I'm using 2 instances of hook_field_widget_WIDGET_TYPE_form_alter(). These are halfstar_field_widget_fivestar_select_form_alter() and halfstar_field_widget_stars_form_alter().
  3. The css file halfstar.css makes changes to 8 widgets (different designs of stars) CSS. In the fivestar module each sites in a separate CSS file however each each CSS file would have been tiny I've combined them into 1. However the "craft" widget has 10 different stars and each star requires custom CSS. As this is such a complicated widget I've separated the CSS for this one out into a separate file called halfstar-craft.css so it only included when needed. I've also added @file comments to each file to explain this.
dman’s picture

Visual review only just now tonight...

Two things stuck out to me.

I may be wrong, but it looks like you are converting the values up to double (and back to half) everywhere in the code, in fact that seems to take up most of the work.
The natural expectation would be for 1-and-a-half stars to be stored as 1.5 etc, yet you convert it to 3/10 ? It that what I'm seeing?
This decision has a LOT of knock-on effects
- if someone wanted to build a chart or a graph or a report of the results, then numbers are wrong.
- If someone has an already-running site and wants to add this module, then numbers become wrong.
- If someone wants to turn this module off, or make it optional, then the numbers are wrong or incompatible.

I can guess that you went down this road because the main storage mechanism was long ago assumed to be an int - but what I would really suggest is revisiting that assumption and fixing/modifying that. You will probably save a good third of the code that's doing busy-work just-in-time conversion everywhere here.

That's not to say there is anything wrong with the code (review-wise) - just that it may be a bad idea (code-wise) to solve the task in this way.

Point 2:

Have you raised this for discussion or a feature request within fivestar itself? It feel s like a lot of the structure you are needing to add with *_alter() callbacks (though correct) could be significanlty less work if you were to contribute a patch directly to fivestar itself.
As in the Project Application Checklist

If the differences between your module is not too fundamental for patching an existing one, we would love to see you joining forces and concentrate all power on enhancing one module.

This functionality is not a 'duplication' at all - in fact it's a straightforward linear enhancement of fivestar, and it would be great to see it aim for inclusion in that suite directly. Existing feature requests for "Half star functionality in fivestar (that I see you've posted to also) suggests that converting between 5 and 10 may not be at all necessary, and that the guys there seem to think that it's entirely possible with only css. I'm not sure about that - but it may be worth getting involved there.

(Sorry, it's late here, I'll have a look at the code line-by-line a little later.)

dahousecat’s picture

Hi Dan,

Thanks for taking a look at the module.

Your right about most of the code dealing with doubling and halving the rating and number of stars, however the score actually stored in votingapi_vote table is correct.

The module doubles the number of stars and the score before it is displayed on the screen as each star actually consists of 2 stars to allow voting on each half individually.

Enabling and disabling the halfstar feature does not change the existing score. A CSS only solution would cause the rating saved to be halved, and the tooltip and descriptions would be also be wrong.

I would be happy to convert this project into a patch for the fivestar module. I initially went down this route as I've not contributed any code before at all before it seemed slightly less daunting to do this as separate module than to submit a patch to an existing one (not sure if that's very logical but still true).

I also felt that most people who use fivestar probably won't use this feature and I'm aware of several module that have started to suffer from bloat. There have been times when I've not used an existing module that offers the functionally that I need as it also does so much more and I don't want all that extra code in my project. I suppose it is about striking a balance, but a certain level of modular design does seem desirable.

klausi’s picture

Status: Reviewed & tested by the community » Fixed

Sounds all reasonable to me and the objections from dman don't seem to be blockers either, so ...

Thanks for your contribution, dahousecat!

I updated your account so you can promote this to a full project and also create new projects as either a sandbox or a "full" project.

Here are some recommended readings to help with excellent maintainership:

You can find lots more contributors chatting on IRC in #drupal-contribute. So, come hang out and stay involved!

Thanks, also, for your patience with the review process. Anyone is welcome to participate in the review process. Please consider reviewing other projects that are pending review. I encourage you to learn more about that process and join the group of reviewers.

Thanks to the dedicated reviewer(s) as well.

dahousecat’s picture

Woo hoo - how exiting!

Thank you :)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.