Index: trunk/extensions/SecurePoll/includes/ballots/RadioRangeBallot.php |
— | — | @@ -11,6 +11,7 @@ |
12 | 12 | * min-score |
13 | 13 | * max-score |
14 | 14 | * column-label-msgs |
| 15 | + * column-order |
15 | 16 | * |
16 | 17 | * Question messages: |
17 | 18 | * column-1, column0, column+1, etc. |
— | — | @@ -31,18 +32,46 @@ |
32 | 33 | return array( $min, $max ); |
33 | 34 | } |
34 | 35 | |
| 36 | + function getColumnDirection( $question ) { |
| 37 | + $order = $question->getProperty( 'column-order' ); |
| 38 | + if ( !$order ) { |
| 39 | + return 1; |
| 40 | + } elseif ( preg_match( '/^asc/i', $order ) ) { |
| 41 | + return 1; |
| 42 | + } elseif ( preg_match( '/^desc/i', $order ) ) { |
| 43 | + return -1; |
| 44 | + } else { |
| 45 | + throw new MWException( __METHOD__.': column-order configured incorrectly' ); |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + |
| 50 | + function getScoresLeftToRight( $question ) { |
| 51 | + $incr = $this->getColumnDirection( $question ); |
| 52 | + list( $min, $max ) = $this->getMinMax( $question ); |
| 53 | + if ( $incr > 0 ) { |
| 54 | + $left = $min; |
| 55 | + $right = $max; |
| 56 | + } else { |
| 57 | + $left = $max; |
| 58 | + $right = $min; |
| 59 | + } |
| 60 | + return range( $left, $right ); |
| 61 | + } |
| 62 | + |
35 | 63 | function getColumnLabels( $question ) { |
36 | 64 | list( $min, $max ) = $this->getMinMax( $question ); |
37 | 65 | $labels = array(); |
38 | 66 | $useMessageLabels = $question->getProperty( 'column-label-msgs' ); |
| 67 | + $scores = $this->getScoresLeftToRight( $question ); |
39 | 68 | if ( $useMessageLabels ) { |
40 | | - for ( $score = $min; $score <= $max; $score++ ) { |
| 69 | + foreach ( $scores as $score ) { |
41 | 70 | $signedScore = $this->addSign( $question, $score ); |
42 | 71 | $labels[$score] = $question->getMessage( "column$signedScore" ); |
43 | 72 | } |
44 | 73 | } else { |
45 | 74 | global $wgLang; |
46 | | - for ( $score = $min; $score <= $max; $score++ ) { |
| 75 | + foreach ( $scores as $score ) { |
47 | 76 | $labels[$score] = $wgLang->formatNum( $score ); |
48 | 77 | } |
49 | 78 | } |