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

Change subject: Show Feedback for only questions that have been attempted
......................................................................

Show Feedback for only questions that have been attempted

Bug:T159952
Change-Id: I131d8e762c98f0edb4993f7c24650056bf6e73c6
---
M Question.php
1 file changed, 31 insertions(+), 7 deletions(-)


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

diff --git a/Question.php b/Question.php
index 5410f87..872ed74 100755
--- a/Question.php
+++ b/Question.php
@@ -87,6 +87,7 @@
                        $output .= '</td>';
                        $output .= '</tr></table>';
                }
+
                return $output;
        }
 
@@ -156,15 +157,14 @@
                $raws = preg_split( '`\n`s', $input, -1, PREG_SPLIT_NO_EMPTY );
                // Parameters used in some special cases.
                $expectOn = 0;
+               $signes = [];
+               $proposalCount = 0;
+               $attemptChecker = 0;
                $checkedCount = 0;
                foreach ( $raws as $proposalId => $raw ) {
-                       $text = null;
-                       $colSpan = '';
                        $signesOutput = '';
                        if ( preg_match( $this->mProposalPattern, $raw, 
$matches ) ) {
-                               $rawClass = 'proposal';
-                               // Insulate the proposal signes.
-                               $text = array_pop( $matches );
+                               array_pop( $matches );
                                array_shift( $matches );
                                // Determine a type ID, according to the 
questionType and the number of signes.
                                $typeId  = substr( $this->mType, 0, 1 );
@@ -193,6 +193,10 @@
                                        // Determine if the input had to be 
checked.
                                        $checked = ( $this->mBeingCorrected &&
                                                        
$this->mRequest->getVal( $name ) == $value ) ? 'checked="checked"' : null;
+                                       // If any proposal is checked, the 
question is attempted
+                                       if ( $this->mBeingCorrected && !empty( 
$this->mRequest->getVal( $name ) ) ) {
+                                               $attemptChecker = 1;
+                                       }
                                        // Determine the color of the cell and 
modify the state of the question.
                                        switch ( $sign ) {
                                                case '+':
@@ -239,7 +243,9 @@
                                        $signesOutput .= '<td class="sign">';
                                        $signesOutput .= '<input class="check" 
' . $inputStyle . ' type="' . $inputType . '" ' . $title . ' name="' . $name . 
'" value="' . $value . '" ' . $checked . ' ' . $disabled . ' />';
                                        $signesOutput .= '</td>';
+                                       $signes[$proposalCount] = $signesOutput;
                                }
+                               $proposalCount++;
                                if ( $typeId == 'sc' ) {
                                        // A single choice object with no 
correct proposal is a syntax error.
                                        if ( $expectOn == 0 ) {
@@ -247,12 +253,25 @@
                                        }
                                        $expectOn = 0;
                                }
+                       }
+               }
+               $counter = 0;
+               foreach( $raws as $proposalId => $raw ) {
+                       $text = null;
+                       $colSpan = '';
+                       $signesOutput = '';
+                       $isProposal = 0;
+                       if ( preg_match( $this->mProposalPattern, $raw, 
$matches ) ) {
+                               $isProposal = 1;
+                               $rawClass = 'proposal';
+                               $text = array_pop( $matches );
                                // If the proposal text is empty, the question 
has a syntax error.
                                if ( trim( $text ) == '' ) {
                                        $text = '???';
                                        $this->setState( 'error' );
                                }
-                       } elseif ( preg_match( $this->mCorrectionPattern, $raw, 
$matches ) && $this->mBeingCorrected ) {
+                       } elseif ( preg_match( $this->mCorrectionPattern, $raw, 
$matches ) && $this->mBeingCorrected && $attemptChecker ) {
+                               $isProposal = 0;
                                $rawClass = 'correction';
                                $text = array_pop( $matches );
                                $signesOutput = '<td>&#x2192;</td>';
@@ -261,7 +280,12 @@
                        }
                        if ( $text ) {
                                $output .= '<tr class="' . $rawClass . '">' . 
"\n";
-                               $output .= $signesOutput;
+                               if ( $isProposal ) {
+                                       $output .= $signes[$counter];
+                                       $counter++;
+                               } else {
+                                       $output .= $signesOutput;
+                               }
                                $output .= '<td' . $colSpan . '>';
                                $output .= $this->mParser->recursiveTagParse( 
$text );
                                $output .= '</td>';

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I131d8e762c98f0edb4993f7c24650056bf6e73c6
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Quiz
Gerrit-Branch: master
Gerrit-Owner: Harjotsingh <harjo...@ymail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to