Hi Marvil

Great progress on this module! Sorry... I've been away for a little while, got caught up in work projects (non drupal). Very glad you went the ctools route!

As for the splitting of votes (x upvotes, x downvotes), can I suggest that we implement the solution in comment #30 (http://drupal.org/node/413980#comment-2735202) as a permanent solution for 2.x-dev? I'm happy overwriting the theme function but it leads to a lot of code duplication which could cause problems for future upgrades.

The idea is that we provide all the information a potential widget might need right out the box. Variables available to the widget would then be:

$points             : Number of total vote points for the vote object (signed)
$unsigned_points    : Number of total vote points for the object (unsigned)
$points_down        : Number of down votes
$points_up:         : Number of up votes

Obviously current widgets would continue to work, but now themers can very easily split the votes if they choose to.

If you are happy with this suggestion I can roll you a patch (I will also include the updates needed WIDGETAPI.txt).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

marvil07’s picture

Title: Splitting of votes (5 voted up, 2 voted down) » New widget for splitting of votes in positives/negatives (5 voted up, 2 voted down)

Yep, that would be great :-), but I would like to have a another widget which shows that variables in the main module.

enzipher’s picture

Hi,

Just wanted to know if there are any updates in this area? I need this feature and would be happy to do testing if needed.

It would also be nice if the the numbers could be changed on-the-fly as the total score does when clicking the vote down/vote up links.

Cheers

wiifm’s picture

Managed to get this basically working by porting the old code from http://drupal.org/node/413980#comment-2735202 into version 2.0 beta 1

Changes (sorry, I am a noob when it comes to creating patches)

Insert line 250 into file vud.theme.inc

  // Added - get the vote count.
  $criteria = array(
    'content_type' => $type,
    'content_id' => $content_id,
    'value_type' => 'points',
    'tag' => $tag,
    'function' => 'count'
  );
  $vote_count = (int)votingapi_select_single_result_value($criteria);

  // Added - calculate number of up and down votes.
  $variables['down_votes'] = ($vote_count - $variables['unsigned_points']) / 2;
  $variables['up_votes'] = $vote_count - $variables['down_votes'];

I then created a new widget using the API supplied to take advantage of the new variables available ($up_votes and $down_votes)

Hope this helps someone

khanz’s picture

Has this been committed yet...

marvil07’s picture

\o/ first implementation!

It still needs work, but marking as needs review to get feedback. I think this patch resolves the logic.

It would be really great to have feedback about how to present the information, I attach one simple propose, but in the patch I used a updown widget clone :-p.

marvil07’s picture

Assigned: Unassigned » marvil07
Status: Active » Needs review
Issue tags: +Needs design review
Fidelix’s picture

I applied the patch successfully, but i dont have a clue how to actually get what you showed in the PNG.

Any tips, please?

Thank you very much for the good work!

marvil07’s picture

FileSize
2.81 KB

I attached the image only as a propose, I am really bad at design and I need a suggestion about it if possible.

I attach here what I got in the new widget after applying this patch for reference, but I should change it to have IMHO something better, so feedback is welcome!

Fidelix’s picture

The "hand" icon, green and red would be nice, just like in Youtube.

I got how it works, i'm developing a widget and i'll share it with everybody once i'm done.

I think it is actually getting pretty good.

jacobpov’s picture

thanks very nice of you!
Subscribing

Soren Jones’s picture

I started a duplicate issue #856946: Make separate up and down vote totals accessible from views before I noticed this.
All of my issue searches included views.

Anyway, maybe you could implement hook_votingapi_metadata_alter here, too.

marvil07’s picture

Status: Needs review » Needs work

Just about to send a new patch with the missing hook

marvil07’s picture

Status: Needs work » Needs review
FileSize
15.43 KB

Ok, after some delay, I got:

- The missing hook (hook_votingapi_metadata_alter()), originally by Soren Jones, let us define a view where you can list two new fields separately(inside the votingapi vote results field): positives and negatives :-)
- A functional propose for the widget visualization using sprites!

Please take a look a this, so I can commit it soon ;-)

Soren Jones’s picture

FileSize
1.01 KB

Thank you!

For anyone who doesn't see the arrows next to the numbers, you need the attached png.
Put it in the /vote_up_down/widgets/upanddown folder.

marvil07’s picture

Thanks for the test! I forgot the diff do not include the binaries as output :-p

Soren Jones’s picture

Ah, right! That makes sense. Good to know.

I just took a quick look. I'll try to do a careful test on Wednesday evening (Japan) -- not that it's necessarily needed.
But looking quickly, all seemed well. In PHP 5.3 even.

Thank you again for this!

Soren Jones’s picture

Well, I'm sorry, but I didn't find any serious bugs. ;-)
A few comments.
Take them or leave them.
Let me know if you want any of them in a patch.

+++ vud.module
@@ -193,3 +193,61 @@ function vud_ctools_plugin_directory($module, $plugin) {
+ * Implementation of votingapi hook_votingapi_results_alter().
...
+/**
+ * Calculate positive/negative results for VotingAPI cache.
+ *
+ * We provide 0 if not votes found.
+ */
+function _vud_get_standard_results($content_type, $content_id) {

Maybe some documentation about why _vud_get_standard_results is being used in addition to hook_votingapi_results_alter to help people like me who are learning.

"if not votes found" isn't grammatical. Maybe something like:
+ * Returns 0 when there are no votes.

And maybe move that comment just above each if statement?

+++ vud.module
@@ -193,3 +193,61 @@ function vud_ctools_plugin_directory($module, $plugin) {
+/**
+ * Implementation of hook_votingapi_metadata_alter().
+ */
+function vud_votingapi_metadata_alter(&$data) {
+  $data['functions']['positives'] = array(
+    'name' => t('Positives'),
+    'description' => t('The sum of all positive votes for a content.'),
+    'module' => 'vud',
+  );
+  $data['functions']['negatives'] = array(
+    'name' => t('Negatives'),
+    'description' => t('The sum of all negative votes for a content.'),
+    'module' => 'vud',
+  );
+}

For the function in the views_cache table, I understand wanting to use one word, but in the Views interface, positives and negatives might be confusing. Would it be OK to add "total" for consistency with "Total score"?

+ 'name' => t('Total positives'),

+ 'name' => t('Total negatives'),

"for a content" isn't grammatical. I can think of a number of alternatives, but maybe this is best:
+ 'description' => t('The positive vote total.'),

+ 'description' => t('The negative vote total.'),

Lastly, in Vote Up/Down Terms, the total within the default (updown) widget and the alternative widget update in real time (not the "Score" total, but the total within the widget), but the upanddown widget doesn't. A page refresh is required to update the number.

Powered by Dreditor.

marvil07’s picture

FileSize
22.68 KB

I'm going to commit this patch to 2.x and 3.x

marvil07’s picture

Status: Needs review » Fixed

\o/ Thanks to all people that help me in this patch. Commited to 2.x and 3.x.

Status: Fixed » Closed (fixed)

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

lesleyfernandes’s picture

What about Drupal 7?

TimelessDomain’s picture

@lesleyfernandes - There is no reason that upanddown widget would be abandoned for D7. So yes D7 will have it.

Furthermore you should refrain from posting so many times, in so many threads for something that is logically implied... People will answer such questions in good time when they are answering other questions/ requests that are more relevant.

lesleyfernandes’s picture

@TimelessDomain: hey man, two times is not "so many times" I think... but thanks for the answer.

jeffwidman’s picture

sub