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

Change subject: Add feedbackDisplay class to questions that have not been 
attempted
......................................................................

Add feedbackDisplay class to questions that have not been attempted

Currently feedback is shown for all questions in a quiz even if
a question is answered or not.This change changes the way feedback
is handled by checking if a question has been attempted.It adds
feedbackDisplay class to not attempted question and uses CSS to hide/show
these questions.

Change-Id: Ibbff5e5c16ed4b3c94479cd1f2b545b918358b0b
---
M Question.php
M modules/ext.quiz.css
2 files changed, 39 insertions(+), 3 deletions(-)


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

diff --git a/Question.php b/Question.php
index 4868061..9080fbb 100644
--- a/Question.php
+++ b/Question.php
@@ -161,6 +161,9 @@
                // Parameters used in some special cases.
                $expectOn = 0;
                $checkedCount = 0;
+               $signes = [];
+               $proposalCount = 0;
+               $attemptChecker = 0;
                foreach ( $raws as $proposalId => $raw ) {
                        $text = null;
                        $colSpan = '';
@@ -198,6 +201,10 @@
                                        $checked = $this->mBeingCorrected && 
$this->mRequest->getVal( $name ) == $value
                                                ? 'checked="checked"'
                                                : null;
+                                       // Determine if the question has been 
attempted
+                                       $attemptChecker = ( 
$this->mBeingCorrected && !empty( $this->mRequest->getVal( $name ) ) )
+                                               ? 1
+                                               : 0;
                                        // Determine the color of the cell and 
modify the state of the question.
                                        switch ( $sign ) {
                                                case '+':
@@ -260,7 +267,9 @@
                                                $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 ) {
@@ -268,6 +277,18 @@
                                        }
                                        $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 = '???';
@@ -276,7 +297,8 @@
                        } elseif ( preg_match( $this->mCorrectionPattern, $raw, 
$matches ) &&
                                $this->mBeingCorrected
                        ) {
-                               $rawClass = 'correction';
+                               $isProposal = 0;
+                               $rawClass = $attemptChecker ? 'correction' : 
'correction feedbackDisplay';
                                $text = array_pop( $matches );
                                $signesOutput = '<td>&#x2192;</td>';
                                // Hacks to avoid counting the number of signes.
@@ -284,7 +306,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>';
@@ -343,11 +370,16 @@
                $raws = preg_split( '`\n`s', $input, -1, PREG_SPLIT_NO_EMPTY );
                global $wqInputId;
                $wqInputId = $this->mQuestionId * 100;
+               //check if the question has been attempted
+               if ( $this->mBeingCorrected ) {
+                       $value = trim( $this->mRequest->getVal( $wqInputId+1 ) 
);
+                       $attemptChecker = $value === '' ? 0 : 1;
+               }
                $output = '';
                foreach ( $raws as $raw ) {
                        if ( preg_match( $this->mCorrectionPattern, $raw, 
$matches ) ) {
                                if ( $this->mBeingCorrected ) {
-                                       $rawClass = 'correction';
+                                       $rawClass = $attemptChecker ? 
'correction' : 'correction feedbackDisplay';
                                        $text = '<td>&#x2192; ' . 
$this->mParser->recursiveTagParse( $matches[1] ) .
                                                '</td>';
                                } else {
diff --git a/modules/ext.quiz.css b/modules/ext.quiz.css
index ace8216..263872b 100644
--- a/modules/ext.quiz.css
+++ b/modules/ext.quiz.css
@@ -83,3 +83,7 @@
        position: absolute;
        margin: 1.8em 0 0 0.1em;
 }
+
+.feedbackDisplay {
+       display: none;
+}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibbff5e5c16ed4b3c94479cd1f2b545b918358b0b
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