Harjotsingh has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/372130 )

Change subject: Add ability for proposal positions to be shuffled on load
......................................................................

Add ability for proposal positions to be shuffled on load

Currently the quiz extension only shuffles the order of questions using Js.
This change adds shuffling feature for proposal for each questions by using
shuffle function of Php.

Bug: T170799
Change-Id: I471984b7a9eb1faa0f5e4e4dae7c519312e495ea
---
M Question.php
1 file changed, 28 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Quiz 
refs/changes/30/372130/1

diff --git a/Question.php b/Question.php
index f2d544c..85e13a9 100644
--- a/Question.php
+++ b/Question.php
@@ -161,11 +161,14 @@
                // Parameters used in some special cases.
                $expectOn = 0;
                $checkedCount = 0;
+               $lines = [];
+               $proposalCount = -1;
                foreach ( $raws as $proposalId => $raw ) {
                        $text = null;
                        $colSpan = '';
                        $signesOutput = '';
                        if ( preg_match( $this->mProposalPattern, $raw, 
$matches ) ) {
+                               $proposalCount++;
                                $rawClass = 'proposal';
                                // Insulate the proposal signes.
                                $text = array_pop( $matches );
@@ -269,14 +272,33 @@
                                $colSpan = ' colspan="13"';
                        }
                        if ( $text ) {
-                               $output .= '<tr class="' . $rawClass . '">' . 
"\n";
-                               $output .= $signesOutput;
-                               $output .= '<td' . $colSpan . '>';
-                               $output .= $this->mParser->recursiveTagParse( 
$text );
-                               $output .= '</td>';
-                               $output .= '</tr>' . "\n";
+                               $lineOutput = '';
+                               $lineOutput = '<tr class="' . $rawClass . '">' 
. "\n";
+                               $lineOutput .= $signesOutput;
+                               $lineOutput .= '<td' . $colSpan . '>';
+                               $lineOutput .= 
$this->mParser->recursiveTagParse( $text );
+                               $lineOutput .= '</td>';
+                               $lineOutput .= '</tr>' . "\n";
+                               if ( $rawClass === 'correction' ) {
+                                       if ( $proposalCount === -1 ) {
+                                               // Add to output directly
+                                               $output .= $lineOutput;
+                                       } else {
+                                               // Add feedback to previous 
proposal
+                                               $lines[ $proposalCount ] .= 
$lineOutput;
+
+                                       }
+                               } else {
+                                       // Add lineOutput for proposal
+                                       $lines[ $proposalCount ] = $lineOutput;
+                               }
                        }
                }
+               // Shuffling the proposals
+               shuffle( $lines );
+               for( $i = 0; $i <= $proposalCount; ++$i ) {
+                                $output .= $lines[ $i ];
+                }
                // A single choice object with no correct proposal is a syntax 
error.
                if ( isset( $typeId ) && $typeId == 'sn' && $expectOn == 0 ) {
                        $this->setState( 'error' );

-- 
To view, visit https://gerrit.wikimedia.org/r/372130
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I471984b7a9eb1faa0f5e4e4dae7c519312e495ea
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Quiz
Gerrit-Branch: master
Gerrit-Owner: Harjotsingh <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to