This patch adds a counter field which displays the count of the result

this is quite helpfull for example for sports result tables or highscores.

|1 bar
|2 second
|3 foo

The hardest part of the patch is

<?php
    // Add the counter for the current site.
    $count += array_search($values, $this->view->result) + 1;
?>

I'm not sure how to get the counter of the current site out of $this, i didn't manage to find another/faster way.

Comments

dawehner’s picture

StatusFileSize
new1.67 KB

arg

mh not sure why this file got a cvs entries diff

merlinofchaos’s picture

Status: Needs review » Fixed

Committed! Very nice!

liquixis’s picture

Status: Fixed » Needs review
StatusFileSize
new3.34 KB

(sorry for my english)

I added "row_index" field to "view" object.
This allow optimize this field handler.
For every field handler: "$values == $this->view->result[$this->view->row_index]" is true.
This will allow replace

    // Add the counter for the current site.
    $count += array_search($values, $this->view->result) + 1;

with

    // Add the counter for the current site.
    $count += $this->view->row_index + 1;

This replacement already in the patch.

dawehner’s picture

i scanned through the patch without testing it, but its much much! nicer then now.

Additional its cool that you corrected the codestyle.

liquixis’s picture

Thanks.

aclight’s picture

It would be helpful if this field was configurable so that the value the count starts from could be set. I want to use this for a view that has an attachment which is a map with the location of all nodes returned by the view (using the gmap module). When using numerical markers, gmap starts at position '0' instead of position '1', so the number returned by this field is one higher than it should be for this particular use case.

Any objections to adding a configurable option with a default value of 1? If not I can work on a patch.

merlinofchaos’s picture

aclight: Sounds reasonable to me.

aclight’s picture

StatusFileSize
new2.05 KB

Ok, attached patch does the following:

1. Provides an option for the field that is used to set the value from which counting starts.
2. Fixes a notice error that happened when a view did not use a pager (due to $count being undefined in that case).
3. Fixes whitespace error before return statement of ::render().

I did not incorporate the changes made in the patch from #3 with the exception of the whitespace fix, since I'm not sure if that change is desired by Earl or not. If it is I can reroll this with those changes as well.

merlinofchaos’s picture

Status: Needs review » Fixed

Good work! Committed to 2.x and 3.x branches.

liquixis’s picture

Did you commit "row_index" changes (from http://drupal.org/node/430068#comment-1690684)?

merlinofchaos’s picture

I committed the latest patch. If there are multiple valid patches on a single issue, there's no easy way for me to figure that out.

liquixis’s picture

aclight in #8 mentioned that

I did not incorporate the changes made in the patch from #3 ..., since I'm not sure if that change is desired by Earl or not. If it is I can reroll this with those changes as well.

But no one said him to do this...
merlinofchaos, if I make new "row_index" patch against updated version, will you commit it?

Status: Fixed » Closed (fixed)

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

dawehner’s picture

i'm quite sure he will commit your changes if there is a patch for the dev version, my original patch was horrible bad if you look at micro-performance

dawehner’s picture

giorgio79’s picture

Status: Closed (fixed) » Needs work

Not sure if I should open a new one or post it here, but when I add the Global: View Result Counter field, and try to do a preview, I get a popup error message, and preview is not generated...
The error message is very general and goes like this:
"An error occurred at /admin/build/views/ajax/preview/taxonomy_term"

giorgio79’s picture

Status: Needs work » Fixed

Ok, it also generates a fatal error after savign which was already posted.
#625330: Global: view result counter dumps caused by dsm()

Status: Fixed » Closed (fixed)

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